summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrismo <chrismo@clabs.org>2016-07-08 22:38:34 -0500
committerchrismo <chrismo@clabs.org>2016-07-08 22:38:34 -0500
commit263c1879e6e892810b70dca556b27d36ff4ffddf (patch)
tree65b80de0f4d7e846ff4e324393b380adee95c86d
parent9022339885e76c07b015d64258c0a20b0602c141 (diff)
downloadbundler-263c1879e6e892810b70dca556b27d36ff4ffddf.tar.gz
Don't parse empty Lockfile during GVP init
Not a common case, but glitch is triggered by new plugin integration tests when there's no Gemfile or .bundle directory. A GemfileNotFound exception is raised deeper down the call stack trying to access the cache_path when executed in a non-bundler dir. That case apparently is legit for plugins.
-rw-r--r--lib/bundler/definition.rb2
-rw-r--r--spec/bundler/definition_spec.rb45
-rw-r--r--spec/plugins/install_spec.rb2
3 files changed, 39 insertions, 10 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 0f8d0ee6e1..b7db1179a0 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -127,7 +127,7 @@ module Bundler
def create_gem_version_promoter
locked_specs = begin
- if @unlocking && @locked_specs.empty?
+ if @unlocking && @locked_specs.empty? && !@lockfile_contents.empty?
# Definition uses an empty set of locked_specs to indicate all gems
# are unlocked, but GemVersionPromoter needs the locked_specs
# for conservative comparison.
diff --git a/spec/bundler/definition_spec.rb b/spec/bundler/definition_spec.rb
index a6e0436cc3..c72f50f0d1 100644
--- a/spec/bundler/definition_spec.rb
+++ b/spec/bundler/definition_spec.rb
@@ -136,18 +136,47 @@ describe Bundler::Definition do
describe "initialize" do
context "gem version promoter" do
- before :each do
- install_gemfile <<-G
+ context "with lockfile" do
+ before :each do
+ install_gemfile <<-G
source "file://#{gem_repo1}"
gem "foo"
- G
+ G
+ end
+
+ it "should get a locked specs list when updating all" do
+ definition = Bundler::Definition.new(bundled_app("Gemfile.lock"), [], Bundler::SourceList.new, true)
+ locked_specs = definition.gem_version_promoter.locked_specs
+ expect(locked_specs.to_a.map(&:name)).to eq ["foo"]
+ expect(definition.instance_variable_get("@locked_specs").empty?).to eq true
+ end
end
- it "should get a locked specs list when updating all" do
- definition = Bundler::Definition.new(bundled_app("Gemfile.lock"), [], Bundler::SourceList.new, true)
- locked_specs = definition.gem_version_promoter.locked_specs
- expect(locked_specs.to_a.map(&:name)).to eq ["foo"]
- expect(definition.instance_variable_get("@locked_specs").empty?).to eq true
+ context "without gemfile or lockfile" do
+ it "should not attempt to parse empty lockfile contents" do
+ definition = Bundler::Definition.new(nil, [], mock_source_list, true)
+ expect(definition.gem_version_promoter.locked_specs.to_a).to eq []
+ end
+ end
+
+ def mock_source_list
+ Class.new do
+ def all_sources
+ []
+ end
+
+ def path_sources
+ []
+ end
+
+ def rubygems_remotes
+ []
+ end
+
+ def replace_sources!(arg)
+ nil
+ end
+ end.new
end
end
end
diff --git a/spec/plugins/install_spec.rb b/spec/plugins/install_spec.rb
index 070a234a4a..eaf6427577 100644
--- a/spec/plugins/install_spec.rb
+++ b/spec/plugins/install_spec.rb
@@ -9,7 +9,7 @@ describe "bundler plugin install" do
end
end
- it "shows propper message when gem in not found in the source" do
+ it "shows proper message when gem in not found in the source" do
bundle "plugin install no-foo --source file://#{gem_repo1}"
expect(out).to include("Could not find")