2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/contents_command'
5 class TestGemCommandsContentsCommand < RubyGemTestCase
10 @cmd = Gem::Commands::ContentsCommand.new
14 @cmd.options[:args] = %w[foo]
15 quick_gem 'foo' do |gem|
16 gem.files = %w[lib/foo.rb Rakefile]
23 assert_match %r|lib/foo\.rb|, @ui.output
24 assert_match %r|Rakefile|, @ui.output
25 assert_equal "", @ui.error
28 def test_execute_bad_gem
29 @cmd.options[:args] = %w[foo]
31 assert_raise MockGemUi::TermError do
37 assert_match %r|Unable to find gem 'foo' in default gem paths|, @ui.output
38 assert_match %r|Directories searched:|, @ui.output
39 assert_equal "", @ui.error
42 def test_execute_exact_match
43 @cmd.options[:args] = %w[foo]
44 quick_gem 'foo' do |gem|
45 gem.files = %w[lib/foo.rb Rakefile]
48 quick_gem 'foo_bar' do |gem|
49 gem.files = %w[lib/foo_bar.rb Rakefile]
56 assert_match %r|lib/foo\.rb|, @ui.output
57 assert_match %r|Rakefile|, @ui.output
58 assert_equal "", @ui.error
61 def test_execute_lib_only
62 @cmd.options[:args] = %w[foo]
63 @cmd.options[:lib_only] = true
65 quick_gem 'foo' do |gem|
66 gem.files = %w[lib/foo.rb Rakefile]
73 assert_match %r|lib/foo\.rb|, @ui.output
74 assert_no_match %r|Rakefile|, @ui.output
76 assert_equal "", @ui.error
79 def test_handle_options
80 assert_equal false, @cmd.options[:lib_only]
81 assert_equal [], @cmd.options[:specdirs]
82 assert_equal nil, @cmd.options[:version]
84 @cmd.send :handle_options, %w[-l -s foo --version 0.0.2]
86 assert_equal true, @cmd.options[:lib_only]
87 assert_equal %w[foo], @cmd.options[:specdirs]
88 assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version]