diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index f355955a5a70..73b120799f69 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -90,7 +90,9 @@ def run dependency = current_dependencies[current_spec.name] groups = "" if dependency && !options[:parseable] - groups = dependency.groups.join(", ") + groups = dependency.groups + groups = groups.sort if options_include_groups + groups = groups.join(", ") end outdated_gems << { @@ -101,13 +103,11 @@ def run } end - relevant_outdated_gems = if options_include_groups - outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems| - contains_group = groups.split(", ").include?(options[:group]) - next unless options[:groups] || contains_group - - gems - end.compact + relevant_outdated_gems = if options[:groups] + without_groups, with_groups = outdated_gems.partition {|g| g[:groups].empty? } + with_groups.group_by {|g| g[:groups] }.sort.flat_map(&:last) + without_groups + elsif options_include_groups + outdated_gems.select {|g| g[:groups].split(", ").include?(options[:group]) } else outdated_gems end @@ -333,8 +333,6 @@ def print_indented(matrix) Bundler.ui.info justify(header, column_sizes) - data.sort_by! {|row| row[0] } - data.each do |row| Bundler.ui.info justify(row, column_sizes) end diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index e6a276cceafd..fb0ec8417d67 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -231,6 +231,30 @@ def test_group_option(group) expect(out).to end_with(expected_output) end + + it "returns a sorted list of outdated gems from one group spread over several group sets" do + install_gemfile <<-G + source "https://gem.repo2" + + gem "weakling", "~> 0.0.1" + group :development do + gem "terranova", '8' + end + group :development, :test do + gem 'activesupport', '2.3.5' + end + G + + test_group_option("development") + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups Release Date + activesupport 2.3.5 3.0 = 2.3.5 development, test + terranova 8 9 = 8 development + TABLE + + expect(out).to end_with(expected_output) + end end describe "with --groups option and outdated transitive dependencies" do @@ -267,6 +291,31 @@ def test_group_option(group) expect(out).to end_with(expected_output) end + + it "lists the outdated gems without groups after the grouped ones" do + install_gemfile <<-G + source "https://gem.repo2" + + gem "bar_dependant", '7.0' + gem "myrack_middleware" + gem "terranova", '8' + G + + update_repo2 do + build_gem "terranova", "9" + end + + bundle "outdated --groups", raise_on_error: false + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups Release Date + terranova 8 9 = 8 default + bar 2.0.0 3.0.0 + myrack 0.9.1 1.0.0 + TABLE + + expect(out).to end_with(expected_output) + end end describe "with --groups option" do @@ -274,6 +323,7 @@ def test_group_option(group) build_repo2 do build_git "foo", path: lib_path("foo") build_git "zebra", path: lib_path("zebra") + build_gem "zondrian", "1.2" end install_gemfile <<-G @@ -284,6 +334,7 @@ def test_group_option(group) group :development, :test do gem 'activesupport', '2.3.5' gem "duradura", '7.0' + gem "zondrian", '1.2' end G end @@ -298,15 +349,48 @@ def test_group_option(group) build_gem "activesupport", "3.0" build_gem "terranova", "9" build_gem "duradura", "8.0" + build_gem "zondrian", "1.3" end bundle "outdated --groups", raise_on_error: false expected_output = <<~TABLE.strip Gem Current Latest Requested Groups Release Date + terranova 8 9 = 8 default activesupport 2.3.5 3.0 = 2.3.5 development, test duradura 7.0 8.0 = 7.0 development, test + zondrian 1.2 1.3 = 1.2 development, test + TABLE + + expect(out).to end_with(expected_output) + end + + it "puts together the gems from the same groups declared in a different order" do + install_gemfile <<-G + source "https://gem.repo2" + + gem "terranova", '8' + group :test, :development do + gem 'activesupport', '2.3.5' + end + group :development, :test do + gem "duradura", '7.0' + end + G + + update_repo2 do + build_gem "activesupport", "3.0" + build_gem "terranova", "9" + build_gem "duradura", "8.0" + end + + bundle "outdated --groups", raise_on_error: false + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups Release Date terranova 8 9 = 8 default + activesupport 2.3.5 3.0 = 2.3.5 development, test + duradura 7.0 8.0 = 7.0 development, test TABLE expect(out).to end_with(expected_output)