hallon 0.18.0 → 0.18.1

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.
Files changed (65) hide show
  1. data/.rspec +1 -1
  2. data/CHANGELOG.md +12 -1
  3. data/README.markdown +13 -5
  4. data/Rakefile +23 -74
  5. data/examples/example_support.rb +2 -0
  6. data/hallon.gemspec +1 -1
  7. data/lib/hallon.rb +1 -6
  8. data/lib/hallon/album.rb +4 -4
  9. data/lib/hallon/album_browse.rb +6 -6
  10. data/lib/hallon/artist.rb +3 -3
  11. data/lib/hallon/artist_browse.rb +9 -9
  12. data/lib/hallon/audio_queue.rb +2 -1
  13. data/lib/hallon/base.rb +10 -10
  14. data/lib/hallon/enumerator.rb +3 -3
  15. data/lib/hallon/ext/spotify.rb +1 -47
  16. data/lib/hallon/image.rb +4 -4
  17. data/lib/hallon/link.rb +4 -4
  18. data/lib/hallon/linkable.rb +10 -10
  19. data/lib/hallon/observable/playlist.rb +2 -3
  20. data/lib/hallon/observable/playlist_container.rb +3 -12
  21. data/lib/hallon/player.rb +2 -2
  22. data/lib/hallon/playlist.rb +6 -6
  23. data/lib/hallon/playlist_container.rb +8 -8
  24. data/lib/hallon/scrobbler.rb +4 -4
  25. data/lib/hallon/search.rb +20 -5
  26. data/lib/hallon/session.rb +18 -17
  27. data/lib/hallon/toplist.rb +4 -4
  28. data/lib/hallon/track.rb +5 -5
  29. data/lib/hallon/user.rb +7 -7
  30. data/lib/hallon/version.rb +1 -1
  31. data/spec/hallon/album_browse_spec.rb +1 -1
  32. data/spec/hallon/artist_browse_spec.rb +1 -1
  33. data/spec/hallon/base_spec.rb +6 -3
  34. data/spec/hallon/enumerator_spec.rb +2 -2
  35. data/spec/hallon/hallon_spec.rb +0 -4
  36. data/spec/hallon/link_spec.rb +1 -1
  37. data/spec/hallon/linkable_spec.rb +4 -4
  38. data/spec/hallon/observable/playlist_container_spec.rb +3 -3
  39. data/spec/hallon/observable/playlist_spec.rb +1 -1
  40. data/spec/hallon/player_spec.rb +9 -9
  41. data/spec/hallon/playlist_container_spec.rb +2 -2
  42. data/spec/hallon/playlist_spec.rb +8 -8
  43. data/spec/hallon/scrobbler_spec.rb +8 -7
  44. data/spec/hallon/search_spec.rb +3 -3
  45. data/spec/hallon/session_spec.rb +10 -10
  46. data/spec/hallon/toplist_spec.rb +4 -4
  47. data/spec/hallon/track_spec.rb +6 -6
  48. data/spec/hallon/user_post_spec.rb +1 -1
  49. data/spec/hallon/user_spec.rb +1 -1
  50. data/spec/mockspotify.rb +36 -42
  51. data/spec/mockspotify/mockspotify_spec.rb +15 -15
  52. data/spec/spec_helper.rb +25 -21
  53. data/spec/support/album_mocks.rb +4 -4
  54. data/spec/support/artist_mocks.rb +5 -5
  55. data/spec/support/image_mocks.rb +4 -4
  56. data/spec/support/playlist_container_mocks.rb +4 -4
  57. data/spec/support/playlist_mocks.rb +6 -6
  58. data/spec/support/search_mocks.rb +2 -2
  59. data/spec/support/session_mocks.rb +1 -1
  60. data/spec/support/shared_for_callbacks.rb +1 -1
  61. data/spec/support/shared_for_linkable_objects.rb +3 -2
  62. data/spec/support/toplist_mocks.rb +2 -2
  63. data/spec/support/track_mocks.rb +4 -4
  64. data/spec/support/user_mocks.rb +2 -2
  65. 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
