OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / test / rubygems / test_gem_commands_specification_command.rb
1 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
2 require 'rubygems/commands/specification_command'
3
4 class TestGemCommandsSpecificationCommand < RubyGemTestCase
5
6   def setup
7     super
8
9     @cmd = Gem::Commands::SpecificationCommand.new
10   end
11
12   def test_execute
13     foo = quick_gem 'foo'
14     Gem.source_index.add_spec foo
15
16     @cmd.options[:args] = %w[foo]
17
18     use_ui @ui do
19       @cmd.execute
20     end
21
22     assert_match %r|Gem::Specification|, @ui.output
23     assert_match %r|name: foo|, @ui.output
24     assert_equal '', @ui.error
25   end
26
27   def test_execute_all
28     foo1 = quick_gem 'foo', '0.0.1'
29     foo2 = quick_gem 'foo', '0.0.2'
30
31     @cmd.options[:args] = %w[foo]
32     @cmd.options[:all] = true
33
34     use_ui @ui do
35       @cmd.execute
36     end
37
38     assert_match %r|Gem::Specification|, @ui.output
39     assert_match %r|name: foo|, @ui.output
40     assert_match %r|version: 0.0.1|, @ui.output
41     assert_match %r|version: 0.0.2|, @ui.output
42     assert_equal '', @ui.error
43   end
44
45   def test_execute_bad_name
46     @cmd.options[:args] = %w[foo]
47
48     assert_raises MockGemUi::TermError do
49       use_ui @ui do
50         @cmd.execute
51       end
52     end
53
54     assert_equal '', @ui.output
55     assert_equal "ERROR:  Unknown gem 'foo'\n", @ui.error
56   end
57
58   def test_execute_exact_match
59     foo = quick_gem 'foo'
60     foo_bar = quick_gem 'foo_bar'
61
62     @cmd.options[:args] = %w[foo]
63
64     use_ui @ui do
65       @cmd.execute
66     end
67
68     assert_match %r|Gem::Specification|, @ui.output
69     assert_match %r|name: foo|, @ui.output
70     assert_equal '', @ui.error
71   end
72
73   def test_execute_remote
74     foo = quick_gem 'foo'
75
76     @fetcher = Gem::FakeFetcher.new
77     Gem::RemoteFetcher.fetcher = @fetcher
78
79     util_setup_spec_fetcher foo
80
81     FileUtils.rm File.join(@gemhome, 'specifications',
82                            "#{foo.full_name}.gemspec")
83
84     @cmd.options[:args] = %w[foo]
85     @cmd.options[:domain] = :remote
86
87     use_ui @ui do
88       @cmd.execute
89     end
90
91     assert_match %r|\A--- !ruby/object:Gem::Specification|, @ui.output
92     assert_match %r|name: foo|, @ui.output
93   end
94
95 end
96