diff --git a/lib/mpd_client/song.rb b/lib/mpd_client/song.rb index 260287a..cf96a93 100644 --- a/lib/mpd_client/song.rb +++ b/lib/mpd_client/song.rb @@ -12,7 +12,9 @@ module MPDClient end def playing? - self == self.class.current_song + if current = self.class.current_song + [artist, album, title] == [current.artist, current.album, current.title] + end end def length @@ -20,7 +22,7 @@ module MPDClient end def <=>(other) - [artist, album, title] == [other.artist, other.album, other.title] + [artist, album, title] <=> [other.artist, other.album, other.title] end def to_h @@ -51,7 +53,9 @@ module MPDClient end def current_song - new(MPDClient.conn.current_song) + if song = MPDClient.conn.current_song + new(song) + end end end diff --git a/spec/lib/mpd_client/song_spec.rb b/spec/lib/mpd_client/song_spec.rb index d19ccfb..569d5d1 100644 --- a/spec/lib/mpd_client/song_spec.rb +++ b/spec/lib/mpd_client/song_spec.rb @@ -11,8 +11,27 @@ describe MPDClient::Song do MPDClient.conn.stub(:queue).and_return([song1, song2]) end - it 'returns the queue of songs' do - queue = subject.queue - expect(queue).to have(2).items + describe "#queue" do + it "returns the list of songs" do + queue = subject.queue + expect(queue).to have(2).items + end + end + + describe "#playing?" do + let(:playing_song) { subject.new(song1) } + let(:not_playing_song) { subject.new(song2) } + + before do + MPDClient.conn.stub(:current_song).and_return(song1) + end + + it "should be true when the song is playing" do + playing_song.playing?.should eq(true) + end + + it "should be false when the song is not playing" do + not_playing_song.playing?.should eq(false) + end end end