spec/lastfm_spec.rb in lastfm-1.0.1 vs spec/lastfm_spec.rb in lastfm-1.1.0

- old
+ new

@@ -105,11 +105,13 @@ mock_response.should_receive(:body).and_return(open(fixture('ng.xml')).read) @lastfm.class.should_receive(:post).and_return(mock_response) lambda { @lastfm.request('xxx.yyy', { :foo => 'bar' }, :post) - }.should raise_error(Lastfm::ApiError, 'Invalid API key - You must be granted a valid key by last.fm') + }.should raise_error(Lastfm::ApiError, 'Invalid API key - You must be granted a valid key by last.fm') {|error| + error.code.should == 10 + } end end describe '#auth' do it 'should return an instance of Lastfm::Auth' do @@ -143,10 +145,28 @@ XML session = @lastfm.auth.get_session('xxxyyyzzz') session['name'].should eql('MyLastFMUsername') session['key'].should eql('zzzyyyxxx') end + + it 'should get mobile session' do + @lastfm.should_receive(:request). + with('auth.getMobileSession', { :username => 'xxxyyyzzz', :authToken => 'xxxxAuthTokenxxxx' }, :get, true). + and_return(make_response(<<XML)) +<?xml version="1.0" encoding="utf-8"?> +<lfm status="ok"> + <session> + <name>MyLastFMUsername</name> + <key>zzzyyyxxx</key> + <subscriber>0</subscriber> + </session> +</lfm> +XML + session = @lastfm.auth.get_mobile_session('xxxyyyzzz', 'xxxxAuthTokenxxxx') + session['name'].should eql('MyLastFMUsername') + session['key'].should eql('zzzyyyxxx') + end end describe '#track' do it 'should return an instance of Lastfm::Track' do @lastfm.track.should be_an_instance_of(Lastfm::MethodCategory::Track) @@ -493,9 +513,24 @@ end describe '#library' do it 'should return an instance of Lastfm::Library' do @lastfm.library.should be_an_instance_of(Lastfm::MethodCategory::Library) + end + + describe '#get_tracks' do + it 'should get the tracks\' info' do + @lastfm.should_receive(:request).with('library.getTracks', { + :user => 'test', + :artist => 'foo', + :album => 'bar', + :limit => nil, + :page => nil + }).and_return(make_response('library_get_tracks')) + tracks = @lastfm.library.get_tracks('test', 'foo', 'bar') + tracks[0]['name'].should eql('Learning to Live') + tracks.size.should == 1 + end end describe '#get_artists' do it 'should get the artists\' info' do @lastfm.should_receive(:request).with('library.getArtists', {