2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2010-02-21 21:52:35 -05:00
|
|
|
require 'rubygems/commands/which_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsWhichCommand < Gem::TestCase
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem::Specification.reset
|
2010-02-21 21:52:35 -05:00
|
|
|
@cmd = Gem::Commands::WhichCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
|
|
|
util_foo_bar
|
|
|
|
|
|
|
|
@cmd.handle_options %w[foo_bar]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2011-07-26 21:40:07 -04:00
|
|
|
def test_execute_directory
|
|
|
|
@cmd.handle_options %w[directory]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_match %r%Can.t find ruby library file or shared library directory\n%,
|
|
|
|
@ui.error
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_execute_one_missing
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: this test fails in isolation
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
util_foo_bar
|
|
|
|
|
2011-07-26 21:40:07 -04:00
|
|
|
@cmd.handle_options %w[foo_bar missing]
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
|
2011-07-26 21:40:07 -04:00
|
|
|
assert_match %r%Can.t find ruby library file or shared library missing\n%,
|
2010-02-21 21:52:35 -05:00
|
|
|
@ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_missing
|
2011-07-26 21:40:07 -04:00
|
|
|
@cmd.handle_options %w[missing]
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
2011-01-28 18:46:47 -05:00
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
2010-02-21 21:52:35 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
2011-07-26 21:40:07 -04:00
|
|
|
assert_match %r%Can.t find ruby library file or shared library missing\n%,
|
2010-02-21 21:52:35 -05:00
|
|
|
@ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def util_foo_bar
|
2011-07-26 21:40:07 -04:00
|
|
|
files = %w[lib/foo_bar.rb lib/directory/baz.rb Rakefile]
|
2011-03-01 04:41:32 -05:00
|
|
|
@foo_bar = quick_spec 'foo_bar' do |gem|
|
2010-02-21 21:52:35 -05:00
|
|
|
gem.files = files
|
|
|
|
end
|
|
|
|
|
|
|
|
files.each do |file|
|
2011-05-31 23:45:05 -04:00
|
|
|
filename = File.join(@foo_bar.full_gem_path, file)
|
|
|
|
FileUtils.mkdir_p File.dirname filename
|
2010-02-21 21:52:35 -05:00
|
|
|
FileUtils.touch filename
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|