gem-search 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,289 +0,0 @@
1
- include GemSearch
2
-
3
- RSpec.describe Executor do
4
- let(:executor) { Executor.new }
5
-
6
- describe '#search' do
7
- context 'when a network error occurred' do
8
- before do
9
- stub_request(:get, build_search_uri(query, 1))
10
- .to_return(status: 500, body: '[]')
11
- end
12
- let(:query) { 'network_error_orccurred' }
13
- it { expect { executor.search(query) }.to raise_error(Exception) }
14
- end
15
-
16
- context 'when no matching gem' do
17
- before { stub_request_search_no_result_with_page(query, 1) }
18
- let(:query) { 'no_match_gem_name' }
19
- it { expect { executor.search(query, default_opts) }.to raise_error(LibraryNotFound) }
20
- end
21
-
22
- describe 'with no-homepage' do
23
- before do
24
- stub_request_search(query, 1, dummy_search_result)
25
- stub_request_search_no_result_with_page(query, 2)
26
- end
27
- let(:query) { 'factory_girl' }
28
-
29
- context 'with no sort option' do
30
- it 'display rubygems ordering by DL(all)' do
31
- res = <<-'EOS'.unindent
32
- |Searching .
33
- |NAME DL(ver) DL(all)
34
- |-------------------------------------------------- -------- ---------
35
- |factory_girl (3.6.0) 541 2042859
36
- |factory_girl_rails (3.5.0) 39724 1238780
37
- |factory_girl_generator (0.0.3) 8015 15547
38
- EOS
39
- expect { executor.search(query, default_opts(has_homepage: false)) }.to output(res).to_stdout
40
- end
41
- end
42
- end
43
-
44
- describe 'sorting' do
45
- before do
46
- stub_request_search(query, 1, dummy_search_result)
47
- stub_request_search_no_result_with_page(query, 2)
48
- end
49
- let(:query) { 'factory_girl' }
50
-
51
- context 'with no sort option' do
52
- it 'display rubygems ordering by DL(all)' do
53
- res = <<-'EOS'.unindent
54
- |Searching .
55
- |NAME DL(ver) DL(all) HOMEPAGE
56
- |-------------------------------------------------- -------- --------- ------------------------------------------------------------
57
- |factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
58
- |factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
59
- |factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
60
- EOS
61
- expect { executor.search(query, default_opts) }.to output(res).to_stdout
62
- end
63
- end
64
-
65
- context 'with sort option: [a]download' do
66
- it 'display rubygems ordering by DL(all)' do
67
- res = <<-'EOS'.unindent
68
- |Searching .
69
- |NAME DL(ver) DL(all) HOMEPAGE
70
- |-------------------------------------------------- -------- --------- ------------------------------------------------------------
71
- |factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
72
- |factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
73
- |factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
74
- EOS
75
- expect { executor.search(query, default_opts) }.to output(res).to_stdout
76
- end
77
- end
78
-
79
- context 'with sort option: [v]version_downloads' do
80
- it 'display rubygems ordering by DL(ver)' do
81
- res = <<-'EOS'.unindent
82
- |Searching .
83
- |NAME DL(ver) DL(all) HOMEPAGE
84
- |-------------------------------------------------- -------- --------- ------------------------------------------------------------
85
- |factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
86
- |factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
87
- |factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
88
- EOS
89
- expect { executor.search(query, default_opts(sort: 'version_downloads')) }.to output(res).to_stdout
90
- end
91
- end
92
-
93
- context 'with sort option: [n]ame' do
94
- it 'display rubygems ordering by name' do
95
- res = <<-'EOS'.unindent
96
- |Searching .
97
- |NAME DL(ver) DL(all) HOMEPAGE
98
- |-------------------------------------------------- -------- --------- ------------------------------------------------------------
99
- |factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
100
- |factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
101
- |factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
102
- EOS
103
- expect { executor.search(query, default_opts(sort: 'name')) }.to output(res).to_stdout
104
- end
105
- end
106
- end
107
-
108
- describe 'multiple page' do
109
- before do
110
- stub_request_search(query, 1, load_http_stubs('search/cucumber-_1.json'))
111
- stub_request_search(query, 2, load_http_stubs('search/cucumber-_2.json'))
112
- stub_request_search(query, 3, load_http_stubs('search/cucumber-_3.json'))
113
- stub_request_search_no_result_with_page(query, 4)
114
- end
115
- let(:query) { 'cucumber-' }
116
- it 'display rubygems ordering by name' do
117
- res = <<-'EOS'.unindent
118
- |Searching ...
119
- |NAME DL(ver) DL(all) HOMEPAGE
120
- |-------------------------------------------------- -------- --------- ------------------------------------------------------------
121
- |autotest-cucumber-notification (0.0.6) 1027 3607 https://github.com/evrone/autotest-cucumber-notification
122
- |calabash-cucumber-cn (0.0.6) 88 88 http://github.com/cpunion/calabash-cucumber-cn
123
- |cucumber-ajaxer (0.0.4) 1875 4966 http://github.com/chalofa/cucumber-ajaxer
124
- |cucumber-api-steps (0.13) 1783 36587 http://github.com/jayzes/cucumber-api-steps
125
- |cucumber-blanket (0.3.0) 324 1674 https://github.com/keyvanfatehi/cucumber-blanket
126
- |cucumber-cafe (0.0.1) 295 295
127
- |cucumber-chef (3.0.8) 1545 28881 http://www.cucumber-chef.org
128
- |cucumber-cinema (0.8.0) 1309 9294 http://github.com/ilyakatz/cucumber-cinema
129
- |cucumber-core (0.2.0) 316 683 http://cukes.info
130
- |cucumber-core (0.2.0) 316 683 http://cukes.info
131
- |cucumber-debug (0.0.1) 1702 1702
132
- |cucumber-en_snippet (0.0.2) 295 565 https://github.com/mtsmfm/cucumber-en_snippet
133
- |cucumber-farmer (1.0.3) 1573 4398 http://github.com/mattscilipoti/cucumber-farmer
134
- |cucumber-formatter-oneline (0.1.0) 413 413
135
- |cucumber-in-the-yard (1.7.8) 2107 33260 http://github.com/burtlo/Cucumber-In-The-Yard
136
- |cucumber-java (0.0.2) 2113 3656 http://cukes.info
137
- |cucumber-jira (0.0.1.beta) 166 166 https://github.com/ipwnstuff/cucumber-jira
138
- |cucumber-json (0.0.2) 2199 3697 http://github.com/jnewland/cucumber-json
139
- |cucumber-jvm (1.1.6) 204 20913 http://github.com/cucumber/cucumber-jvm
140
- |cucumber-loggly (0.3.1) 903 4869 https://github.com/brettweavnet/cucumber-loggly
141
- |cucumber-mingle (1.0.0) 1539 1539
142
- |cucumber-nagios (0.9.2) 27094 75277 http://cucumber-nagios.org/
143
- |cucumber-nc (0.0.2) 162 1362 https://github.com/MrJoy/cucumber-nc
144
- |cucumber-newrelic (0.0.2) 1694 3201 http://github.com/jnewland/cucumber-newrelic
145
- |cucumber-notify (0.0.5) 1168 3348 https://github.com/argent-smith/autotest-cucumber-notification/tree/deprecated
146
- |cucumber-openerpscenario (0.1.9.1) 1110 11064
147
- |cucumber-peel (0.0.1) 1000 1000 https://github.com/testdouble/cucumber-peel
148
- |cucumber-pride (0.0.2) 1272 2321 https://github.com/pvdb/cucumber-pride
149
- |cucumber-profiler (1.0.0) 1171 1171 https://github.com/mblum14/cucumber-profiler
150
- |cucumber-puppet (0.3.7) 2974 24374 http://projects.puppetlabs.com/projects/cucumber-puppet
151
- |cucumber-rails (1.4.0) 286328 2700475 http://cukes.info
152
- |cucumber-rails-training-wheels (1.0.0) 109001 109001 http://cukes.info
153
- |cucumber-rails2 (0.3.5) 10776 13172 https://github.com/Vanuan/cucumber-rails
154
- |cucumber-rapid7 (0.0.1.beta.1) 101 430 https://github.com/ecarey-r7/cucumber-rapid7
155
- |cucumber-rapid7 (0.0.1.beta.1) 101 430 https://github.com/ecarey-r7/cucumber-rapid7
156
- |cucumber-relizy (0.0.2) 1433 2502 https://github.com/wynst/cucumber-relizy
157
- |cucumber-salad (0.4.0) 488 5326 https://github.com/mojotech/cucumber-salad
158
- |cucumber-salad (0.4.0) 488 5326 https://github.com/mojotech/cucumber-salad
159
- |cucumber-scout (0.0.2) 1634 3124 http://github.com/jnewland/cucumber-scout
160
- |cucumber-screenshot (0.3.4) 2241 15704 http://github.com/mocoso/cucumber-screenshot
161
- |cucumber-selenium-standalone (0.0.3) 1322 3593 http://github.com/techwhizbang/cucumber-selenium-standalone
162
- |cucumber-sinatra (0.5.0) 8463 28042 http://github.com/bernd/cucumber-sinatra
163
- |cucumber-slice (0.0.2) 629 1199 https://github.com/testdouble/cucumber-slice
164
- |cucumber-slices (0.0.4) 172 649 http://github.com/psytau/cucumber-slices
165
- |cucumber-sshd (0.1.0) 152 152 https://rubygems.org/gems/cucumber-sshd
166
- |cucumber-standalone (0.0.1) 1665 1665 http://github.com/jnewland/cucumber-standalone
167
- |cucumber-step_writer (0.1.2) 1251 3229
168
- |cucumber-table (0.0.1) 527 527
169
- |cucumber-the (1.0.0) 1209 1209
170
- |cucumber-timecop (0.0.3) 445 820 https://github.com/zedtux/cucumber-timecop
171
- |cucumber-timed_formatter (0.1.1) 1066 2165 http://github.com/kronn/cucumber-timed_formatter
172
- |cucumber-to-rally (0.1.3) 1001 3894
173
- |cucumber-usual_suspects (0.0.1) 1378 1378 http://github.com/mattwynne/cucumber-usual_suspects
174
- |cucumber-value (0.0.1) 1233 1233 https://github.com/hatofmonkeys/cucumber-value
175
- |cucumber-vimscript (0.0.3) 1097 3316 http://github.com/AndrewRadev/cucumber-vimscript
176
- |cucumber-voip (0.1.0) 1244 1244 https://github.com/benlangfeld/cucumber-voip
177
- |cucumber-websteps (0.10.0) 18583 22129 http://relishapp.com/kucaahbe/cucumber-websteps
178
- |cucumber-wordpress (1.3.1) 1346 7458 http://github.com/dxw/cucumber-wordpress
179
- |guard-cucumber-js (0.0.2) 1039 1935
180
- |mattscilipoti-cucumber-rails (0.2.4.2) 1394 3989 http://github.com/aslakhellesoy/cucumber-rails
181
- |mattscilipoti_cucumber-rails (0.2.4) 1401 1401 http://github.com/aslakhellesoy/cucumber-rails
182
- |tasty-cucumber-client (0.1.10) 1504 11518 http://tasty-cucumber.com
183
- |vagrant-cucumber-host (0.1.14) 163 163
184
- EOS
185
- expect { executor.search(query, default_opts(sort: 'name')) }.to output(res).to_stdout
186
- end
187
- end
188
-
189
- describe 'ruled NAME line' do
190
- context 'NAME size is 42' do
191
- before do
192
- stub_request_search(query, 1, dummy_search_result_name_size_is_42)
193
- stub_request_search_no_result_with_page(query, 2)
194
- end
195
- let(:query) { 'size_is_42_2345678901234567890123456789012' }
196
- it 'is 50 characters' do
197
- res = <<-'EOS'.unindent
198
- |Searching .
199
- |NAME DL(ver) DL(all) HOMEPAGE
200
- |-------------------------------------------------- -------- --------- ------------------------------------------------------------
201
- |size_is_42_2345678901234567890123456789012 (0.0.1) 100 1000
202
- EOS
203
- expect { executor.search(query, default_opts) }.to output(res).to_stdout
204
- end
205
- end
206
-
207
- context 'NAME size is 43' do
208
- before do
209
- stub_request_search(query, 1, dummy_search_result_name_size_is_43)
210
- stub_request_search_no_result_with_page(query, 2)
211
- end
212
- let(:query) { 'size_is_43_23456789012345678901234567890123' }
213
- it 'is 51 characters' do
214
- res = <<-'EOS'.unindent
215
- |Searching .
216
- |NAME DL(ver) DL(all) HOMEPAGE
217
- |--------------------------------------------------- -------- --------- ------------------------------------------------------------
218
- |size_is_43_23456789012345678901234567890123 (0.0.2) 200 2000
219
- EOS
220
- expect { executor.search(query, default_opts) }.to output(res).to_stdout
221
- end
222
- end
223
- end
224
- end
225
-
226
- describe '#browse' do
227
- context 'when a network error occurred' do
228
- before do
229
- stub_request(:get, build_gems_uri(query))
230
- .to_return(status: 500, body: '[]')
231
- end
232
- let(:query) { 'network_error_orccurred' }
233
- it { expect { executor.browse(query) }.to raise_error(Exception) }
234
- end
235
-
236
- context 'when no matching gem' do
237
- before { stub_request_gems_no_result(query) }
238
- let(:query) { 'no_match_gem_name' }
239
- it { expect { executor.browse(query) }.to raise_error(OpenURI::HTTPError) }
240
- end
241
-
242
- context 'when no homepage_uri' do
243
- before do
244
- url = Executor::GEM_URL % query
245
- allow(executor).to receive(:system).with(anything, url)
246
- stub_request_gems(query, load_http_stubs("gems/#{query}.json"))
247
- end
248
- let(:query) { 'git-trend_no_homepage' }
249
-
250
- it 'open a rubygems url' do
251
- executor.browse(query)
252
- end
253
- end
254
-
255
- context 'when homepage_uri is existed' do
256
- before do
257
- http_stub = load_http_stubs("gems/#{query}.json")
258
- url = JSON.parse(http_stub)['homepage_uri']
259
- allow(executor).to receive(:system).with(anything, url)
260
- stub_request_gems(query, http_stub)
261
- end
262
- let(:query) { 'git-trend' }
263
-
264
- it 'open a homepage url' do
265
- executor.browse(query)
266
- end
267
- end
268
- end
269
-
270
- private
271
-
272
- def dummy_search_result_name_size_is_42
273
- [{
274
- 'name' => 'size_is_42_2345678901234567890123456789012',
275
- 'downloads' => 1000,
276
- 'version' => '0.0.1',
277
- 'version_downloads' => 100
278
- }].to_json
279
- end
280
-
281
- def dummy_search_result_name_size_is_43
282
- [{
283
- 'name' => 'size_is_43_23456789012345678901234567890123',
284
- 'downloads' => 2000,
285
- 'version' => '0.0.2',
286
- 'version_downloads' => 200
287
- }].to_json
288
- end
289
- end