Skip to content

Commit 4619f13

Browse files
author
Thibault Jouan
committed
Fix setup command --regenerate-binstubs option flag
`--[no-]regenerate-binstubs' option flag was added in 909b5fb but is not used yet. This change tests if the option was set before calling Gem::Commands::SetupCommand#regenerate_binstubs. We also simplify how the option is set, since it's more similar to `format_executable' for example (simple option flag), rather than `document' where we use the same hash key for multiple options. This way we can just test the value being either true or false, instead of testing key presence (`Hash#key?') or relying on `nil' being returned for nonexistent hash keys with `Hash#[]'.
1 parent ac7d289 commit 4619f13

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/rubygems/commands/setup_command.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ def initialize
8282

8383
add_option '--[no-]regenerate-binstubs',
8484
'Regenerate gem binstubs' do |value, options|
85-
if value then
86-
options[:regenerate_binstubs] = true
87-
else
88-
options.delete(:regenerate_binstubs)
89-
end
85+
options[:regenerate_binstubs] = value
9086
end
9187

9288
@verbose = nil
@@ -156,7 +152,7 @@ def execute
156152

157153
say "RubyGems #{Gem::VERSION} installed"
158154

159-
regenerate_binstubs
155+
regenerate_binstubs if options[:regenerate_binstubs]
160156

161157
uninstall_old_gemcutter
162158

test/rubygems/test_gem_commands_setup_command.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ def test_execute_regenerate_binstubs
7777
assert_match %r{\A#!}, File.read(gem_bin_path)
7878
end
7979

80+
def test_execute_no_regenerate_binstubs
81+
gem_bin_path = gem_install 'a'
82+
write_file gem_bin_path do |io|
83+
io.puts 'I changed it!'
84+
end
85+
86+
@cmd.options[:document] = []
87+
@cmd.options[:regenerate_binstubs] = false
88+
@cmd.execute
89+
90+
assert_equal "I changed it!\n", File.read(gem_bin_path)
91+
end
92+
8093
def test_pem_files_in
8194
assert_equal %w[rubygems/ssl_certs/rubygems.org/foo.pem],
8295
@cmd.pem_files_in('lib').sort

0 commit comments

Comments
 (0)