2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/contents_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsContentsCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::ContentsCommand.new
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def gem name
|
|
|
|
spec = quick_gem name do |gem|
|
|
|
|
gem.files = %W[lib/#{name}.rb Rakefile]
|
|
|
|
end
|
|
|
|
write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
|
|
|
|
write_file File.join(*%W[gems #{spec.full_name} Rakefile])
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute
|
|
|
|
@cmd.options[:args] = %w[foo]
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
gem 'foo'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|lib/foo\.rb|, @ui.output
|
|
|
|
assert_match %r|Rakefile|, @ui.output
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_all
|
|
|
|
@cmd.options[:all] = true
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
|
|
|
gem 'bar'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|lib/foo\.rb|, @ui.output
|
|
|
|
assert_match %r|lib/bar\.rb|, @ui.output
|
|
|
|
assert_match %r|Rakefile|, @ui.output
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_bad_gem
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|Unable to find gem 'foo' in default gem paths|, @ui.output
|
|
|
|
assert_match %r|Directories searched:|, @ui.output
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_exact_match
|
|
|
|
@cmd.options[:args] = %w[foo]
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
|
|
|
gem 'bar'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|lib/foo\.rb|, @ui.output
|
|
|
|
assert_match %r|Rakefile|, @ui.output
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_lib_only
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:lib_only] = true
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|lib/foo\.rb|, @ui.output
|
2008-10-25 18:58:43 -04:00
|
|
|
refute_match %r|Rakefile|, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_multiple
|
|
|
|
@cmd.options[:args] = %w[foo bar]
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
|
|
|
gem 'bar'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r|lib/foo\.rb|, @ui.output
|
|
|
|
assert_match %r|lib/bar\.rb|, @ui.output
|
|
|
|
assert_match %r|Rakefile|, @ui.output
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_no_prefix
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:prefix] = false
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
Rakefile
|
2011-05-31 23:45:05 -04:00
|
|
|
lib/foo.rb
|
2009-06-09 17:38:59 -04:00
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.output
|
|
|
|
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_execute_default_gem
|
|
|
|
default_gem_spec = new_default_spec("default", "2.0.0.0",
|
|
|
|
nil, "default/gem.rb")
|
|
|
|
default_gem_spec.executables = ["default_command"]
|
|
|
|
default_gem_spec.files += ["default_gem.so"]
|
|
|
|
install_default_specs(default_gem_spec)
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[default]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2012-11-30 01:20:34 -05:00
|
|
|
expected = %W[
|
|
|
|
#{Gem::ConfigMap[:bindir]}/default_command
|
|
|
|
#{Gem::ConfigMap[:rubylibdir]}/default/gem.rb
|
|
|
|
#{Gem::ConfigMap[:archdir]}/default_gem.so
|
|
|
|
].sort.join "\n"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-11-30 01:20:34 -05:00
|
|
|
assert_equal expected, @ui.output.chomp
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_handle_options
|
2010-04-22 04:24:42 -04:00
|
|
|
refute @cmd.options[:lib_only]
|
|
|
|
assert @cmd.options[:prefix]
|
|
|
|
assert_empty @cmd.options[:specdirs]
|
|
|
|
assert_nil @cmd.options[:version]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
@cmd.send :handle_options, %w[-l -s foo --version 0.0.2 --no-prefix]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
assert @cmd.options[:lib_only]
|
|
|
|
refute @cmd.options[:prefix]
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal %w[foo], @cmd.options[:specdirs]
|
|
|
|
assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|