Skip to content

Commit

Permalink
+ Raise an error on install with multiple gems and --version
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Jun 29, 2012
1 parent ab86ce8 commit 62653cb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rubygems/commands/install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ def execute

exit_code = 0

if options[:version] != Gem::Requirement.default &&
get_all_gem_names.size > 1 then
alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
terminate_interaction 1
end

get_all_gem_names_and_versions.each do |gem_name, gem_version|
gem_version ||= options[:version]

Expand Down
20 changes: 20 additions & 0 deletions test/rubygems/test_gem_commands_install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,26 @@ def test_execute_two
assert out.empty?, out.inspect
end

def test_execute_two_version
@cmd.options[:args] = %w[a b]
@cmd.options[:version] = Gem::Requirement.new("> 1")

use_ui @ui do
e = assert_raises Gem::MockGemUi::TermError do
@cmd.execute
end

assert_equal 1, e.exit_code
end

assert_empty @cmd.installed_specs

msg = "ERROR: Can't use --version w/ multiple gems. Use name:ver instead."

assert_empty @ui.output
assert_equal msg, @ui.error.chomp
end

def test_execute_conservative
util_setup_fake_fetcher
util_setup_spec_fetcher
Expand Down

0 comments on commit 62653cb

Please sign in to comment.