- Spotify.should_receive(:playlistcontainer_add_playlist).and_return(null_pointer)
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
- Spotify.should_receive(:playlistcontainer_get_unseen_tracks).and_return(4, -1)
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!(playlist.pointer, index), playlist.pointer, index] })
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
- Spotify.should_receive(:playlist_subscribers).and_return(mock_empty_subscribers)
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.mocksp_playlist_get_autolink_tracks(playlist.pointer).should be_false
324
+ Spotify.mock_playlist_get_autolink_tracks(playlist.pointer).should be_false
325
325
  playlist.autolink_tracks = true
326
- Spotify.mocksp_playlist_get_autolink_tracks(playlist.pointer).should be_true
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
- Spotify.should_receive(:playlist_get_offline_status).and_return symbol_for(1)
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
- Spotify.should_receive(:playlist_get_offline_status).and_return symbol_for(2)
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
- Spotify.should_receive(:playlist_get_offline_status).and_return symbol_for(3)
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
- Spotify.should_receive(:playlist_get_offline_status).and_return symbol_for(0)
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
- Spotify.should_receive(:session_set_social_credentials).with(anything, :facebook, "Kim", "password").and_return(:ok)
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.mocksp_session_set_is_scrobbling_possible(session.pointer, scrobbling.provider, true)
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.mocksp_session_set_is_scrobbling_possible(session.pointer, scrobbling.provider, false)
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
- Spotify.should_receive(:session_is_scrobbling_possible).and_return(:invalid_indata)
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
- Spotify.should_receive(:session_set_scrobbling).and_return(:invalid_indata)
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
- Spotify.should_receive(:session_is_scrobbling).and_return do |session, provider, buffer|
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!(session.pointer, scrobbling.provider, buffer)
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
@@ -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
- Spotify.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)
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
- Spotify.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)
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
- Spotify.should_receive(:search_create).and_return(null_pointer)
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
@@ -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([:settings_path]) { should == options[:settings_path] }
61
- its([:cache_path]) { should == options[:cache_path] }
60
+ its([:settings_location]) { should == options[:settings_location] }
61
+ its([:cache_location]) { should == options[:cache_location] }
62
62
 
63
- its([:load_playlists]) { should == true }
63
+ its([:initially_unload_playlists]) { should == false }
64
64
  its([:compress_playlists]) { should == true }
65
- its([:cache_playlist_metadata]) { should == true }
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
- Spotify.should_receive(:session_login).with(anything, 'Kim', nil, false, 'blob')
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
- Spotify.should_receive(:session_login).with(anything, 'Kim', 'pass', false, nil)
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
- Spotify.should_receive(:session_set_connection_rules).with(session.pointer, 5)
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
- Spotify.should_receive(:offline_sync_get_status).and_return(false)
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
- Spotify.should_receive(:session_preferred_offline_bitrate).with(session.pointer, :'96k', false).and_return(:ok)
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
- Spotify.should_receive(:session_preferred_offline_bitrate).with(session.pointer, :'96k', true).and_return(:ok)
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
 
@@ -2,12 +2,12 @@
2
2
 
3
3
  describe Hallon::Toplist do
4
4
  let(:toplist) do
5
- Spotify.registry_add 'spotify:toplist:artists:everywhere', mock_toplistbrowse
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.registry_add 'spotify:toplist:tracks:everywhere', mock_empty_toplistbrowse
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.registry_add 'spotify:toplist:user:Kim:tracks', mock_toplistbrowse
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.registry_add 'spotify:toplist:tracks:SE', mock_toplistbrowse
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
@@ -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!('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') }
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
- Spotify.should_receive(:link_create_from_track!).and_return(playlist)
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
- Spotify.should_receive(:link_create_from_track!).and_return(album)
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
- Spotify.should_receive(:link_create_from_track!).and_return(artist)
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
- Spotify.should_receive(:inbox_post_tracks).and_return(null_pointer)
25
+ spotify_api.should_receive(:inbox_post_tracks).and_return(null_pointer)
26
26
  post.should be_nil
27
27
  end
28
28
 
@@ -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.registry_add("spotify:container:%s" % user.name, mock_container)
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
@@ -25,65 +25,59 @@ module Spotify
25
25
  end
26
26
  end
27
27
 
28
- extend FFI::Library
29
- extend Mock
28
+ class API
29
+ extend FFI::Library
30
+ extend Mock
31
+ end
32
+
30
33
  require 'spotify'
31
34
 
32
35
  module Mock
