Skip to content

Commit 2acfd65

Browse files
homusegiddins
authored andcommitted
Auto merge of #1873 - Fryguy:fix_query_command_with_exact, r=segiddins
Fix broken --exact parameter to gem command # Description: Before this patch `gem list --exact` fails with the following error: > gem list --exact aws-sdk *** LOCAL GEMS *** ERROR: While executing gem ... (TypeError) type mismatch: String given # Tasks: - [x] Describe the problem / feature - [x] Write tests - [x] Write code to solve the problem - [x] Get code review from coworkers / friends I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md). (cherry picked from commit 9da1964)
1 parent a02f60e commit 2acfd65

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

lib/rubygems/commands/query_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def execute
8686
name = Array(options[:name])
8787
else
8888
args = options[:args].to_a
89-
name = options[:exact] ? args : args.map{|arg| /#{arg}/i }
89+
name = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i }
9090
end
9191

9292
prerelease = options[:prerelease]

test/rubygems/test_gem_commands_query_command.rb

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def test_execute_local_details
642642
assert_equal expected, @ui.output
643643
end
644644

645-
def test_execute_exact
645+
def test_execute_exact_remote
646646
spec_fetcher do |fetcher|
647647
fetcher.spec 'coolgem-omg', 3
648648
fetcher.spec 'coolgem', '4.2.1'
@@ -665,6 +665,60 @@ def test_execute_exact
665665
assert_equal expected, @ui.output
666666
end
667667

668+
def test_execute_exact_local
669+
spec_fetcher do |fetcher|
670+
fetcher.spec 'coolgem-omg', 3
671+
fetcher.spec 'coolgem', '4.2.1'
672+
fetcher.spec 'wow_coolgem', 1
673+
end
674+
675+
@cmd.handle_options %w[--exact coolgem]
676+
677+
use_ui @ui do
678+
@cmd.execute
679+
end
680+
681+
expected = <<-EOF
682+
683+
*** LOCAL GEMS ***
684+
685+
coolgem (4.2.1)
686+
EOF
687+
688+
assert_equal expected, @ui.output
689+
end
690+
691+
def test_execute_exact_multiple
692+
spec_fetcher do |fetcher|
693+
fetcher.spec 'coolgem-omg', 3
694+
fetcher.spec 'coolgem', '4.2.1'
695+
fetcher.spec 'wow_coolgem', 1
696+
697+
fetcher.spec 'othergem-omg', 3
698+
fetcher.spec 'othergem', '1.2.3'
699+
fetcher.spec 'wow_othergem', 1
700+
end
701+
702+
@cmd.handle_options %w[--exact coolgem othergem]
703+
704+
use_ui @ui do
705+
@cmd.execute
706+
end
707+
708+
expected = <<-EOF
709+
710+
*** LOCAL GEMS ***
711+
712+
coolgem (4.2.1)
713+
714+
*** LOCAL GEMS ***
715+
716+
othergem (1.2.3)
717+
EOF
718+
719+
assert_equal expected, @ui.output
720+
end
721+
668722
private
669723

670724
def add_gems_to_fetcher

0 commit comments

Comments
 (0)