grooveshark 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,39 +0,0 @@
1
- require File.expand_path("./helper", File.dirname(__FILE__))
2
-
3
- describe Grooveshark::Broadcast do
4
- let(:client) { Grooveshark::Client.new }
5
-
6
- describe "search" do
7
- let(:result) { client.top_broadcasts(10) }
8
-
9
- it "returns an array" do
10
- expect(result).to be_an Array
11
- expect(result.size).to eq 10
12
- end
13
-
14
- it "includes brodcasts" do
15
- all = result.all? { |item| item.kind_of?(Grooveshark::Broadcast) }
16
- expect(all).to be_true
17
- end
18
- end
19
-
20
- describe "broadcast" do
21
- let(:broadcast) { client.top_broadcasts.first }
22
-
23
- it "has a valid id" do
24
- expect(broadcast.id).to match /^[abcdef\d]{24}$/i
25
- end
26
-
27
- describe "#active_song" do
28
- it "is a song instance" do
29
- expect(broadcast.active_song).to be_a Grooveshark::Song
30
- end
31
- end
32
-
33
- describe "#next_song" do
34
- it "is a song instance" do
35
- expect(broadcast.active_song).to be_a Grooveshark::Song
36
- end
37
- end
38
- end
39
- end
@@ -1,85 +0,0 @@
1
- require File.expand_path("./helper", File.dirname(__FILE__))
2
-
3
- describe 'Client' do
4
- context 'initialization' do
5
- it 'should have a valid session' do
6
- @gs = Grooveshark::Client.new
7
- @gs.session.should_not == nil
8
- @gs.session.should match /^[abcdef\d]{32}$/i
9
- end
10
-
11
- it 'should have a valid country' do
12
- gs = Grooveshark::Client.new
13
- gs.country.should be_a_kind_of Hash
14
- gs.country.size.should == 7
15
- end
16
-
17
- it 'should have a valid token' do
18
- @gs = Grooveshark::Client.new
19
- @gs.comm_token.should_not == nil
20
- @gs.comm_token.should match /^[abcdef\d]{40}$/i
21
- end
22
- end
23
-
24
- context 'authentication' do
25
- it 'should raise InvalidAuthentication error for invalid credentials' do
26
- @gs = Grooveshark::Client.new
27
- lambda { @gs.login('invlid_user_name', 'invalid_password') }.should raise_error Grooveshark::InvalidAuthentication
28
- end
29
-
30
- it 'should obtain a new communication token on TTL expiration' do
31
- @gs = Grooveshark::Client.new(:ttl => 1)
32
- @tokens = []
33
-
34
- 3.times do |i|
35
- @gs.search_songs('Muse')
36
- @tokens << @gs.comm_token
37
- sleep 3
38
- end
39
-
40
- @tokens.uniq!
41
- @tokens.size.should == 3
42
- end
43
- end
44
-
45
- context 'search' do
46
- before(:all) do
47
- @gs = Grooveshark::Client.new
48
- end
49
-
50
- it 'should return empty songs collection' do
51
- songs = @gs.search_songs("@@@@@%%%%%%%@%@%%@")
52
- songs.should be_a_kind_of Array
53
- songs.size.should == 0
54
- end
55
-
56
- it 'should return songs collection' do
57
- songs = @gs.search_songs('Nirvana')
58
- songs.should be_a_kind_of Array
59
- songs.size.should_not == 0
60
- end
61
- end
62
-
63
- context 'download' do
64
- it 'should download without being banned' do
65
- gs = Grooveshark::Client.new
66
- ten_minutes_later = Time.new + 15 * 60 # Usually IP is banned after about 15 minutes
67
- while Time.new < ten_minutes_later do
68
- # Try with a short song (this one is about a minute long)
69
- song = gs.search_songs("Alan Reeves The Chase").first
70
- url = gs.get_song_url(song)
71
- file = RestClient::Request.execute(:method => :post, :url => url, :raw_response => true).file
72
- case mime_type = `file -b --mime-type #{file.path}`.strip
73
- when /^audio\//
74
- # This is the expected type
75
- when /^application\/octet-stream$/
76
- # Sometimes the file type can't be detected and this type is returned. At least we
77
- # check it's big enough to be an audio file.
78
- file.size.should >= 500 * 1024
79
- else
80
- raise RSpec::Expectations::ExpectationNotMetError, "Unknown MIME type (#{mime_type})"
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path("./helper", File.dirname(__FILE__))
2
-
3
- describe 'String' do
4
- it 'should normalize attributes' do
5
- vars = ['key_name', 'keyName', 'KeyName', 'KeyNAME']
6
- target = 'key_name'
7
- vars.each { |s| s.normalize_attribute.should == target }
8
- end
9
- end
10
-
11
- describe 'Hash' do
12
- it 'should normalize simple keys' do
13
- h = {'KeyName' => 'Value'}.normalize
14
-
15
- h.key?('KeyName').should == false
16
- h.key?('key_name').should == true
17
- end
18
-
19
- it 'should normalize symbol keys' do
20
- h = {:KeyName => 'Value'}.normalize
21
- h.key?(:KeyName).should == false
22
- h.key?('key_name').should == true
23
- end
24
-
25
- it 'should normalize nested data' do
26
- h = {
27
- 'keyA' => {'nestedKey' => 'Value'},
28
- 'keyB' => [{'arrKey' => 'Value'}]
29
- }.normalize
30
-
31
- h['key_a'].key?('nested_key').should == true
32
- h['key_b'].class.should == Array
33
- h['key_b'].first.key?('arr_key').should == true
34
- end
35
- end