33
- def self.find_type(*args, &block)
34
- Spotify.find_type(*args, &block)
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, :user,
41
- :message, :pointer,
39
+ :creator, Spotify::User,
40
+ :message, Spotify::NULString,
42
41
  :seen, :bool
43
42
  end
44
43
 
45
- class PlaylistContainerItem < FFI::Struct
46
- layout :playlist, :playlist,
44
+ class PlaylistContainerItem < Spotify::Struct
45
+ layout :playlist, Spotify::Playlist,
47
46
  :type, :playlist_type,
48
- :folder_name, :pointer,
47
+ :folder_name, Spotify::NULString,
49
48
  :folder_id, :uint64,
50
49
  :num_seen_tracks, :int,
51
- :seen_tracks, :pointer
50
+ :seen_tracks, :array
52
51
  end
53
52
  end
54
53
 
55
- old_verbose, $VERBOSE = $VERBOSE, true
54
+ class API
55
+ old_verbose, $VERBOSE = $VERBOSE, true
56
56
 
57
- def self.attach_mock_function(name, cname, params, returns, options = {})
58
- attach_function(name, cname, params, returns, options)
59
- define_singleton_method("#{name}!") do |*args|
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
- attach_function :registry_find, [:string], :pointer
65
- attach_function :registry_add, [:string, :pointer], :void
66
- attach_function :registry_clean, [], :void
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
- attach_function :mock_session, :mocksp_session_create, [:pointer, :connectionstate, :int, Spotify::OfflineSyncStatus, :int, :int, :playlist], :session
69
- attach_mock_function :mock_user, :mocksp_user_create, [:string, :string, :bool], :user
70
- attach_mock_function :mock_track, :mocksp_track_create, [:string, :int, :array, :album, :int, :int, :int, :int, :error, :bool, :availability, :track_offline_status, :bool, :bool, :track, :bool, :bool], :track
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
- attach_function :mock_albumbrowse, :mocksp_albumbrowse_create, [:error, :int, :album, :artist, :int, :array, :int, :array, :string, :albumbrowse_complete_cb, :pointer], :albumbrowse
76
- attach_function :mock_artistbrowse, :mocksp_artistbrowse_create, [:error, :int, :artist, :int, :array, :int, :array, :int, :array, :int, :array, :int, :array, :string, :artistbrowse_type, :artistbrowse_complete_cb, :pointer], :artistbrowse
77
- attach_function :mock_toplistbrowse, :mocksp_toplistbrowse_create, [:error, :int, :int, :array, :int, :array, :int, :array], :toplistbrowse
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
- attach_mock_function :mock_playlist, :mocksp_playlist_create, [:string, :bool, :user, :bool, :string, :image_id, :bool, :uint, Spotify::Subscribers, :bool, :playlist_offline_status, :int, :int, :array], :playlist
80
- attach_mock_function :mock_playlistcontainer, :mocksp_playlistcontainer_create, [:user, :bool, :int, :array, PlaylistContainerCallbacks, :userdata], :playlistcontainer
81
- attach_function :mock_search, :mocksp_search_create, [:error, :string, :string, :int, :int, :array, :int, :int, :array, :int, :int, :array, :int, :int, :array, :search_complete_cb, :pointer], :search
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
- # mocked accessors
85
- attach_function :mocksp_playlist_get_autolink_tracks, [:playlist], :bool
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 = (class << Spotify; self; end).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.registry_add("i_exist", FFI::Pointer.new(1))
40
- Spotify.registry_add("i_exist_too", FFI::Pointer.new(2))
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.registry_find("i_exist").should eq FFI::Pointer.new(1)
43
- Spotify.registry_find("i_exist_too").should eq FFI::Pointer.new(2)
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.registry_find("i_do_not_exist").should be_null
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.registry_add("i_exist", pointer)
54
- Spotify.registry_find("i_exist").should_not be_null
53
+ Spotify.mock_registry_add("i_exist", pointer)
54
+ Spotify.mock_registry_find("i_exist").should_not be_null
55
55
 
56
- Spotify.registry_clean
57
- Spotify.registry_find("i_exist").should be_null
56
+ Spotify.mock_registry_clean
57
+ Spotify.mock_registry_find("i_exist").should be_null
58
58
 
59
- Spotify.registry_add("i_exist", pointer)
60
- Spotify.registry_find("i_exist").should_not be_null
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