spot 0.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spotify_spec.rb DELETED
@@ -1,435 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- describe Spot do
4
- before(:each) do
5
- @spot = Spot.new
6
- end
7
-
8
- context "tracks if success" do
9
- after(:each) do
10
- a_request(:get, @url).should have_been_made.once
11
- end
12
-
13
- before(:each) do
14
- @url = stubs("track", "kaizers orchestra")
15
- end
16
-
17
- it "should contain the right amounts of songs" do
18
- set_up(100, true)
19
- Spot.find_all_songs("kaizers orchestra").should have(100).results
20
- end
21
-
22
- it "should call SpotContainer::Song with the right arguments" do
23
- SpotContainer::Song.should_receive(:new) do |args|
24
- args["album"]["released"].should match(/^\d{4}$/)
25
- args["album"]["href"].should match(/^spotify\:album\:[a-zA-Z0-9]+$/)
26
- args["album"]["name"].should_not be_empty
27
- args["album"]["availability"]["territories"].should match(/[A-Z]{2}/)
28
-
29
- args["name"].should_not be_empty
30
- args["popularity"].should match(/[0-9\.]+/)
31
- args["length"].should be_instance_of(Float)
32
- args["href"].should match(/^spotify\:track\:[a-zA-Z0-9]+$/)
33
-
34
- validate_artists(args["artists"])
35
-
36
- mock_media(true)
37
- end.exactly(100).times
38
-
39
- Spot.find_all_songs("kaizers orchestra").results
40
- end
41
-
42
- it "should be able to cache a request" do
43
- set_up(100, true)
44
- spot = Spot.find_all_songs("kaizers orchestra")
45
- 10.times { spot.results }
46
- end
47
-
48
- it "should not have any songs if nothing is valid" do
49
- set_up(100, false)
50
- Spot.find_all_songs("kaizers orchestra").results.should be_empty
51
- end
52
- end
53
-
54
- context "artists if success" do
55
- after(:each) do
56
- a_request(:get, @url).should have_been_made.once
57
- end
58
-
59
- before(:each) do
60
- @url = stubs("artist", "kaizers orchestra")
61
- end
62
-
63
- it "should contain the right amounts of artists" do
64
- set_up(100, true, SpotContainer::Artist)
65
- Spot.find_all_artists("kaizers orchestra").should have(100).results
66
- end
67
-
68
- it "should call SpotContainer::Artist with the right arguments" do
69
- SpotContainer::Artist.should_receive(:new) do |args|
70
- args["name"].should_not be_empty
71
- args["popularity"].should match(/[0-9\.]+/)
72
- args["href"].should match(/^spotify\:artist\:[a-zA-Z0-9]+$/)
73
- mock_media(true)
74
- end.exactly(100).times
75
-
76
- Spot.find_all_artists("kaizers orchestra").results
77
- end
78
-
79
- it "should be able to cache a request" do
80
- set_up(100, true, SpotContainer::Artist)
81
- spot = Spot.find_all_artists("kaizers orchestra")
82
- 10.times { spot.results }
83
- end
84
-
85
- it "should not have any songs if nothing is valid" do
86
- set_up(100, false, SpotContainer::Artist)
87
- Spot.find_all_artists("kaizers orchestra").results.should be_empty
88
- end
89
- end
90
-
91
- context "album if success" do
92
- after(:each) do
93
- a_request(:get, @url).should have_been_made.once
94
- end
95
-
96
- before(:each) do
97
- @url = stubs("album", "kaizers orchestra")
98
- end
99
-
100
- it "should contain the right amounts of albums" do
101
- set_up(100, true, SpotContainer::Album)
102
- Spot.find_all_albums("kaizers orchestra").should have(100).results
103
- end
104
-
105
- it "should call SpotContainer::Album with the right arguments" do
106
- SpotContainer::Album.should_receive(:new) do |args|
107
- validate_artists(args["artists"])
108
-
109
- args["href"].should match(/^spotify\:album\:[a-zA-Z0-9]+$/)
110
-
111
- args["availability"]["territories"].should match(/[A-Z]{2}/)
112
- args["name"].should_not be_empty
113
- args["popularity"].should match(/[0-9\.]+/)
114
- mock_media(true)
115
- end.exactly(100).times
116
-
117
- Spot.find_all_albums("kaizers orchestra").results
118
- end
119
-
120
- it "should be possible to specify a territories" do
121
- Spot.territory("RANDOM").find_all_albums("kaizers orchestra").results.should be_empty
122
- end
123
-
124
- it "should be able to cache a request" do
125
- set_up(100, true, SpotContainer::Album)
126
- spot = Spot.find_all_albums("kaizers orchestra")
127
- 10.times { spot.results }
128
- end
129
-
130
- it "should not have any songs if nothing is valid" do
131
- set_up(100, false, SpotContainer::Album)
132
- Spot.find_all_albums("kaizers orchestra").results.should be_empty
133
- end
134
- end
135
-
136
- context "find_*" do
137
- after(:each) do
138
- a_request(:get, @url).should have_been_made.once
139
- end
140
-
141
- before(:each) do
142
- @url = stubs("track", "kaizers orchestra")
143
- end
144
-
145
- it "should only return one element" do
146
- Spot.find_song("kaizers orchestra").result.should be_instance_of(SpotContainer::Song)
147
- end
148
- end
149
-
150
- it "should be possible to set a page variable" do
151
- url = stubs("track", "kaizers orchestra", 11)
152
- Spot.page(11).find_song("kaizers orchestra").result.should be_instance_of(SpotContainer::Song)
153
- a_request(:get, url).should have_been_made.once
154
- end
155
-
156
- context "the prime method" do
157
- before(:each) do
158
- @url = stubs("track", "kaizers orchestra")
159
- end
160
-
161
- after(:each) do
162
- a_request(:get, @url).should have_been_made.once
163
- end
164
-
165
- it "should return the best match" do
166
- Spot.prime.find_song("kaizers orchestra").result.artist.name.should eq("Kaizers Orchestra")
167
- end
168
- end
169
-
170
- context "the cleaner" do
171
- after(:each) do
172
- a_request(:get, @url).should have_been_made.once
173
- end
174
-
175
- it "Song - Artist => Song Artist" do
176
- @url = stubs("track", "this is a string this to")
177
- Spot.strip.find_song("this is a string - this to").result
178
- end
179
-
180
- it "Song - A + B + C => Song A" do
181
- @url = stubs("track", "song a")
182
- Spot.strip.find_song("Song - A + B + C").result
183
- end
184
-
185
- it "Song - A abc/def => Song - A abc" do
186
- @url = stubs("track", "song a abc")
187
- Spot.strip.find_song("Song - A abc/def").result
188
- end
189
-
190
- it "Song - A & abc def => Song - A" do
191
- @url = stubs("track", "song a")
192
- Spot.strip.find_song("Song - A & abc def").result
193
- end
194
-
195
- it "Song A \"abc def\" => Song - A" do
196
- @url = stubs("track", "song a")
197
- Spot.strip.find_song("Song A \"abc def\"").result
198
- end
199
-
200
- it "Song - A [B + C] => Song - A" do
201
- @url = stubs("track", "song a")
202
- Spot.strip.find_song("Song - A [B + C]").result
203
- end
204
-
205
- it "Song - A (Super Song) => Song - A" do
206
- @url = stubs("track", "song a")
207
- Spot.strip.find_song("Song - A (Super Song)").result
208
- end
209
-
210
- it "Song A feat. (Super Song) => Song A" do
211
- @url = stubs("track", "song a")
212
- Spot.strip.find_song("Song A feat. (Super Song)").result
213
- end
214
-
215
- it "Song A feat.(Super Song) => Song A" do
216
- @url = stubs("track", "song a")
217
- Spot.strip.find_song("Song A feat. (Super Song)").result
218
- end
219
-
220
- it "Song A feat.Super B C => Song A B C" do
221
- @url = stubs("track", "song a b c")
222
- Spot.strip.find_song("Song A feat.Super B C").result
223
- end
224
-
225
- it "Song A feat Super B C => Song A B C" do
226
- @url = stubs("track", "song a b c")
227
- Spot.strip.find_song("Song A feat Super B C").result
228
- end
229
-
230
- it "A -- B => A B" do
231
- @url = stubs("track", "a b")
232
- Spot.strip.find_song("A -- B").result
233
- end
234
-
235
- it "123 A B => A B" do
236
- @url = stubs("track", "a b")
237
- Spot.strip.find_song("123 A B").result
238
- end
239
-
240
- it "123 A B.mp3 => A B" do
241
- @url = stubs("track", "a b")
242
- Spot.strip.find_song("123 A B.mp3").result
243
- end
244
-
245
- it "01. A B => A B" do
246
- @url = stubs("track", "a b")
247
- Spot.strip.find_song("01. A B").result
248
- end
249
-
250
- it " 01. A B => A B" do
251
- @url = stubs("track", "a b")
252
- Spot.strip.find_song(" 01. A B").result
253
- end
254
-
255
- it "123 A B.mp3(whitespace) => A B" do
256
- @url = stubs("track", "a b")
257
- Spot.strip.find_song("123 A B.mp3 ").result
258
- end
259
-
260
- it "A_B_C_D_E => A B C D E" do
261
- @url = stubs("track", "a b c d e")
262
- Spot.strip.find_song("A_B_C_D_E").result
263
- end
264
-
265
- it "100_A=> A" do
266
- @url = stubs("track", "a")
267
- Spot.strip.find_song("100_A").result
268
- end
269
-
270
- it "A 1.2.3.4.5 => A 1 2 3 4 5" do
271
- @url = stubs("track", "a 1 2 3 4 5")
272
- Spot.strip.find_song("A 1.2.3.4.5").result
273
- end
274
-
275
- unless RUBY_VERSION =~ /1\.8\.7/
276
- it "ÅÄÖ åäö å ä ö Å Ä Ö => AAO aao a a o A A O" do
277
- @url = stubs("track", "aao aao a a o a a o")
278
- Spot.strip.find_song("ÅÄÖ åäö å ä ö Å Ä Ö").result
279
- end
280
- end
281
-
282
- it "don't => don't (no change)" do
283
- @url = stubs("track", "don't")
284
- Spot.strip.find_song("don't").result
285
- end
286
-
287
- it "A 'don' B => A B" do
288
- @url = stubs("track", "a b")
289
- Spot.strip.find_song("A 'don' B").result
290
- end
291
- end
292
-
293
- context "method does not exist" do
294
- before(:each) do
295
- stubs("track", "string")
296
- end
297
-
298
- it "should raise no method error if the method does't exist (plain value)" do
299
- lambda { Spot.find_song("string").random_method }.should raise_error(NoMethodError)
300
- end
301
-
302
- it "should raise an error if the method matches find_*_*" do
303
- lambda { Spot.find_song("string").find_by_song }.should raise_error(NoMethodError)
304
- end
305
-
306
- it "should raise an error if the method matches find_all_* " do
307
- lambda { Spot.find_song("string").find_all_random }.should raise_error(NoMethodError)
308
- end
309
- end
310
-
311
- context "exclude" do
312
- it "should contain a list of non wanted words" do
313
- @spot.instance_eval do
314
- [
315
- "tribute",
316
- "cover",
317
- "remix",
318
- "live",
319
- "club mix",
320
- "karaoke",
321
- "club version",
322
- "remaster",
323
- "demo",
324
- "made famous by",
325
- "remixes",
326
- "instrumental(s)?",
327
- "ringtone(s)?"
328
- ].each do |value|
329
- @exclude.include?(value).should == true
330
- end
331
- end
332
- end
333
-
334
- it "should have a working exclude? method" do
335
- {
336
- "tribute" => true,
337
- "cover random" => true,
338
- "live" => true,
339
- "club mix random" => true,
340
- "LIVE" => true,
341
- "karaoKE" => true,
342
- "instrumental" => true,
343
- "Karaoke - Won't Get Fooled Again" => true,
344
- "club version" => true,
345
- "instrumentals" => true,
346
- "demo" => true,
347
- "made famous by" => true,
348
- "remixes" => true,
349
- "ringtone" => true,
350
- "ringtones" => true,
351
- "riingtonerandom" => false,
352
- "club random mix" => false,
353
- "random" => false
354
- }.each do |comp, outcome|
355
- @spot.exclude?(comp).should eq(outcome)
356
- end
357
- end
358
- end
359
-
360
- context "territory" do
361
- before(:each) do
362
- stubs("track", "search")
363
- end
364
-
365
- it "should not find any songs when using a non valid territory" do
366
- @spot.territory("RANDOM").find_all_songs("search").results.should be_empty
367
- end
368
-
369
- it "should find some songs when using a valid territory" do
370
- @spot.territory("SE").find_all_songs("search").results.should_not be_empty
371
- end
372
-
373
- it "should be ignored if nil" do
374
- @spot.territory(nil).find_all_songs("search").results.count.should eq(@spot.find_all_songs("search").results.count)
375
- end
376
- end
377
-
378
- context "bugs" do
379
- before(:each) do
380
- stub_request(:get, "http://ws.spotify.com/search/1/track.json?page=1&q=the%20rolling%20stones%20itn%20roll").
381
- to_return(:body => File.read("spec/fixtures/track.json"), :status => 200)
382
- end
383
-
384
- it "should not raise an error" do
385
- lambda { Spot.prime.strip.find_song("013 - The Rolling Stones - It's Only Rock 'N Roll.mp3").result }.should_not raise_error
386
- end
387
- end
388
-
389
- context "tribute" do
390
- before(:each) do
391
- stub_request(:get, "http://ws.spotify.com/search/1/track.json?page=1&q=britney%20spears%20tribute").
392
- to_return(:body => File.read("spec/fixtures/exclude.tribute.json"), :status => 200)
393
- end
394
-
395
- it "should not return anything" do
396
- Spot.prime.strip.find_song("Britney Spears Tribute").result.should be_nil
397
- end
398
- end
399
-
400
- context "prefix" do
401
- it "should be possible to add a prefix - without strip" do
402
- @url = stubs("track", "-A B C C")
403
- @spot.prefix("-A B C").find_song("C").result
404
- end
405
-
406
- it "should be possible to add a prefix - with strip" do
407
- @url = stubs("track", "a b c c")
408
- @spot.strip.prefix("-A B C").find_song("C").result
409
- end
410
-
411
- it "should be possible to add a prefix, 123 A B.mp3=> A B" do
412
- @url = stubs("track", "random a b")
413
- @spot.strip.prefix("random").find_song("123 A B.mp3 ").result
414
- end
415
-
416
- after(:each) do
417
- a_request(:get, @url).should have_been_made.once
418
- end
419
- end
420
-
421
- context "the info values" do
422
- after(:each) do
423
- a_request(:get, @url).should have_been_made.once
424
- end
425
-
426
- it "should have some info" do
427
- @url = stubs("track", "kaizers orchestra")
428
- spot = Spot.strip.find_song("kaizers orchestra")
429
- spot.num_results.should eq(188)
430
- spot.limit.should eq(100)
431
- spot.offset.should eq(0)
432
- spot.query.should eq("kaizers orchestra")
433
- end
434
- end
435
- end