Skip to content

Commit 3efe965

Browse files
simideivid-rodriguez
authored andcommitted
Merge pull request #4613 from tnir/4612-beter-gem-help-build
Fix `gem help build` output format (cherry picked from commit 608c4e4)
1 parent 6a9e89b commit 3efe965

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lib/rubygems/command.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ def when_invoked(&block)
355355
def add_option(*opts, &handler) # :yields: value, options
356356
group_name = Symbol === opts.first ? opts.shift : :options
357357

358+
raise "Do not pass an empty string in opts" if opts.include?("")
359+
358360
@option_groups[group_name] << [opts, handler]
359361
end
360362

lib/rubygems/commands/build_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def initialize
2323
options[:output] = value
2424
end
2525

26-
add_option '-C PATH', '', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options|
26+
add_option '-C PATH', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options|
2727
options[:build_path] = value
2828
end
2929
end

test/rubygems/test_gem_command.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ def test_invoke_with_options
189189
assert_match %r{Usage: gem doit}, @ui.output
190190
end
191191

192+
def test_add_option
193+
assert_nothing_raised RuntimeError do
194+
@cmd.add_option('--force', 'skip validation of the spec') {|v,o| }
195+
end
196+
end
197+
198+
def test_add_option_with_empty
199+
assert_raise RuntimeError, "Do not pass an empty string in opts" do
200+
@cmd.add_option('', 'skip validation of the spec') {|v,o| }
201+
end
202+
end
203+
192204
def test_option_recognition
193205
@cmd.add_option('-h', '--help [COMMAND]', 'Get help on COMMAND') do |value, options|
194206
options[:help] = true

test/rubygems/test_gem_commands_help_command.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def test_gem_help_platforms
3535
end
3636
end
3737

38+
def test_gem_help_build
39+
util_gem 'build' do |out, err|
40+
assert_match(/-C PATH *Run as if gem build was started in <PATH>/, out)
41+
assert_equal '', err
42+
end
43+
end
44+
3845
def test_gem_help_commands
3946
mgr = Gem::CommandManager.new
4047

0 commit comments

Comments
 (0)