diff options
author | James Wen <jrw2175@columbia.edu> | 2016-02-18 00:07:22 -0500 |
---|---|---|
committer | James Wen <jrw2175@columbia.edu> | 2016-02-18 00:07:22 -0500 |
commit | b2c3ee86eb21f7f8030c4e4ef3cf5df24b8aef36 (patch) | |
tree | d11c66923504e731571021f1efbb125aacf7ce53 | |
parent | ec8df2e5ec595f053508b957af1b9978d784f2e9 (diff) | |
download | bundler-b2c3ee86eb21f7f8030c4e4ef3cf5df24b8aef36.tar.gz |
Fix `--minor` flag behavior for `bundle outdated`
- `bundle outdated --minor` should only report updates in the minor
version (not "at least minor version")
- Create shared example unit spec for ignoring major version updates
-rw-r--r-- | lib/bundler/cli/outdated.rb | 31 | ||||
-rw-r--r-- | spec/commands/outdated_spec.rb | 49 |
2 files changed, 56 insertions, 24 deletions
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 1535b2c4bf..d0ae0b46c5 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -56,18 +56,12 @@ module Bundler end active_spec = active_spec.last - if options[:major] - current_major = current_spec.version.segments.first - active_major = active_spec.version.segments.first - active_spec = nil unless active_major > current_major - end - - if options[:minor] - current_minor = current_spec.version.segments[0, 2].compact.join(".") - active_minor = active_spec.version.segments[0, 2].compact.join(".") - active_spec = nil unless active_minor > current_minor + if options[:major] || options[:minor] + update_present = update_present_via_semver_portions(current_spec, active_spec, options) + active_spec = nil unless update_present end end + next if active_spec.nil? gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version) @@ -123,5 +117,22 @@ module Bundler raise ProductionError, error_message end end + + def update_present_via_semver_portions(current_spec, active_spec, options) + current_major = current_spec.version.segments.first + active_major = active_spec.version.segments.first + + update_present = false + + update_present = active_major > current_major if options[:major] + + if options[:minor] && current_major == active_major + current_minor = current_spec.version.segments[1, 1].first + active_minor = active_spec.version.segments[1, 1].first + update_present = active_minor > current_minor + end + + update_present + end end end diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index ebe356fda3..65da3f6ea1 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -241,12 +241,33 @@ describe "bundle outdated" do end end - shared_examples_for "incorrect semantic versioning is ignored" do - before { update_repo2 { build_gem "weakling", "1" } } + 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 "ignores gems not in proper semantic version format" do + it "ignores gems that have updates in the major version" do subject - expect(out).to include("weakling (newest") + expect(out).to_not include("activesupport (newest") + expect(out).to_not include("weakling (newest") + end + end + + shared_examples_for "minor version is ignored" do + before do + update_repo2 do + build_gem "activesupport", "2.4.5" + build_gem "weakling", "0.3.1" + 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 end @@ -260,8 +281,8 @@ describe "bundle outdated" do it "ignores gems that have updates in the patch version" do subject - expect(out).to_not include("weakling (newest") expect(out).to_not include("activesupport (newest") + expect(out).to_not include("weakling (newest") end end @@ -270,34 +291,34 @@ describe "bundle outdated" do it "only reports gems that have a newer major version" do update_repo2 do - build_gem "weakling", "0.2.0" - build_gem "activesupport", "3.0" + build_gem "activesupport", "3.3.5" + build_gem "weakling", "0.8.0" end subject - expect(out).to_not include("weakling (newest") expect(out).to include("activesupport (newest") + expect(out).to_not include("weakling (newest") end + it_behaves_like "minor version is ignored" it_behaves_like "patch version is ignored" - it_behaves_like "incorrect semantic versioning is ignored" end describe "with --minor option" do subject { bundle "outdated --minor" } - it "only reports gems that have at least a newer minor version" do + it "only reports gems that have a newer minor version" do update_repo2 do - build_gem "activesupport", "3.0.0" - build_gem "weakling", "0.2.0" + build_gem "activesupport", "2.7.5" + build_gem "weakling", "2.0.1" end subject - expect(out).to include("weakling (newest") expect(out).to include("activesupport (newest") + expect(out).to_not include("weakling (newest") end + it_behaves_like "major version is ignored" it_behaves_like "patch version is ignored" - it_behaves_like "incorrect semantic versioning is ignored" end end |