mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Fix implementation of playing? method and test it
This commit is contained in:
parent
494c1795f4
commit
183c6279cd
@ -12,7 +12,9 @@ module MPDClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def playing?
|
def playing?
|
||||||
self == self.class.current_song
|
if current = self.class.current_song
|
||||||
|
[artist, album, title] == [current.artist, current.album, current.title]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def length
|
def length
|
||||||
@ -20,7 +22,7 @@ module MPDClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
[artist, album, title] == [other.artist, other.album, other.title]
|
[artist, album, title] <=> [other.artist, other.album, other.title]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h
|
||||||
@ -51,7 +53,9 @@ module MPDClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_song
|
def current_song
|
||||||
new(MPDClient.conn.current_song)
|
if song = MPDClient.conn.current_song
|
||||||
|
new(song)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,27 @@ describe MPDClient::Song do
|
|||||||
MPDClient.conn.stub(:queue).and_return([song1, song2])
|
MPDClient.conn.stub(:queue).and_return([song1, song2])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the queue of songs' do
|
describe "#queue" do
|
||||||
queue = subject.queue
|
it "returns the list of songs" do
|
||||||
expect(queue).to have(2).items
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user