-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gem_commands_contents_command.rb
154 lines (116 loc) · 3.2 KB
/
test_gem_commands_contents_command.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
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
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
def test_execute_bad_gem
@cmd.options[:args] = %w[foo]
assert_raises MockGemUi::TermError do
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
refute_match %r|Rakefile|, @ui.output
assert_equal "", @ui.error
end
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
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