2009-10-03 11:59:29 -04:00
|
|
|
require_relative 'gemutilities'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/contents_command'
|
|
|
|
|
|
|
|
class TestGemCommandsContentsCommand < RubyGemTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::ContentsCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
quick_gem 'foo' do |gem|
|
|
|
|
gem.files = %w[lib/foo.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
quick_gem 'foo' do |gem|
|
|
|
|
gem.files = %w[lib/foo.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem 'bar' do |gem|
|
|
|
|
gem.files = %w[lib/bar.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises 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]
|
|
|
|
quick_gem 'foo' do |gem|
|
|
|
|
gem.files = %w[lib/foo.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem 'foo_bar' do |gem|
|
|
|
|
gem.files = %w[lib/foo_bar.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
quick_gem 'foo' do |gem|
|
|
|
|
gem.files = %w[lib/foo.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
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]
|
|
|
|
quick_gem 'foo' do |gem|
|
|
|
|
gem.files = %w[lib/foo.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem 'bar' do |gem|
|
|
|
|
gem.files = %w[lib/bar.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
quick_gem 'foo' do |gem|
|
|
|
|
gem.files = %w[lib/foo.rb Rakefile]
|
|
|
|
end
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
lib/foo.rb
|
|
|
|
Rakefile
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.output
|
|
|
|
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_handle_options
|
|
|
|
assert_equal false, @cmd.options[:lib_only]
|
|
|
|
assert_equal [], @cmd.options[:specdirs]
|
|
|
|
assert_equal nil, @cmd.options[:version]
|
|
|
|
|
|
|
|
@cmd.send :handle_options, %w[-l -s foo --version 0.0.2]
|
|
|
|
|
|
|
|
assert_equal true, @cmd.options[:lib_only]
|
|
|
|
assert_equal %w[foo], @cmd.options[:specdirs]
|
|
|
|
assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|