Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for Gemfile hashing, fix hashing logic

  • Loading branch information...
commit 3d88ab9e3dab9c524c0f1b5561af2cbb92ac791a 1 parent 48758f9
Andre Arko and Terence Lee authored
Showing with 40 additions and 11 deletions.
  1. +10 −10 lib/bundler/definition.rb
  2. +30 −1 spec/install/gems/resolving_spec.rb
View
20 lib/bundler/definition.rb
@@ -137,7 +137,7 @@ def specs_for(groups)
def resolve
@resolve ||= begin
- if Bundler.settings[:frozen]
+ if Bundler.settings[:frozen] || lock_current?
@locked_specs
else
last_resolve = converge_locked_specs
@@ -151,24 +151,24 @@ def resolve
source_requirements[dep.name] = dep.source.specs
end
- # Only run a resolve against the locally available gems if Gemfile has changed
- # since the last resolve
- return last_resolve unless gemfile_changed?
-
- # If it's changed, update hash and rerun resolve
Bundler.settings[:gemfile_hash] = gemfile_hash
- last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve) end
+ last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve)
+ end
end
end
- def gemfile_changed?
- Digest::MD5.hexdigest(File.read(Bundler.default_gemfile)) == Bundler.settings[:gemfile_hash]
+ def gemfile_hash
+ Digest::MD5.hexdigest(Bundler.default_gemfile.read)
+ end
+
+ def lock_current?
+ Bundler.settings[:gemfile_hash] == gemfile_hash && Bundler.default_lockfile.exist?
end
def index
@index ||= Index.build do |idx|
@sources.each do |s|
- idx.use s.specs
+ idx.use s.specs(@dependencies)
end
end
end
View
31 spec/install/gems/resolving_spec.rb
@@ -69,4 +69,33 @@
end
end
end
-end
+
+ context "Gemfile hashing" do
+ before do
+ build_lib('foo')
+ install_gemfile <<-G, :expect_err => true
+ source "file://#{gem_repo1}"
+ gem "foo", :path => "#{lib_path('foo-1.0')}"
+ G
+ end
+
+ it "when Gemfile changes it reruns the resolver" do
+ install_gemfile <<-G, :expect_err => true, :env => {"DEBUG_RESOLVER" => true }
+ gem "foo", :path => "#{lib_path('foo-1.0')}"
+ G
+ err.should_not == ""
+ end
+
+ it "if the Gemfile has not changed don't rerun the resolver" do
+ bundle :install, :env => {"DEBUG_RESOLVER" => true }
+ err.should == ""
+ end
+
+ it "if the Gemfile.lock does not exist, generate one" do
+ bundled_app('Gemfile.lock').rmtree
+
+ bundle :install, :expect_err => true, :env => {"DEBUG_RESOLVER" => true }
+ err.should_not == ""
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.