2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2014-09-13 23:30:02 -04:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/commands/open_command'
|
|
|
|
|
|
|
|
class TestGemCommandsOpenCommand < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::OpenCommand.new
|
|
|
|
end
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
def gem(name, version = "1.0")
|
2014-09-13 23:30:02 -04:00
|
|
|
spec = quick_gem name do |gem|
|
|
|
|
gem.files = %W[lib/#{name}.rb Rakefile]
|
2016-03-03 19:29:40 -05:00
|
|
|
gem.version = version
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
|
|
|
|
write_file File.join(*%W[gems #{spec.full_name} Rakefile])
|
2015-02-05 08:42:45 -05:00
|
|
|
spec
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:editor] = "#{Gem.ruby} -e0 --"
|
|
|
|
|
2017-05-01 07:40:46 -04:00
|
|
|
gem 'foo', '1.0.0'
|
|
|
|
spec = gem 'foo', '1.0.1'
|
2020-03-27 05:22:21 -04:00
|
|
|
mock = Minitest::Mock.new
|
2015-02-05 08:42:45 -05:00
|
|
|
mock.expect(:call, true, [spec.full_gem_path])
|
2014-09-13 23:30:02 -04:00
|
|
|
|
2015-02-05 08:42:45 -05:00
|
|
|
Dir.stub(:chdir, mock) do
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
2015-02-05 08:42:45 -05:00
|
|
|
assert mock.verify
|
2014-09-13 23:30:02 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
def test_wrong_version
|
|
|
|
@cmd.options[:version] = "4.0"
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
|
|
|
gem "foo", "5.0"
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2016-03-03 19:29:40 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{Unable to find gem 'foo'}, @ui.output
|
2016-03-03 19:29:40 -05:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_execute_bad_gem
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2014-09-13 23:30:02 -04:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{Unable to find gem 'foo'}, @ui.output
|
2014-09-13 23:30:02 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2018-08-27 06:05:04 -04:00
|
|
|
def test_default_gem
|
|
|
|
@cmd.options[:version] = "1.0"
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
|
|
|
version = @cmd.options[:version]
|
|
|
|
@cmd.define_singleton_method(:spec_for) do |name|
|
|
|
|
spec = Gem::Specification.find_all_by_name(name, version).first
|
|
|
|
|
|
|
|
spec.define_singleton_method(:default_gem?) do
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
return spec if spec
|
|
|
|
|
|
|
|
say "Unable to find gem '#{name}'"
|
|
|
|
end
|
|
|
|
|
|
|
|
gem("foo", "1.0")
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2018-08-27 06:05:04 -04:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{'foo' is a default gem and can't be opened\.} , @ui.output
|
2018-08-27 06:05:04 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|