mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Make all the tests work
This commit is contained in:
parent
5e45aad95a
commit
494c1795f4
@ -21,7 +21,11 @@ module MPDClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def year
|
def year
|
||||||
@first_song.year
|
@first_song.date
|
||||||
|
end
|
||||||
|
|
||||||
|
def <=>(other)
|
||||||
|
year <=> other.year
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h
|
||||||
|
|||||||
@ -3,6 +3,12 @@ module MPDClient
|
|||||||
|
|
||||||
include ClassToProc
|
include ClassToProc
|
||||||
|
|
||||||
|
attr :name
|
||||||
|
|
||||||
|
def initialize(name)
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def all
|
def all
|
||||||
MPDClient.conn.artists.sort.map(&self)
|
MPDClient.conn.artists.sort.map(&self)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ module MPDClient
|
|||||||
include Comparable
|
include Comparable
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
delegate %i(id track artist album title time pos) => :@song
|
delegate %i(id track artist album title genre date time pos) => :@song
|
||||||
|
|
||||||
def initialize(song, pos: nil)
|
def initialize(song, pos: nil)
|
||||||
@song = song
|
@song = song
|
||||||
|
|||||||
@ -1,30 +1,34 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Album do
|
describe MPDClient::Album do
|
||||||
|
|
||||||
|
subject { MPDClient::Album }
|
||||||
|
|
||||||
let(:song1) { MPD::Song.new({ album: 'Back in Black', genre: 'Rock', date: '1980' }) }
|
let(:song1) { MPD::Song.new({ album: 'Back in Black', genre: 'Rock', date: '1980' }) }
|
||||||
let(:song2) { MPD::Song.new({ album: 'Highway to Hell', genre: 'Rock', date: '1979' }) }
|
let(:song2) { MPD::Song.new({ album: 'Highway to Hell', genre: 'Rock', date: '1979' }) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
MPDConnection.mpd.stub(:albums).and_return([song1.album, song2.album])
|
MPDClient.conn.tap do |mpd|
|
||||||
MPDConnection.mpd.stub(:search).and_return([song1, song2])
|
mpd.stub(:albums).and_return([song1.album, song2.album])
|
||||||
MPDConnection.mpd.stub(:search).with(:album, song1.album).and_return([song1])
|
mpd.stub(:where).and_return([song1, song2])
|
||||||
MPDConnection.mpd.stub(:search).with(:album, song2.album).and_return([song2])
|
mpd.stub(:where).with(album: song1.album).and_return([song1])
|
||||||
|
mpd.stub(:where).with(album: song2.album).and_return([song2])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has attributes based on first song' do
|
it 'has attributes based on first song' do
|
||||||
album = Album.new(song1.album)
|
album = subject.new(song1.album)
|
||||||
expect(album.title).to eq(song1.album)
|
expect(album.title).to eq(song1.album)
|
||||||
expect(album.genre).to eq(song1.genre)
|
expect(album.genre).to eq(song1.genre)
|
||||||
expect(album.year).to eq(song1.date)
|
expect(album.year).to eq(song1.date)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return a list of albums' do
|
it 'should return a list of albums' do
|
||||||
expect(Album.by_artist('AC/DC')).to have(2).items
|
expect(subject.by_artist('AC/DC')).to have(2).items
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should sort the albums by year' do
|
it 'should sort the albums by year' do
|
||||||
albums = Album.by_artist('AC/DC')
|
albums = subject.by_artist('AC/DC')
|
||||||
expect(albums.sort.map(&:year)).to eq(['1979', '1980'])
|
expect(albums.sort.map(&:year)).to eq(['1979', '1980'])
|
||||||
end
|
end
|
||||||
|
|
||||||
23
spec/lib/mpd_client/artist_spec.rb
Normal file
23
spec/lib/mpd_client/artist_spec.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe MPDClient::Artist do
|
||||||
|
|
||||||
|
subject { MPDClient::Artist }
|
||||||
|
|
||||||
|
let(:artist) { subject.new('Alice Cooper') }
|
||||||
|
let(:artists) { ['Alice Cooper', 'Jimmy Eat World', 'Dream Theater'] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
MPDClient.conn.stub(:artists).and_return(artists)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has attributes' do
|
||||||
|
expect(artist.name).to eq('Alice Cooper')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns all artists' do
|
||||||
|
expect(subject.all).to have(3).items
|
||||||
|
expect(subject.all.map(&:name)).to eq(artists.sort)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
23
spec/lib/mpd_client/connection_spec.rb
Normal file
23
spec/lib/mpd_client/connection_spec.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe MPDClient::Connection do
|
||||||
|
|
||||||
|
subject { MPDClient::Connection }
|
||||||
|
|
||||||
|
let(:conn) { subject.new('localhost', 6600) }
|
||||||
|
|
||||||
|
describe "#each_conn" do
|
||||||
|
let(:fake_users) { [1, 2, 3] }
|
||||||
|
it "enumerates the connected users" do
|
||||||
|
fake_users.each {|n| conn.connected_users << n }
|
||||||
|
conn.each_conn.to_a.should eq(fake_users)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#connected_users" do
|
||||||
|
it "doesn't allow duplicate connections" do
|
||||||
|
3.times { conn.connected_users << "user" }
|
||||||
|
conn.connected_users.should have(1).item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
4
spec/lib/mpd_client/control_spec.rb
Normal file
4
spec/lib/mpd_client/control_spec.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe MPDClient::Control do
|
||||||
|
end
|
||||||
@ -1,16 +1,18 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Song do
|
describe MPDClient::Song do
|
||||||
|
|
||||||
|
subject { MPDClient::Song }
|
||||||
|
|
||||||
let(:song1) { MPD::Song.new({ title: 'Back in Black', album: 'Back in Black', genre: 'Rock', date: '1980' }) }
|
let(:song1) { MPD::Song.new({ title: 'Back in Black', album: 'Back in Black', genre: 'Rock', date: '1980' }) }
|
||||||
let(:song2) { MPD::Song.new({ title: 'Highway to Hell', album: 'Highway to Hell', genre: 'Rock', date: '1979' }) }
|
let(:song2) { MPD::Song.new({ title: 'Highway to Hell', album: 'Highway to Hell', genre: 'Rock', date: '1979' }) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
MPDConnection.mpd.stub(:queue).and_return([song1, song2])
|
MPDClient.conn.stub(:queue).and_return([song1, song2])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the queue of songs' do
|
it 'returns the queue of songs' do
|
||||||
queue = Song.queue
|
queue = subject.queue
|
||||||
expect(queue).to have(2).items
|
expect(queue).to have(2).items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
23
spec/lib/mpd_client_spec.rb
Normal file
23
spec/lib/mpd_client_spec.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe MPDClient do
|
||||||
|
|
||||||
|
subject { MPDClient }
|
||||||
|
|
||||||
|
before do
|
||||||
|
subject.connect!
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#listen" do
|
||||||
|
it "exposes `Connection#on` for easy event listening" do
|
||||||
|
subject.conn.should_receive(:on).exactly(3).times
|
||||||
|
|
||||||
|
subject.listen do
|
||||||
|
on(:first) { "something" }
|
||||||
|
on(:second) { "something" }
|
||||||
|
on(:third) { "something" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@ -1,18 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Artist do
|
|
||||||
|
|
||||||
let(:artist) { Artist.new('Alice Cooper') }
|
|
||||||
let(:artists) { ['Alice Cooper', 'Jimmy Eat World', 'Dream Theater'] }
|
|
||||||
|
|
||||||
it 'has attributes' do
|
|
||||||
expect(artist.name).to eq('Alice Cooper')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns all artists' do
|
|
||||||
MPDConnection.mpd.stub(:artists).and_return(artists)
|
|
||||||
expect(Artist.all).to have(3).items
|
|
||||||
expect(Artist.all.map(&:name)).to eq(artists.sort)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Control do
|
|
||||||
end
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe MPDClient do
|
|
||||||
it 'should respond to GET' do
|
|
||||||
get '/'
|
|
||||||
expect(last_response.status).to eq(404)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,20 +1,16 @@
|
|||||||
ENV['RACK_ENV'] = 'test'
|
ENV['RACK_ENV'] = 'test'
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), '..', 'mpd_client.rb')
|
require File.expand_path('../lib/mpd_client', __dir__)
|
||||||
|
require 'rspec'
|
||||||
require 'sinatra'
|
require 'rspec/mocks'
|
||||||
require 'rack/test'
|
require 'rack/test'
|
||||||
|
|
||||||
# setup test environment
|
|
||||||
set :environment, :test
|
|
||||||
set :run, false
|
|
||||||
set :raise_errors, true
|
|
||||||
set :logging, false
|
|
||||||
|
|
||||||
def app
|
|
||||||
MPDClient
|
|
||||||
end
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include Rack::Test::Methods
|
config.include Rack::Test::Methods
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
allow_message_expectations_on_nil
|
||||||
|
MPDClient::Connection.any_instance.stub(:connected?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user