-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmpd_spec.rb
88 lines (71 loc) · 2.28 KB
/
mpd_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'spec_helper'
require_relative '../lib/ruby-mpd'
RSpec.describe 'MPD' do
subject { MPD.new('localhost', 6600, password: password) }
let(:password) { nil }
it 'has a version number' do
expect(MPD::VERSION).not_to be nil
end
describe "defaults" do
it 'has sensible default settings' do
expect(subject.hostname).to eql('localhost')
expect(subject.port).to eql(6600)
end
end
describe '#authenticate' do
context "with a password" do
let(:password) { 'foo' }
it "calls #send_command with the password set in #initialize" do
expect(subject).to receive(:send_command).with(:password, password).and_return(true)
subject.authenticate
end
end
context "without a password" do
let(:password) { nil }
it "does NOT call send_command" do
expect(subject).to_not receive(:send_command)
subject.authenticate
end
end
end
describe '#connect' do
context "when already connected" do
before do
expect(subject).to receive(:connected?).and_return(true)
end
it 'raises an error' do
expect { subject.connect }.to raise_error(MPD::ConnectionError)
end
end
context "when not yet connected" do
before do
expect(subject).to receive(:connected?).and_return(false)
expect(subject).to receive(:socket).and_return(double(gets: 'OK MPD 1'))
end
it 'calls #authenticate' do
expect(subject).to receive(:authenticate)
subject.connect
end
end
end
# describe '#socket' do
# let(:socket_file) { File.expand_path('../support/socket.sock', __FILE__) }
# let(:socket) { subject.send(:socket) }
# context "if the hostname is a file that exists" do
# subject { MPD.new(socket_file) }
# before do
# allow(File).to receive(:exists?).with(socket_file).and_return(true)
# allow(UNIXSocket).to receive(:new).with(socket_file).and_return('unix socket stub')
# end
# it 'uses a Unix socket' do
# expect(socket).to eql('unix socket stub')
# end
# end
# context "if the hostname does NOT exist" do
# subject { MPD.new('localhost') }
# it 'uses a TCP socket' do
# expect(socket).to be_a(TCPSocket)
# end
# end
# end
end