2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative "helper"
|
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
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2011-07-26 21:40:07 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "", @ui.output
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{Can.t find Ruby library file or shared library directory\n},
|
2011-07-26 21:40:07 -04:00
|
|
|
@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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@cmd.handle_options %w[foo_bar missinglib]
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2013-11-18 19:34:13 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{Can.t find Ruby library file or shared library missinglib\n},
|
2010-02-21 21:52:35 -05:00
|
|
|
@ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_missing
|
2012-11-29 01:52:18 -05:00
|
|
|
@cmd.handle_options %w[missinglib]
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2010-02-21 21:52:35 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "", @ui.output
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{Can.t find Ruby library file or shared library missinglib\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]
|
2013-11-11 19:16:41 -05:00
|
|
|
@foo_bar = util_spec "foo_bar" do |gem|
|
2010-02-21 21:52:35 -05:00
|
|
|
gem.files = files
|
|
|
|
end
|
2015-07-01 17:50:14 -04:00
|
|
|
install_specs @foo_bar
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
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
|