Skip to content

Commit 77c6e73

Browse files
committed
Ensure that the correct dependencies are used in fixture projects
1 parent 25ce4ef commit 77c6e73

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

test/support/sass_rails_test_case.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ def assert_output(match)
5959
#
6060
# Automatically changes back to the working directory
6161
# and removes the temp directory when done.
62-
def within_rails_app(name, without_gems = [], gem_locations = $gem_locations)
62+
def within_rails_app(name, without_gems = [], gem_options = $gem_options)
6363
sourcedir = File.expand_path("../../fixtures/#{name}", __FILE__)
6464
Dir.mktmpdir do |tmpdir|
6565
FileUtils.cp_r "#{sourcedir}/.", tmpdir
6666
Dir.chdir(tmpdir) do
67-
gem_locations.each {|name, path| modify_gem_location name, path}
67+
gem_options.each {|name, options| modify_gem_entry name, options}
6868
without_gems.each {|name| remove_gem name}
69+
puts File.read("Gemfile")
70+
FileUtils.rm("Gemfile.lock")
6971
runcmd "bundle install --verbose"
7072
yield
7173
end
@@ -81,23 +83,29 @@ def process_gemfile(gemfile = "Gemfile", &blk)
8183
end
8284
end
8385

84-
def modify_gem_location(gemname, path, gemfile = "Gemfile")
86+
def modify_gem_entry(gemname, options, gemfile = "Gemfile")
8587
found = false
8688
process_gemfile(gemfile) do |line|
8789
if line =~ /gem *(["'])#{Regexp.escape(gemname)}\1/
8890
found = true
89-
%Q{gem "#{gemname}", :path => #{path.inspect}\n}
91+
gem_entry(gemname, options) + "\n"
9092
else
9193
line
9294
end
9395
end
9496
unless found
9597
File.open(gemfile, "a") do |f|
96-
f.print(%Q{\ngem "#{gemname}", :path => #{path.inspect}\n})
98+
f.print("\n#{gem_entry(gemname, options)}\n")
9799
end
98100
end
99101
end
100102

103+
def gem_entry(gemname, options)
104+
entry = %Q{gem "#{gemname}", "~> #{options[:version]}"}
105+
entry += ", :path => #{options[:path].inspect}" if options[:path]
106+
entry
107+
end
108+
101109
def remove_gem(gemname)
102110
process_gemfile(gemfile) do |line|
103111
line unless line =~ /gem *(["'])#{Regexp.escape(gemname)}\1/

test/test_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
# If developing against local dependencies, this code will ensure they get picked up
1414
# in the project fixtures that have their own bundle environment
15-
$gem_locations = {}
15+
$gem_options = {}
1616
possible_dev_dependencies = %w(sass-rails sass rails actionpack railties sprockets)
1717
Bundler.load.specs.each do |s|
1818
if possible_dev_dependencies.include?(s.name)
1919
gem_path = s.full_gem_path
20-
if File.exists?("#{gem_path}/#{s.name}.gemspec")
21-
$gem_locations[s.name] = gem_path
22-
end
20+
gem_options = {:version => s.version}
21+
gem_options[:path] = gem_path if File.exists?("#{gem_path}/#{s.name}.gemspec")
22+
$gem_options[s.name] = gem_options
2323
end
2424
end
2525

0 commit comments

Comments
 (0)