From 5cf8be558510539a222be2db6649b7906c55f986 Mon Sep 17 00:00:00 2001 From: James Wen Date: Fri, 25 Mar 2016 14:01:41 -0400 Subject: Prevent endless recursive copy for `bundle package --all` and differently named gemspecs and gems - Fixes #4392 --- lib/bundler/runtime.rb | 3 +- spec/commands/package_spec.rb | 79 +++++++++++++++++++++++++++++++------------ 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index e80a9eaeba..d4a7837072 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -133,9 +133,10 @@ module Bundler gemspec = gemspec_cache_hash.values.first root_gem_name = gemspec.name unless gemspec.nil? end + specs.each do |spec| next if spec.name == "bundler" - next if File.exist?("#{root_gem_name}.gemspec") && spec.source.class == Bundler::Source::Path && root_gem_name && spec.name == root_gem_name + next if !Dir.glob("*.gemspec").empty? && spec.source.class == Bundler::Source::Path && root_gem_name && spec.name == root_gem_name spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true) spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache) end diff --git a/spec/commands/package_spec.rb b/spec/commands/package_spec.rb index 08b36b1e9d..8cf6de4c8c 100644 --- a/spec/commands/package_spec.rb +++ b/spec/commands/package_spec.rb @@ -31,33 +31,68 @@ describe "bundle package" do expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist end end + context "with a gemspec" do - before do - File.open(bundled_app("mygem.gemspec"), "w") do |f| - f.write <<-G - Gem::Specification.new do |s| - s.name = "mygem" - s.version = "0.1.1" - s.summary = "" - s.authors = ["gem author"] - s.add_development_dependency "nokogiri", "=1.4.2" - end - G + context "that has the same name as the gem" do + before do + File.open(bundled_app("mygem.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "nokogiri", "=1.4.2" + end + G + end + end + + it "caches all dependencies except bundler and the gemspec specified gem" do + gemfile <<-D + source "file://#{gem_repo1}" + gem 'rack' + gemspec + D + + bundle! "package --all" + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist + expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist end end - it "caches all dependencies except bundler and the gemspec specified gem" do - gemfile <<-D - source "file://#{gem_repo1}" - gem 'rack' - gemspec - D - bundle! "package --all" + context "that has a different name as the gem" do + before do + File.open(bundled_app("mygem_diffname.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "nokogiri", "=1.4.2" + end + G + end + end - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist - expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + it "caches all dependencies except bundler and the gemspec specified gem" do + gemfile <<-D + source "file://#{gem_repo1}" + gem 'rack' + gemspec + D + + bundle! "package --all" + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist + expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end end end end -- cgit v1.2.1 From 8897eb95c14e875db9ae17bd0023c5ac19842ed6 Mon Sep 17 00:00:00 2001 From: James Wen Date: Sat, 26 Mar 2016 09:35:11 -0400 Subject: Create shared examples for major, minor, patch version detection in `bundle outdated` specs --- spec/commands/outdated_spec.rb | 98 ++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 8f961e5a42..b77f7cb0dc 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -241,21 +241,65 @@ describe "bundle outdated" do end end - shared_examples_for "major version is ignored" do + shared_examples_for "version update is detected" do + it "reports that a gem has a newer version" do + subject + expect(out).to include("activesupport (newest") + end + end + + shared_examples_for "major version updates are detected" do before do update_repo2 do build_gem "activesupport", "3.3.5" - build_gem "weakling", "1.0.1" + build_gem "weakling", "0.8.0" + end + end + + it_behaves_like "version update is detected" + end + + shared_examples_for "minor version updates are detected" do + before do + update_repo2 do + build_gem "activesupport", "2.7.5" + build_gem "weakling", "2.0.1" + end + end + + it_behaves_like "version update is detected" + end + + shared_examples_for "patch version updates are detected" do + before do + update_repo2 do + build_gem "activesupport", "2.3.7" + build_gem "weakling", "0.3.1" end end - it "ignores gems that have updates in the major version" do + it_behaves_like "version update is detected" + end + + shared_examples_for "no version updates are detected" do + it "does not detect any version updates" do subject expect(out).to_not include("activesupport (newest") expect(out).to_not include("weakling (newest") end end + shared_examples_for "major version is ignored" do + before do + update_repo2 do + build_gem "activesupport", "3.3.5" + build_gem "weakling", "1.0.1" + end + end + + it_behaves_like "no version updates are detected" + end + shared_examples_for "minor version is ignored" do before do update_repo2 do @@ -264,11 +308,7 @@ describe "bundle outdated" do end end - it "ignores gems that have updates in the minor version" do - subject - expect(out).to_not include("activesupport (newest") - expect(out).to_not include("weakling (newest") - end + it_behaves_like "no version updates are detected" end shared_examples_for "patch version is ignored" do @@ -279,27 +319,13 @@ describe "bundle outdated" do end end - it "ignores gems that have updates in the patch version" do - subject - expect(out).to_not include("activesupport (newest") - expect(out).to_not include("weakling (newest") - end + it_behaves_like "no version updates are detected" end describe "with --major option" do subject { bundle "outdated --major" } - it "only reports gems that have a newer major version" do - update_repo2 do - build_gem "activesupport", "3.3.5" - build_gem "weakling", "0.8.0" - end - - subject - expect(out).to include("activesupport (newest") - expect(out).to_not include("weakling (newest") - end - + it_behaves_like "major version updates are detected" it_behaves_like "minor version is ignored" it_behaves_like "patch version is ignored" end @@ -307,17 +333,7 @@ describe "bundle outdated" do describe "with --minor option" do subject { bundle "outdated --minor" } - it "only reports gems that have a newer minor version" do - update_repo2 do - build_gem "activesupport", "2.7.5" - build_gem "weakling", "2.0.1" - end - - subject - expect(out).to include("activesupport (newest") - expect(out).to_not include("weakling (newest") - end - + it_behaves_like "minor version updates are detected" it_behaves_like "major version is ignored" it_behaves_like "patch version is ignored" end @@ -325,17 +341,7 @@ describe "bundle outdated" do describe "with --patch option" do subject { bundle "outdated --patch" } - it "only reports gems that have a newer patch version" do - update_repo2 do - build_gem "activesupport", "2.3.7" - build_gem "weakling", "0.3.1" - end - - subject - expect(out).to include("activesupport (newest") - expect(out).to_not include("weakling (newest") - end - + it_behaves_like "patch version updates are detected" it_behaves_like "major version is ignored" it_behaves_like "minor version is ignored" end -- cgit v1.2.1 From 2fc60267bb4e94661e63ca52291a2e74183e7160 Mon Sep 17 00:00:00 2001 From: James Wen Date: Sun, 27 Mar 2016 00:22:34 -0400 Subject: Allow `bundle outdated` to handle all combinations of `--major`, `--minor`, and `--patch` flags - Add test coverage for these combination sets - Fixes #4396 --- lib/bundler/cli/outdated.rb | 8 ++++---- spec/commands/outdated_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 4296ec630d..7928c1f0af 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -126,13 +126,13 @@ module Bundler update_present = active_major > current_major if options[:major] - if (options[:minor] || options[:patch]) && current_major == active_major + if !update_present && (options[:minor] || options[:patch]) && current_major == active_major current_minor = current_spec.version.segments[1, 1].first active_minor = active_spec.version.segments[1, 1].first - if options[:minor] - update_present = active_minor > current_minor - elsif options[:patch] && current_minor == active_minor + update_present = active_minor > current_minor if options[:minor] + + if !update_present && options[:patch] && current_minor == active_minor current_patch = current_spec.version.segments[2, 1].first active_patch = active_spec.version.segments[2, 1].first diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index b77f7cb0dc..7f699f035d 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -345,4 +345,36 @@ describe "bundle outdated" do it_behaves_like "major version is ignored" it_behaves_like "minor version is ignored" end + + describe "with --minor --patch options" do + subject { bundle "outdated --minor --patch" } + + it_behaves_like "minor version updates are detected" + it_behaves_like "patch version updates are detected" + it_behaves_like "major version is ignored" + end + + describe "with --major --minor options" do + subject { bundle "outdated --major --minor" } + + it_behaves_like "major version updates are detected" + it_behaves_like "minor version updates are detected" + it_behaves_like "patch version is ignored" + end + + describe "with --major --patch options" do + subject { bundle "outdated --major --patch" } + + it_behaves_like "major version updates are detected" + it_behaves_like "patch version updates are detected" + it_behaves_like "minor version is ignored" + end + + describe "with --major --minor --patch options" do + subject { bundle "outdated --major --minor --patch" } + + it_behaves_like "major version updates are detected" + it_behaves_like "minor version updates are detected" + it_behaves_like "patch version updates are detected" + end end -- cgit v1.2.1