diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-07-12 15:16:34 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-07-12 15:16:34 -0700 |
commit | 4803fda05bb38f4152168fb3e53997d9c7df83df (patch) | |
tree | 3ae89bf340cdb8a8f2d99243a7017ad61983cf42 | |
parent | 9f8db4ef1fca1d9f2b526d325e83c3a6e309fc5c (diff) | |
download | bundler-4803fda05bb38f4152168fb3e53997d9c7df83df.tar.gz |
Fixes a bug where lockfiles were being updated or created even in the face of errors
-rw-r--r-- | lib/bundler/environment.rb | 4 | ||||
-rw-r--r-- | spec/install/gems/simple_case_spec.rb | 24 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 61 |
3 files changed, 88 insertions, 1 deletions
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb index 50603839d9..2a41d15b5b 100644 --- a/lib/bundler/environment.rb +++ b/lib/bundler/environment.rb @@ -36,8 +36,10 @@ module Bundler env_file = root.join('.bundle/environment.rb') env_file.rmtree if env_file.exist? + contents = @definition.to_lock + File.open(root.join('Gemfile.lock'), 'w') do |f| - f.puts @definition.to_lock + f.puts contents end end diff --git a/spec/install/gems/simple_case_spec.rb b/spec/install/gems/simple_case_spec.rb index 0f876dcebf..455adbe1b0 100644 --- a/spec/install/gems/simple_case_spec.rb +++ b/spec/install/gems/simple_case_spec.rb @@ -11,6 +11,30 @@ describe "bundle install with gem sources" do out.should =~ /no dependencies/ end + it "does not make a lockfile if the install fails" do + install_gemfile <<-G, :expect_err => true + raise StandardError, "FAIL" + G + + err.should =~ /FAIL \(StandardError\)/ + bundled_app("Gemfile.lock").should_not exist + end + + it "doesn't delete the lockfile if one already exists" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem 'rack' + G + + lockfile = File.read(bundled_app("Gemfile.lock")) + + install_gemfile <<-G, :expect_err => true + raise StandardError, "FAIL" + G + + File.read(bundled_app("Gemfile.lock")).should == lockfile + end + it "fetches gems" do install_gemfile <<-G source "file://#{gem_repo1}" diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index f7b69ace33..62b37c4018 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -1,6 +1,67 @@ require "spec_helper" describe "Bundler.setup" do + it "raises if the Gemfile was not yet installed" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + ruby <<-R + require 'rubygems' + require 'bundler' + + begin + Bundler.setup + puts "FAIL" + rescue Bundler::GemNotFound + puts "WIN" + end + R + + out.should == "WIN" + end + + it "doesn't create a Gemfile.lock if the setup fails" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + ruby <<-R, :expect_err => true + require 'rubygems' + require 'bundler' + + Bundler.setup + R + + bundled_app("Gemfile.lock").should_not exist + end + + it "doesn't change the Gemfile.lock if the setup fails" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + lockfile = File.read(bundled_app("Gemfile.lock")) + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "nosuchgem", "10.0" + G + + ruby <<-R, :expect_err => true + require 'rubygems' + require 'bundler' + + Bundler.setup + R + + File.read(bundled_app("Gemfile.lock")).should == lockfile + end + it "uses BUNDLE_GEMFILE to locate the gemfile if present" do gemfile <<-G source "file://#{gem_repo1}" |