hallon 0.18.0 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/CHANGELOG.md +12 -1
- data/README.markdown +13 -5
- data/Rakefile +23 -74
- data/examples/example_support.rb +2 -0
- data/hallon.gemspec +1 -1
- data/lib/hallon.rb +1 -6
- data/lib/hallon/album.rb +4 -4
- data/lib/hallon/album_browse.rb +6 -6
- data/lib/hallon/artist.rb +3 -3
- data/lib/hallon/artist_browse.rb +9 -9
- data/lib/hallon/audio_queue.rb +2 -1
- data/lib/hallon/base.rb +10 -10
- data/lib/hallon/enumerator.rb +3 -3
- data/lib/hallon/ext/spotify.rb +1 -47
- data/lib/hallon/image.rb +4 -4
- data/lib/hallon/link.rb +4 -4
- data/lib/hallon/linkable.rb +10 -10
- data/lib/hallon/observable/playlist.rb +2 -3
- data/lib/hallon/observable/playlist_container.rb +3 -12
- data/lib/hallon/player.rb +2 -2
- data/lib/hallon/playlist.rb +6 -6
- data/lib/hallon/playlist_container.rb +8 -8
- data/lib/hallon/scrobbler.rb +4 -4
- data/lib/hallon/search.rb +20 -5
- data/lib/hallon/session.rb +18 -17
- data/lib/hallon/toplist.rb +4 -4
- data/lib/hallon/track.rb +5 -5
- data/lib/hallon/user.rb +7 -7
- data/lib/hallon/version.rb +1 -1
- data/spec/hallon/album_browse_spec.rb +1 -1
- data/spec/hallon/artist_browse_spec.rb +1 -1
- data/spec/hallon/base_spec.rb +6 -3
- data/spec/hallon/enumerator_spec.rb +2 -2
- data/spec/hallon/hallon_spec.rb +0 -4
- data/spec/hallon/link_spec.rb +1 -1
- data/spec/hallon/linkable_spec.rb +4 -4
- data/spec/hallon/observable/playlist_container_spec.rb +3 -3
- data/spec/hallon/observable/playlist_spec.rb +1 -1
- data/spec/hallon/player_spec.rb +9 -9
- data/spec/hallon/playlist_container_spec.rb +2 -2
- data/spec/hallon/playlist_spec.rb +8 -8
- data/spec/hallon/scrobbler_spec.rb +8 -7
- data/spec/hallon/search_spec.rb +3 -3
- data/spec/hallon/session_spec.rb +10 -10
- data/spec/hallon/toplist_spec.rb +4 -4
- data/spec/hallon/track_spec.rb +6 -6
- data/spec/hallon/user_post_spec.rb +1 -1
- data/spec/hallon/user_spec.rb +1 -1
- data/spec/mockspotify.rb +36 -42
- data/spec/mockspotify/mockspotify_spec.rb +15 -15
- data/spec/spec_helper.rb +25 -21
- data/spec/support/album_mocks.rb +4 -4
- data/spec/support/artist_mocks.rb +5 -5
- data/spec/support/image_mocks.rb +4 -4
- data/spec/support/playlist_container_mocks.rb +4 -4
- data/spec/support/playlist_mocks.rb +6 -6
- data/spec/support/search_mocks.rb +2 -2
- data/spec/support/session_mocks.rb +1 -1
- data/spec/support/shared_for_callbacks.rb +1 -1
- data/spec/support/shared_for_linkable_objects.rb +3 -2
- data/spec/support/toplist_mocks.rb +2 -2
- data/spec/support/track_mocks.rb +4 -4
- data/spec/support/user_mocks.rb +2 -2
- metadata +5 -5
@@ -102,7 +102,7 @@ describe Hallon::PlaylistContainer do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should return nil when failing to add the item" do
|
105
|
-
|
105
|
+
spotify_api.should_receive(:playlistcontainer_add_playlist).and_return(null_pointer)
|
106
106
|
playlist = container.add Hallon::Link.new("spotify:user:burgestrand")
|
107
107
|
playlist.should be_nil
|
108
108
|
end
|
@@ -295,7 +295,7 @@ describe Hallon::PlaylistContainer do
|
|
295
295
|
end
|
296
296
|
|
297
297
|
it "raises an error if the result was an error (but count was not)" do
|
298
|
-
|
298
|
+
spotify_api.should_receive(:playlistcontainer_get_unseen_tracks).and_return(4, -1)
|
299
299
|
expect { container.unseen_tracks_for(empty_playlist) }.to raise_error(Hallon::OperationFailedError)
|
300
300
|
end
|
301
301
|
end
|
@@ -137,7 +137,7 @@ describe Hallon::Playlist do
|
|
137
137
|
|
138
138
|
describe "#tracks" do
|
139
139
|
it "returns an enumerator of the playlist’s tracks" do
|
140
|
-
playlist.tracks.to_a.should eq instantiate(Hallon::Playlist::Track, *(0...4).map { |index| [Spotify.playlist_track
|
140
|
+
playlist.tracks.to_a.should eq instantiate(Hallon::Playlist::Track, *(0...4).map { |index| [Spotify.playlist_track(playlist.pointer, index), playlist.pointer, index] })
|
141
141
|
end
|
142
142
|
|
143
143
|
it "returns an empty enumerator if the playlist has no tracks" do
|
@@ -231,7 +231,7 @@ describe Hallon::Playlist do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should return an empty array when there are no subscribers" do
|
234
|
-
|
234
|
+
spotify_api.should_receive(:playlist_subscribers).and_return(mock_empty_subscribers)
|
235
235
|
playlist.subscribers.should eq []
|
236
236
|
end
|
237
237
|
|
@@ -321,9 +321,9 @@ describe Hallon::Playlist do
|
|
321
321
|
|
322
322
|
describe "#autolink_tracks=" do
|
323
323
|
it "should set autolink status" do
|
324
|
-
Spotify.
|
324
|
+
Spotify.mock_playlist_get_autolink_tracks(playlist.pointer).should be_false
|
325
325
|
playlist.autolink_tracks = true
|
326
|
-
Spotify.
|
326
|
+
Spotify.mock_playlist_get_autolink_tracks(playlist.pointer).should be_true
|
327
327
|
end
|
328
328
|
end
|
329
329
|
|
@@ -359,22 +359,22 @@ describe Hallon::Playlist do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
specify "#available_offline?" do
|
362
|
-
|
362
|
+
spotify_api.should_receive(:playlist_get_offline_status).and_return symbol_for(1)
|
363
363
|
playlist.should be_available_offline
|
364
364
|
end
|
365
365
|
|
366
366
|
specify "#syncing?" do
|
367
|
-
|
367
|
+
spotify_api.should_receive(:playlist_get_offline_status).and_return symbol_for(2)
|
368
368
|
playlist.should be_syncing
|
369
369
|
end
|
370
370
|
|
371
371
|
specify "#waiting?" do
|
372
|
-
|
372
|
+
spotify_api.should_receive(:playlist_get_offline_status).and_return symbol_for(3)
|
373
373
|
playlist.should be_waiting
|
374
374
|
end
|
375
375
|
|
376
376
|
specify "#offline_mode?" do
|
377
|
-
|
377
|
+
spotify_api.should_receive(:playlist_get_offline_status).and_return symbol_for(0)
|
378
378
|
playlist.should_not be_offline_mode
|
379
379
|
end
|
380
380
|
end
|
@@ -21,24 +21,24 @@ describe Hallon::Scrobbler do
|
|
21
21
|
|
22
22
|
describe "#credentials=" do
|
23
23
|
it "sets the credentials for the scrobbler provider" do
|
24
|
-
|
24
|
+
spotify_api.should_receive(:session_set_social_credentials).with(anything, :facebook, "Kim", "password").and_return(:ok)
|
25
25
|
scrobbling.credentials = "Kim", "password"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#possible?" do
|
30
30
|
it "returns true if scrobbling is possible" do
|
31
|
-
Spotify.
|
31
|
+
Spotify.mock_session_set_is_scrobbling_possible(session.pointer, scrobbling.provider, true)
|
32
32
|
scrobbling.should be_possible
|
33
33
|
end
|
34
34
|
|
35
35
|
it "returns false if scrobbling is not possible" do
|
36
|
-
Spotify.
|
36
|
+
Spotify.mock_session_set_is_scrobbling_possible(session.pointer, scrobbling.provider, false)
|
37
37
|
scrobbling.should_not be_possible
|
38
38
|
end
|
39
39
|
|
40
40
|
it "raises an error if libspotify does not like us" do
|
41
|
-
|
41
|
+
spotify_api.should_receive(:session_is_scrobbling_possible).and_return(:invalid_indata)
|
42
42
|
expect { scrobbling.possible? }.to raise_error(Spotify::Error)
|
43
43
|
end
|
44
44
|
end
|
@@ -53,14 +53,14 @@ describe Hallon::Scrobbler do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "raises an error if setting scrobbling state fails" do
|
56
|
-
|
56
|
+
spotify_api.should_receive(:session_set_scrobbling).and_return(:invalid_indata)
|
57
57
|
expect { scrobbling.enabled = true }.to raise_error(Spotify::Error, /INVALID_INDATA/)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe "#enabled?" do
|
62
62
|
before do
|
63
|
-
|
63
|
+
spotify_api.should_receive(:session_is_scrobbling).and_return do |session, provider, buffer|
|
64
64
|
buffer.write_int(Spotify.enum_value(state_symbol))
|
65
65
|
end
|
66
66
|
end
|
@@ -103,13 +103,14 @@ describe Hallon::Scrobbler do
|
|
103
103
|
session = scrobbling.send(:session)
|
104
104
|
state = nil
|
105
105
|
FFI::Buffer.alloc_out(:int) do |buffer|
|
106
|
-
Spotify.session_is_scrobbling
|
106
|
+
Spotify.try(:session_is_scrobbling, session.pointer, scrobbling.provider, buffer)
|
107
107
|
state = buffer.read_int
|
108
108
|
end
|
109
109
|
Spotify.enum_type(:scrobbling_state)[state]
|
110
110
|
end
|
111
111
|
|
112
112
|
it "sets the local scrobbling state to use the global state" do
|
113
|
+
state(scrobbling).should eq :use_global_setting
|
113
114
|
scrobbling.enabled = true
|
114
115
|
state(scrobbling).should eq :local_enabled
|
115
116
|
scrobbling.reset
|
data/spec/hallon/search_spec.rb
CHANGED
@@ -21,12 +21,12 @@ describe Hallon::Search do
|
|
21
21
|
|
22
22
|
describe ".new" do
|
23
23
|
it "should have some sane defaults" do
|
24
|
-
|
24
|
+
spotify_api.should_receive(:search_create).with(session.pointer, "my å utf8 query", 0, 25, 0, 25, 0, 25, 0, 25, :standard, anything, anything).and_return(mock_search)
|
25
25
|
Hallon::Search.new("my å utf8 query")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should allow you to customize the defaults" do
|
29
|
-
|
29
|
+
spotify_api.should_receive(:search_create).with(session.pointer, "my å utf8 query", 1, 2, 3, 4, 5, 6, 7, 8, :suggest, anything, anything).and_return(mock_search)
|
30
30
|
my_params = {
|
31
31
|
:tracks_offset => 1,
|
32
32
|
:tracks => 2,
|
@@ -47,7 +47,7 @@ describe Hallon::Search do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should raise an error if the search failed" do
|
50
|
-
|
50
|
+
spotify_api.should_receive(:search_create).and_return(null_pointer)
|
51
51
|
expect { Hallon::Search.new("omgwtfbbq") }.to raise_error(/search (.*?) failed/)
|
52
52
|
end
|
53
53
|
end
|
data/spec/hallon/session_spec.rb
CHANGED
@@ -57,12 +57,12 @@ describe Hallon::Session do
|
|
57
57
|
describe "options" do
|
58
58
|
subject { session.options }
|
59
59
|
its([:user_agent]) { should == options[:user_agent] }
|
60
|
-
its([:
|
61
|
-
its([:
|
60
|
+
its([:settings_location]) { should == options[:settings_location] }
|
61
|
+
its([:cache_location]) { should == options[:cache_location] }
|
62
62
|
|
63
|
-
its([:
|
63
|
+
its([:initially_unload_playlists]) { should == false }
|
64
64
|
its([:compress_playlists]) { should == true }
|
65
|
-
its([:
|
65
|
+
its([:dont_save_metadata_for_playlists]) { should == false }
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "#container" do
|
@@ -133,12 +133,12 @@ describe Hallon::Session do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should login with a blob when given a blob" do
|
136
|
-
|
136
|
+
spotify_api.should_receive(:session_login).with(anything, 'Kim', nil, false, 'blob')
|
137
137
|
session.login 'Kim', Hallon::Blob('blob')
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should not login with a blob when not given a blob" do
|
141
|
-
|
141
|
+
spotify_api.should_receive(:session_login).with(anything, 'Kim', 'pass', false, nil)
|
142
142
|
session.login 'Kim', 'pass'
|
143
143
|
end
|
144
144
|
end
|
@@ -241,7 +241,7 @@ describe Hallon::Session do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should combine given rules and feed to libspotify" do
|
244
|
-
|
244
|
+
spotify_api.should_receive(:session_set_connection_rules).with(session.pointer, 5)
|
245
245
|
session.connection_rules = :network, :allow_sync_over_mobile
|
246
246
|
end
|
247
247
|
end
|
@@ -261,7 +261,7 @@ describe Hallon::Session do
|
|
261
261
|
end
|
262
262
|
|
263
263
|
it "returns an empty hash when offline sync status details are unavailable" do
|
264
|
-
|
264
|
+
spotify_api.should_receive(:offline_sync_get_status).and_return(false)
|
265
265
|
session.offline_sync_status.should eq Hash.new
|
266
266
|
end
|
267
267
|
end
|
@@ -281,12 +281,12 @@ describe Hallon::Session do
|
|
281
281
|
|
282
282
|
describe "#offline_bitrate=" do
|
283
283
|
it "should not resync unless explicitly told so" do
|
284
|
-
|
284
|
+
spotify_api.should_receive(:session_preferred_offline_bitrate).with(session.pointer, :'96k', false).and_return(:ok)
|
285
285
|
session.offline_bitrate = :'96k'
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should resync if asked to" do
|
289
|
-
|
289
|
+
spotify_api.should_receive(:session_preferred_offline_bitrate).with(session.pointer, :'96k', true).and_return(:ok)
|
290
290
|
session.offline_bitrate = :'96k', :resync
|
291
291
|
end
|
292
292
|
|
data/spec/hallon/toplist_spec.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
describe Hallon::Toplist do
|
4
4
|
let(:toplist) do
|
5
|
-
Spotify.
|
5
|
+
Spotify.mock_registry_add 'spotify:toplist:artists:everywhere', mock_toplistbrowse
|
6
6
|
Hallon::Toplist.new(:artists)
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:empty_toplist) do
|
10
|
-
Spotify.
|
10
|
+
Spotify.mock_registry_add 'spotify:toplist:tracks:everywhere', mock_empty_toplistbrowse
|
11
11
|
Hallon::Toplist.new(:tracks)
|
12
12
|
end
|
13
13
|
|
@@ -20,12 +20,12 @@ describe Hallon::Toplist do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should pass the username given a string to libspotify" do
|
23
|
-
Spotify.
|
23
|
+
Spotify.mock_registry_add 'spotify:toplist:user:Kim:tracks', mock_toplistbrowse
|
24
24
|
Hallon::Toplist.new(:tracks, "Kim").should be_loaded
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should pass the correct region to libspotify" do
|
28
|
-
Spotify.
|
28
|
+
Spotify.mock_registry_add 'spotify:toplist:tracks:SE', mock_toplistbrowse
|
29
29
|
Hallon::Toplist.new(:tracks, :se).should be_loaded
|
30
30
|
end
|
31
31
|
end
|
data/spec/hallon/track_spec.rb
CHANGED
@@ -171,9 +171,9 @@ describe Hallon::Track do
|
|
171
171
|
|
172
172
|
describe "#unwrap" do
|
173
173
|
let(:track) { Hallon::Track.new(mock_track_two) }
|
174
|
-
let(:playlist) { Spotify.link_create_from_string
|
175
|
-
let(:artist) { Spotify.link_create_from_string
|
176
|
-
let(:album) { Spotify.link_create_from_string
|
174
|
+
let(:playlist) { Spotify.link_create_from_string('spotify:user:burgestrand:playlist:07AX9IY9Hqmj1RqltcG0fi') }
|
175
|
+
let(:artist) { Spotify.link_create_from_string('spotify:artist:3bftcFwl4vqRNNORRsqm1G') }
|
176
|
+
let(:album) { Spotify.link_create_from_string('spotify:album:1xvnWMz2PNFf7mXOSRuLws') }
|
177
177
|
|
178
178
|
it "does nothing if the track is not a placeholder" do
|
179
179
|
track.stub(:placeholder? => false)
|
@@ -181,17 +181,17 @@ describe Hallon::Track do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should unwrap a playlist placeholder into a playlist" do
|
184
|
-
|
184
|
+
spotify_api.should_receive(:link_create_from_track).and_return(playlist)
|
185
185
|
track.unwrap.should eq Hallon::Playlist.new(playlist)
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should unwrap an album placeholder into an album" do
|
189
|
-
|
189
|
+
spotify_api.should_receive(:link_create_from_track).and_return(album)
|
190
190
|
track.unwrap.should eq Hallon::Album.new(album)
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should unwrap an artist placeholder into an artist" do
|
194
|
-
|
194
|
+
spotify_api.should_receive(:link_create_from_track).and_return(artist)
|
195
195
|
track.unwrap.should eq Hallon::Artist.new(artist)
|
196
196
|
end
|
197
197
|
end
|
@@ -22,7 +22,7 @@ describe Hallon::User::Post do
|
|
22
22
|
|
23
23
|
describe ".create" do
|
24
24
|
it "should return nil if the inboxpost failed" do
|
25
|
-
|
25
|
+
spotify_api.should_receive(:inbox_post_tracks).and_return(null_pointer)
|
26
26
|
post.should be_nil
|
27
27
|
end
|
28
28
|
|
data/spec/hallon/user_spec.rb
CHANGED
@@ -77,7 +77,7 @@ describe Hallon::User do
|
|
77
77
|
let(:published) { Hallon::PlaylistContainer.new(mock_container) }
|
78
78
|
|
79
79
|
it "should return the playlist container of the user" do
|
80
|
-
Spotify.
|
80
|
+
Spotify.mock_registry_add("spotify:container:%s" % user.name, mock_container)
|
81
81
|
|
82
82
|
session.login('burgestrand', 'pass')
|
83
83
|
user.published.should eq published
|
data/spec/mockspotify.rb
CHANGED
@@ -25,65 +25,59 @@ module Spotify
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
class API
|
29
|
+
extend FFI::Library
|
30
|
+
extend Mock
|
31
|
+
end
|
32
|
+
|
30
33
|
require 'spotify'
|
31
34
|
|
32
35
|
module Mock
|
33
|
-
|
34
|
-
Spotify
|
35
|
-
end
|
36
|
-
|
37
|
-
class PlaylistTrack < FFI::Struct
|
38
|
-
layout :track, :track,
|
36
|
+
class PlaylistTrack < Spotify::Struct
|
37
|
+
layout :track, Spotify::Track,
|
39
38
|
:create_time, :int,
|
40
|
-
:creator,
|
41
|
-
:message,
|
39
|
+
:creator, Spotify::User,
|
40
|
+
:message, Spotify::NULString,
|
42
41
|
:seen, :bool
|
43
42
|
end
|
44
43
|
|
45
|
-
class PlaylistContainerItem <
|
46
|
-
layout :playlist,
|
44
|
+
class PlaylistContainerItem < Spotify::Struct
|
45
|
+
layout :playlist, Spotify::Playlist,
|
47
46
|
:type, :playlist_type,
|
48
|
-
:folder_name,
|
47
|
+
:folder_name, Spotify::NULString,
|
49
48
|
:folder_id, :uint64,
|
50
49
|
:num_seen_tracks, :int,
|
51
|
-
:seen_tracks, :
|
50
|
+
:seen_tracks, :array
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
|
54
|
+
class API
|
55
|
+
old_verbose, $VERBOSE = $VERBOSE, true
|
56
56
|
|
57
|
-
|
58
|
-
attach_function
|
59
|
-
|
60
|
-
Spotify::Pointer.new(send(name, *args), returns, false)
|
61
|
-
end
|
62
|
-
end
|
57
|
+
attach_function :mock_registry_find, [:string], :pointer
|
58
|
+
attach_function :mock_registry_add, [:string, :pointer], :void
|
59
|
+
attach_function :mock_registry_clean, [], :void
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
attach_function :mock_session_create, [:pointer, :connectionstate, :int, OfflineSyncStatus, :int, :int, Playlist], Session
|
62
|
+
attach_function :mock_user_create, [:string, :string, :bool], User
|
63
|
+
attach_function :mock_track_create, [:string, :int, :array, Album, :int, :int, :int, :int, :error, :bool, :availability, :track_offline_status, :bool, :bool, Track, :bool, :bool], Track
|
64
|
+
attach_function :mock_image_create, [ImageID, :imageformat, :size_t, :buffer_in, :error], Image
|
65
|
+
attach_function :mock_artist_create, [:string, ImageID, :bool], Artist
|
66
|
+
attach_function :mock_album_create, [:string, Artist, :int, ImageID, :albumtype, :bool, :bool], Album
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
attach_mock_function :mock_image, :mocksp_image_create, [:image_id, :imageformat, :size_t, :buffer_in, :error], :image
|
72
|
-
attach_mock_function :mock_artist, :mocksp_artist_create, [:string, :image_id, :bool], :artist
|
73
|
-
attach_mock_function :mock_album, :mocksp_album_create, [:string, :artist, :int, :image_id, :albumtype, :bool, :bool], :album
|
68
|
+
attach_function :mock_albumbrowse_create, [:error, :int, Album, Artist, :int, :array, :int, :array, :string, :albumbrowse_complete_cb, :userdata], AlbumBrowse
|
69
|
+
attach_function :mock_artistbrowse_create, [:error, :int, Artist, :int, :array, :int, :array, :int, :array, :int, :array, :int, :array, :string, :artistbrowse_type, :artistbrowse_complete_cb, :userdata], ArtistBrowse
|
70
|
+
attach_function :mock_toplistbrowse_create, [:error, :int, :int, :array, :int, :array, :int, :array], ToplistBrowse
|
74
71
|
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
attach_function :mock_playlist_create, [:string, :bool, User, :bool, :string, ImageID, :bool, :uint, Subscribers, :bool, :playlist_offline_status, :int, :int, :array], Playlist
|
73
|
+
attach_function :mock_playlistcontainer_create, [User, :bool, :int, :array, PlaylistContainerCallbacks, :userdata], PlaylistContainer
|
74
|
+
attach_function :mock_search_create, [:error, :string, :string, :int, :int, :array, :int, :int, :array, :int, :int, :array, :int, :int, :array, :search_complete_cb, :userdata], Search
|
75
|
+
attach_function :mock_subscribers, [:int, :array], Subscribers
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
attach_function :mock_subscribers, :mocksp_subscribers, [:int, :array], Spotify::Subscribers
|
77
|
+
# mocked accessors
|
78
|
+
attach_function :mock_playlist_get_autolink_tracks, [Playlist], :bool
|
79
|
+
attach_function :mock_session_set_is_scrobbling_possible, [Session, :social_provider, :bool], :void
|
83
80
|
|
84
|
-
|
85
|
-
|
86
|
-
attach_function :mocksp_session_set_is_scrobbling_possible, [:session, :social_provider, :bool], :void
|
87
|
-
|
88
|
-
$VERBOSE = old_verbose
|
81
|
+
$VERBOSE = old_verbose
|
82
|
+
end
|
89
83
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe Spotify::Mock do
|
2
2
|
it "should have injected itself into Spotify's ancestor chain" do
|
3
|
-
ancestors =
|
3
|
+
ancestors = Spotify::API.singleton_class.ancestors
|
4
4
|
mock_index = ancestors.index(Spotify::Mock)
|
5
5
|
ffi_index = ancestors.index(FFI::Library)
|
6
6
|
|
@@ -9,14 +9,14 @@ describe Spotify::Mock do
|
|
9
9
|
|
10
10
|
describe "hextoa" do
|
11
11
|
it "should convert a hexidecimal string properly" do
|
12
|
-
Spotify.attach_function :hextoa, [:string, :int], :string
|
12
|
+
Spotify::API.attach_function :hextoa, :hextoa, [:string, :int], :string
|
13
13
|
Spotify.hextoa("3A3A", 4).should eq "::"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "atohex" do
|
18
18
|
it "should convert a byte string to a hexadecimal string" do
|
19
|
-
Spotify.attach_function :atohex, [:buffer_out, :buffer_in, :int], :void
|
19
|
+
Spotify::API.attach_function :atohex, :atohex, [:buffer_out, :buffer_in, :int], :void
|
20
20
|
|
21
21
|
FFI::Buffer.alloc_out(8) do |b|
|
22
22
|
Spotify.atohex(b, "\x3A\x3A\x0F\xF1", b.size)
|
@@ -27,7 +27,7 @@ describe Spotify::Mock do
|
|
27
27
|
|
28
28
|
describe "unregion" do
|
29
29
|
it "should convert an integer to the correct region" do
|
30
|
-
Spotify.attach_function :unregion, [ :int ], :string
|
30
|
+
Spotify::API.attach_function :unregion, :unregion, [ :int ], :string
|
31
31
|
|
32
32
|
sweden = 21317
|
33
33
|
Spotify.unregion(sweden).should eq "SE"
|
@@ -36,28 +36,28 @@ describe Spotify::Mock do
|
|
36
36
|
|
37
37
|
describe "the registry" do
|
38
38
|
it "should find previously added entries" do
|
39
|
-
Spotify.
|
40
|
-
Spotify.
|
39
|
+
Spotify.mock_registry_add("i_exist", FFI::Pointer.new(1))
|
40
|
+
Spotify.mock_registry_add("i_exist_too", FFI::Pointer.new(2))
|
41
41
|
|
42
|
-
Spotify.
|
43
|
-
Spotify.
|
42
|
+
Spotify.mock_registry_find("i_exist").should eq FFI::Pointer.new(1)
|
43
|
+
Spotify.mock_registry_find("i_exist_too").should eq FFI::Pointer.new(2)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should return nil for entries not in the registry" do
|
47
|
-
Spotify.
|
47
|
+
Spotify.mock_registry_find("i_do_not_exist").should be_null
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should be cleanable" do
|
51
51
|
pointer = FFI::MemoryPointer.new(:uint)
|
52
52
|
|
53
|
-
Spotify.
|
54
|
-
Spotify.
|
53
|
+
Spotify.mock_registry_add("i_exist", pointer)
|
54
|
+
Spotify.mock_registry_find("i_exist").should_not be_null
|
55
55
|
|
56
|
-
Spotify.
|
57
|
-
Spotify.
|
56
|
+
Spotify.mock_registry_clean
|
57
|
+
Spotify.mock_registry_find("i_exist").should be_null
|
58
58
|
|
59
|
-
Spotify.
|
60
|
-
Spotify.
|
59
|
+
Spotify.mock_registry_add("i_exist", pointer)
|
60
|
+
Spotify.mock_registry_find("i_exist").should_not be_null
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|