mpc 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +13 -0
- data/lib/mpc.rb +75 -201
- data/lib/mpc/version.rb +3 -0
- data/mpc.gemspec +25 -0
- data/test/mpc_test.rb +21 -175
- data/test/test_helper.rb +4 -0
- metadata +28 -22
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler"
|
2
|
+
require "rake/testtask"
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc "Test the library"
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << "lib"
|
10
|
+
t.libs << "test"
|
11
|
+
t.pattern = "test/**/*_test.rb"
|
12
|
+
t.verbose = true
|
13
|
+
end
|
data/lib/mpc.rb
CHANGED
@@ -1,226 +1,125 @@
|
|
1
|
+
require "socket"
|
1
2
|
class Mpc
|
3
|
+
|
2
4
|
@@regexps = {
|
3
|
-
"ACK"
|
4
|
-
"OK"
|
5
|
-
"FILE"
|
5
|
+
"ACK" => /\AACK \[(\d+)\@(\d+)\] \{(.*)\} (.+)\Z/,
|
6
|
+
"OK" => /\AOK\n\Z/,
|
7
|
+
"FILE" => /\Afile\:(.*)\Z/,
|
8
|
+
"CONNECT" => /\AOK MPD (\d+)\.(\d+).(\d+)\n\Z/
|
6
9
|
}
|
7
10
|
|
11
|
+
attr_accessor :host, :port
|
8
12
|
def initialize(host = "127.0.0.1", port = 6600)
|
9
|
-
@
|
13
|
+
@host = host
|
14
|
+
@port = port
|
15
|
+
end
|
16
|
+
|
17
|
+
def connect
|
18
|
+
@socket = socket
|
10
19
|
@socket.gets
|
11
20
|
end
|
12
21
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
22
|
+
def disconnect
|
23
|
+
@socket.close
|
24
|
+
@socket = nil
|
16
25
|
end
|
17
26
|
|
18
|
-
def
|
19
|
-
|
27
|
+
def play
|
28
|
+
send_command "play"
|
20
29
|
end
|
21
30
|
|
22
|
-
def
|
23
|
-
|
24
|
-
status_hash[:state] == "pause"
|
31
|
+
def playing?
|
32
|
+
status[:state] == "play"
|
25
33
|
end
|
26
34
|
|
27
35
|
def stop
|
28
|
-
|
36
|
+
send_command "stop"
|
29
37
|
end
|
30
38
|
|
31
39
|
def stopped?
|
32
|
-
|
33
|
-
|
40
|
+
status[:state] == "stop"
|
41
|
+
end
|
42
|
+
|
43
|
+
def pause
|
44
|
+
send_command "pause 1"
|
45
|
+
end
|
46
|
+
|
47
|
+
def paused?
|
48
|
+
status[:state] == "pause"
|
34
49
|
end
|
35
50
|
|
36
51
|
def next
|
37
|
-
|
52
|
+
send_command "next"
|
38
53
|
end
|
39
54
|
|
40
55
|
def previous
|
41
|
-
|
56
|
+
send_command "previous"
|
42
57
|
end
|
43
58
|
|
44
59
|
def random(state = nil)
|
45
|
-
|
46
|
-
|
47
|
-
else
|
48
|
-
random_state = state
|
49
|
-
end
|
50
|
-
puts("random #{random_state}")
|
60
|
+
state ||= bool_to_int(!random?)
|
61
|
+
send_command "random #{state}"
|
51
62
|
end
|
52
63
|
|
53
64
|
def random?
|
54
|
-
|
55
|
-
status_hash[:random] == "1"
|
65
|
+
status[:random] == "1"
|
56
66
|
end
|
57
67
|
|
58
68
|
def repeat(state = nil)
|
59
|
-
|
60
|
-
|
61
|
-
else
|
62
|
-
repeat_state = state
|
63
|
-
end
|
64
|
-
puts("repeat #{repeat_state}")
|
69
|
+
state ||= bool_to_int(!repeat?)
|
70
|
+
send_command "repeat #{state}"
|
65
71
|
end
|
66
72
|
|
67
73
|
def repeat?
|
68
|
-
|
69
|
-
status_hash[:repeat] == "1"
|
74
|
+
status[:repeat] == "1"
|
70
75
|
end
|
71
76
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
raise Exception.new("Volume should be between 0 (minimum) and 100 (maximum)")
|
76
|
-
end
|
77
|
-
puts("setvol #{volume.to_s}")
|
78
|
-
end
|
77
|
+
def volume(level = nil)
|
78
|
+
set_volume(level) if level
|
79
|
+
get_volume
|
79
80
|
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
status_hash[:volume]
|
84
|
-
end
|
85
|
-
|
86
|
-
def volume_up
|
87
|
-
set_volume(volume.to_i + 20)
|
88
|
-
end
|
89
|
-
|
90
|
-
def volume_down
|
91
|
-
set_volume(volume.to_i - 20)
|
92
|
-
end
|
93
|
-
|
94
|
-
def seek(time, song = nil)
|
95
|
-
if song.nil?
|
96
|
-
song = current_song[:pos]
|
82
|
+
def volume_up
|
83
|
+
set_volume(volume.to_i + 20)
|
97
84
|
end
|
98
|
-
puts("seek #{song.to_s} #{time.to_s}")
|
99
|
-
end
|
100
85
|
|
101
|
-
|
102
|
-
|
103
|
-
raise Exception.new("Wrong type: #{type}")
|
86
|
+
def volume_down
|
87
|
+
set_volume(volume.to_i - 20)
|
104
88
|
end
|
105
|
-
if what == ""
|
106
|
-
raise Exception.new(" \"What\" can\"t be an empty string")
|
107
|
-
end
|
108
|
-
parse_song_list(puts("search #{type} #{what}"))
|
109
|
-
end
|
110
|
-
|
111
|
-
def current_playlist_songs
|
112
|
-
parse_song_list(puts("playlistid"))
|
113
|
-
end
|
114
|
-
|
115
|
-
def list_all_songs
|
116
|
-
parse_song_list(puts("listallinfo"))
|
117
|
-
end
|
118
|
-
|
119
|
-
def current_song
|
120
|
-
parse_song_list(puts("currentsong")).first
|
121
|
-
end
|
122
|
-
|
123
|
-
def stats
|
124
|
-
to_hash(puts("stats"))
|
125
|
-
end
|
126
89
|
|
127
|
-
|
128
|
-
unless status[:state] == "stop"
|
129
|
-
output = {:song_time=>current_song[:time],:time=>status[:time].split(":").first,:artist=>current_song[:artist],:title=>current_song[:title],:file=>current_song[:file],:album=>current_song[:album],:id=>current_song[:id]}
|
130
|
-
else
|
131
|
-
output = {:song_time=>0,:time=>0,:artist=>nil,:title=>nil,:file=>nil,:album=>nil,:id=>nil}
|
132
|
-
end
|
133
|
-
end
|
90
|
+
private
|
134
91
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
if line.match(/\Aplaylist\:(.*)\n\Z/)
|
139
|
-
output << to_hash(line)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
output
|
143
|
-
end
|
144
|
-
|
145
|
-
def list_playlist_info(name)
|
146
|
-
parse_song_list(puts("listplaylistinfo #{name}"))
|
147
|
-
end
|
148
|
-
|
149
|
-
def add_to_playlist(uri, name = nil)
|
150
|
-
if name.nil?
|
151
|
-
puts("add \"#{uri}\"")
|
152
|
-
else
|
153
|
-
puts("playlistadd \"#{name}\" \"#{uri}\"")
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def rename_playlist(original_name, name)
|
158
|
-
puts("rename \"#{original_name}\" \"#{name}\"")
|
159
|
-
end
|
160
|
-
|
161
|
-
def create_playlist(name)
|
162
|
-
puts("save \"#{name}\"")
|
163
|
-
end
|
164
|
-
|
165
|
-
def destroy_playlist(name)
|
166
|
-
puts("rm \"#{name}\"")
|
167
|
-
end
|
168
|
-
|
169
|
-
def clear!(name = nil)
|
170
|
-
if name.nil?
|
171
|
-
puts("clear")
|
172
|
-
else
|
173
|
-
puts("playlistclear \"#{name}\"")
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def get_paths
|
178
|
-
song_list(puts("listall"))
|
179
|
-
end
|
92
|
+
def get_volume
|
93
|
+
status[:volume]
|
94
|
+
end
|
180
95
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
if root[segments.first].nil?
|
187
|
-
root << Tree::TreeNode.new(segments.first,segments.first)
|
188
|
-
# root[segments.first] = {}
|
189
|
-
end
|
190
|
-
last_element = root[segments.first]
|
191
|
-
first_element = segments.delete_at(0)
|
192
|
-
segments.each_with_index do |element, index|
|
193
|
-
if last_element[element].nil?
|
194
|
-
last_element << Tree::TreeNode.new(element, first_element + "/" + segments[0...index+1].join("/") )
|
195
|
-
# last_element[element] = {}
|
196
|
-
end
|
197
|
-
last_element = last_element[element]
|
198
|
-
end
|
199
|
-
end
|
200
|
-
root
|
201
|
-
end
|
96
|
+
def set_volume(level)
|
97
|
+
level = 0 if level < 0
|
98
|
+
level = 100 if level > 100
|
99
|
+
send_command "setvol #{level.to_s}"
|
100
|
+
end
|
202
101
|
|
203
|
-
|
204
|
-
|
205
|
-
|
102
|
+
def socket
|
103
|
+
TCPSocket.new(@host, @port)
|
104
|
+
end
|
206
105
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
private
|
106
|
+
def gets_from_socket
|
107
|
+
@socket.gets
|
108
|
+
end
|
211
109
|
|
212
|
-
def
|
110
|
+
def send_command(command)
|
111
|
+
raise StandardError unless @socket
|
213
112
|
@socket.puts(command)
|
214
|
-
|
113
|
+
get_response
|
215
114
|
end
|
216
115
|
|
217
|
-
def
|
116
|
+
def get_response
|
218
117
|
response = ""
|
219
|
-
while line =
|
118
|
+
while line = gets_from_socket do
|
220
119
|
if @@regexps["OK"].match(line)
|
221
120
|
return response
|
222
121
|
elsif error = @@regexps["ACK"].match(line)
|
223
|
-
raise
|
122
|
+
raise ArgumentError.new(line)
|
224
123
|
else
|
225
124
|
response << line
|
226
125
|
end
|
@@ -228,45 +127,20 @@ class Mpc
|
|
228
127
|
response
|
229
128
|
end
|
230
129
|
|
231
|
-
def status
|
232
|
-
output = puts("status")
|
233
|
-
to_hash(output)
|
234
|
-
end
|
235
|
-
|
236
130
|
def to_hash(string)
|
237
|
-
|
238
|
-
string.
|
239
|
-
key, value = line.chomp.split(": ", 2)
|
240
|
-
|
241
|
-
end
|
242
|
-
status_hash
|
243
|
-
end
|
244
|
-
|
245
|
-
def parse_song_list(song_list)
|
246
|
-
output = Array.new
|
247
|
-
song_hash = Hash.new
|
248
|
-
song_list.each do |song|
|
249
|
-
if song.match(@@regexps["FILE"])
|
250
|
-
output << song_hash
|
251
|
-
song_hash = Hash.new
|
252
|
-
end
|
253
|
-
song_hash.merge!(to_hash(song))
|
131
|
+
output = Hash.new
|
132
|
+
string.each_line do |line|
|
133
|
+
key, value = line.chomp.split(": ", 2)
|
134
|
+
output[key.to_sym] = value
|
254
135
|
end
|
255
|
-
output << song_hash
|
256
|
-
output.delete_at(0)
|
257
136
|
output
|
258
137
|
end
|
259
138
|
|
260
|
-
def
|
261
|
-
|
262
|
-
list.each do |song|
|
263
|
-
if song.match(@@regexps["FILE"])
|
264
|
-
output << song.split(": ",2).second.gsub!("\n","")
|
265
|
-
end
|
266
|
-
end
|
267
|
-
output
|
139
|
+
def status
|
140
|
+
to_hash(send_command("status"))
|
268
141
|
end
|
269
142
|
|
270
|
-
|
143
|
+
def bool_to_int(bool)
|
144
|
+
bool == true ? 1 : 0
|
271
145
|
end
|
272
|
-
end
|
146
|
+
end
|
data/lib/mpc/version.rb
ADDED
data/mpc.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mpc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mpc"
|
7
|
+
s.version = Mpc::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Michał Krzyżanowski"]
|
10
|
+
s.email = ["michal.krzyzanowski+github@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{MPD client}
|
13
|
+
s.description = %q{Ruby MPD client}
|
14
|
+
|
15
|
+
s.rubyforge_project = "mpc"
|
16
|
+
|
17
|
+
s.add_dependency("rubytree")
|
18
|
+
|
19
|
+
s.add_development_dependency("mocha")
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/test/mpc_test.rb
CHANGED
@@ -1,189 +1,35 @@
|
|
1
|
-
require "
|
2
|
-
require "mocha"
|
1
|
+
require "test_helper"
|
3
2
|
|
4
|
-
|
3
|
+
class MpcTest < MiniTest::Unit::TestCase
|
5
4
|
|
6
|
-
require "test/unit"
|
7
|
-
require "lib/mpc"
|
8
|
-
require "tree"
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
11
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
|
-
|
13
|
-
class MpcTest < Test::Unit::TestCase
|
14
|
-
|
15
5
|
def setup
|
6
|
+
@socket_mock = stub("TCPSocket", :puts => nil, :gets => nil, :close => nil)
|
16
7
|
@mpc = Mpc.new
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
test "gets raises an exception on ACK response" do
|
21
|
-
TCPSocket.any_instance.stubs(:gets).returns("ACK [5@0] {} unknown command \"asd\"\n")
|
22
|
-
assert_raise(Mpc::Exception) do
|
23
|
-
@mpc.send(:puts,'asd')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
test "gets outputs empty string on OK response " do
|
28
|
-
TCPSocket.any_instance.stubs(:gets).returns("OK\n")
|
29
|
-
assert_equal("",@mpc.stop )
|
30
|
-
end
|
31
|
-
|
32
|
-
test "status outputs propper hash" do
|
33
|
-
@mpc.stubs(:gets).returns("volume: -1\nrepeat: 0\nrandom: 0\nsingle: 0\nconsume: 0\nplaylist: 43\nplaylistlength: 41\nxfade: 0\nstate: stop\nsong: 17\nsongid: 17\nnextsong: 18\nnextsongid: 18\n")
|
34
|
-
assert_equal({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"},@mpc.send(:status) )
|
35
|
-
end
|
36
|
-
|
37
|
-
test "random without state should send request with opposite value" do
|
38
|
-
@mpc.stubs(:status).returns({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"})
|
39
|
-
@mpc.expects(:puts).with('random 1')
|
40
|
-
@mpc.random
|
41
|
-
end
|
42
|
-
|
43
|
-
test "random with state should send request with given value" do
|
44
|
-
@mpc.stubs(:status).returns({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"})
|
45
|
-
@mpc.expects(:puts).with('random 0')
|
46
|
-
@mpc.random(0)
|
47
|
-
end
|
48
|
-
|
49
|
-
test "repeat without state should send request with opposite value" do
|
50
|
-
@mpc.stubs(:status).returns({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"})
|
51
|
-
@mpc.expects(:puts).with('repeat 1')
|
52
|
-
@mpc.repeat
|
53
|
-
end
|
54
|
-
|
55
|
-
test "repeat with state should send request with given value" do
|
56
|
-
@mpc.stubs(:status).returns({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"})
|
57
|
-
@mpc.expects(:puts).with('repeat 0')
|
58
|
-
@mpc.repeat(0)
|
59
|
-
end
|
60
|
-
|
61
|
-
test "set_volume with volume in propper range should not raise exception" do
|
62
|
-
@mpc.expects(:puts).with('setvol 100')
|
63
|
-
@mpc.set_volume(100)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "setvol with volume out of range should raise exception" do
|
67
|
-
assert_raise(Mpc::Exception) do
|
68
|
-
@mpc.set_volume(200)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
test "seek without song_position seeks current song" do
|
73
|
-
@mpc.stubs(:current_song).returns({:date=>"2008", :track=>"4", :album=>"One Kind Favor", :genre=>"Blues", :time=>"190", :file=>"Kuba's Music/B.B. King - One Kind Favor/04. B.B. King - How Many More Years.mp3", :pos=>"3", :title=>"How Many More Years", :id=>"3", :albumartist=>"B.B. King", :artist=>"B.B. King"})
|
74
|
-
@mpc.expects(:puts).with('seek 3 130')
|
75
|
-
@mpc.seek(130)
|
76
|
-
end
|
77
|
-
|
78
|
-
test "seek with song_position seeks given song" do
|
79
|
-
@mpc.stubs(:current_song).returns({:date=>"2008", :track=>"4", :album=>"One Kind Favor", :genre=>"Blues", :time=>"190", :file=>"Kuba's Music/B.B. King - One Kind Favor/04. B.B. King - How Many More Years.mp3", :pos=>"3", :title=>"How Many More Years", :id=>"3", :albumartist=>"B.B. King", :artist=>"B.B. King"})
|
80
|
-
@mpc.expects(:puts).with('seek 11 20')
|
81
|
-
@mpc.seek(20,11)
|
82
|
-
end
|
83
|
-
|
84
|
-
test "find with wrong type should raise exception" do
|
85
|
-
assert_raise(Mpc::Exception) do
|
86
|
-
@mpc.find('wrong_type')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
test "find with correct type but with empty string should raise exception" do
|
91
|
-
assert_raise(Mpc::Exception) do
|
92
|
-
@mpc.find('artist',"")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
test "find with correct type and with string should return hash with songs" do
|
97
|
-
|
8
|
+
@mpc.stubs(:socket).returns(@socket_mock)
|
9
|
+
@mpc.connect
|
98
10
|
end
|
99
11
|
|
100
|
-
|
101
|
-
@mpc.
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@root = Tree::TreeNode.new('/')
|
106
|
-
@first_node = Tree::TreeNode.new('Abra Dab')
|
107
|
-
|
108
|
-
@folder = Tree::TreeNode.new('Miasto Jest Nasze')
|
109
|
-
@folder << Tree::TreeNode.new('ABRADAB - Bezposrednio.mp3')
|
110
|
-
@folder << Tree::TreeNode.new('miasto jest nasze (3).mp3')
|
111
|
-
|
112
|
-
@first_node << @folder
|
113
|
-
@root << @first_node
|
114
|
-
|
115
|
-
@second_node = Tree::TreeNode.new('iTunes')
|
116
|
-
@folder = Tree::TreeNode.new('iTunes Music')
|
117
|
-
@first_subfolder = Tree::TreeNode.new('02. Aaliyah')
|
118
|
-
@element = Tree::TreeNode.new('Romeo must die')
|
119
|
-
@mp3 = Tree::TreeNode.new('06 Are You Feelin Me.mp3')
|
120
|
-
@element << @mp3
|
121
|
-
@first_subfolder << @element
|
122
|
-
@second_subfolder = Tree::TreeNode.new("07. Dave Bing ft Lil' Mo")
|
123
|
-
@element = Tree::TreeNode.new('Romeo must die')
|
124
|
-
@mp3 = Tree::TreeNode.new('12 Someone Gonna Die Tonight.mp3')
|
125
|
-
@element << @mp3
|
126
|
-
@second_subfolder << @element
|
127
|
-
|
128
|
-
@folder << @first_subfolder
|
129
|
-
@folder << @second_subfolder
|
130
|
-
@second_node << @folder
|
131
|
-
@root << @second_node
|
132
|
-
|
133
|
-
assert_equal(@root.to_s,@mpc.list_library.to_s)
|
12
|
+
def test_library_raises_error_if_there_is_no_connection
|
13
|
+
@mpc.disconnect
|
14
|
+
assert_raises(StandardError){
|
15
|
+
@mpc.play
|
16
|
+
}
|
134
17
|
end
|
135
18
|
|
136
|
-
|
137
|
-
@mpc.
|
138
|
-
|
19
|
+
def test_gets_raises_an_exception_on_ACK_response
|
20
|
+
@mpc.stubs(:gets_from_socket).returns("ACK [5@0] {} unknown command \"asd\"\n")
|
21
|
+
assert_raises(ArgumentError){
|
22
|
+
@mpc.send(:send_command, "asd")
|
23
|
+
}
|
139
24
|
end
|
140
25
|
|
141
|
-
|
142
|
-
@mpc.stubs(:
|
143
|
-
|
144
|
-
expected_output << {:playlist => "asd"}
|
145
|
-
expected_output << {:playlist => "foo"}
|
146
|
-
expected_output << {:playlist => "nowa"}
|
147
|
-
assert_equal(expected_output,@mpc.list_playlists)
|
26
|
+
def test_gets_outputs_empty_string_on_OK_response
|
27
|
+
@mpc.stubs(:gets_from_socket).returns("OK\n")
|
28
|
+
assert_equal("", @mpc.stop )
|
148
29
|
end
|
149
30
|
|
150
|
-
|
151
|
-
@mpc.stubs(:
|
152
|
-
|
153
|
-
:id=> "23",
|
154
|
-
:title=> "ToNieMy",
|
155
|
-
:file=> "Paktofonika - Kinematografia/ToNieMy.mp3",
|
156
|
-
:time=> "227",
|
157
|
-
:album=> "Kinematografia",
|
158
|
-
:track=> "6",
|
159
|
-
:pos=> "5",
|
160
|
-
:genre=> "Hip-Hop",
|
161
|
-
:artist=> "Paktofonika"} )
|
162
|
-
@mpc.stubs(:status).returns({
|
163
|
-
:bitrate=> "128",
|
164
|
-
:song=> "5",
|
165
|
-
:volume=> "-1",
|
166
|
-
:audio=> "44100:24:2",
|
167
|
-
:consume=> "0",
|
168
|
-
:repeat=> "0",
|
169
|
-
:nextsong=> "6",
|
170
|
-
:time=> "102:227",
|
171
|
-
:playlist=> "54",
|
172
|
-
:state=> "play",
|
173
|
-
:playlistlength=> "23",
|
174
|
-
:nextsongid=> "24",
|
175
|
-
:xfade=> "0",
|
176
|
-
:random=> "0",
|
177
|
-
:songid=> "23",
|
178
|
-
:single=> "0"})
|
179
|
-
expected_output = {
|
180
|
-
:title=>"ToNieMy",
|
181
|
-
:file=>"Paktofonika - Kinematografia/ToNieMy.mp3",
|
182
|
-
:artist=>"Paktofonika",
|
183
|
-
:album=>"Kinematografia",
|
184
|
-
:song_time=>"227",
|
185
|
-
:id=>"23",
|
186
|
-
:time=>"102"}
|
187
|
-
assert_equal(expected_output,@mpc.ping)
|
31
|
+
def test_status_outputs_propper_hash
|
32
|
+
@mpc.stubs(:get_response).returns("volume: -1\nrepeat: 0\nrandom: 0\nsingle: 0\nconsume: 0\nplaylist: 43\nplaylistlength: 41\nxfade: 0\nstate: stop\nsong: 17\nsongid: 17\nnextsong: 18\nnextsongid: 18\n")
|
33
|
+
assert_equal({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"}, @mpc.send(:status) )
|
188
34
|
end
|
189
35
|
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
version: "0.8"
|
4
|
+
prerelease:
|
5
|
+
version: "0.9"
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- "Micha\xC5\x82 Krzy\xC5\xBCanowski"
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-08-04 00:00:00 +02:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,14 +21,23 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
|
-
segments:
|
30
|
-
- 0
|
31
24
|
version: "0"
|
32
25
|
type: :runtime
|
33
26
|
version_requirements: *id001
|
34
|
-
|
35
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Ruby MPD client
|
39
|
+
email:
|
40
|
+
- michal.krzyzanowski+github@gmail.com
|
36
41
|
executables: []
|
37
42
|
|
38
43
|
extensions: []
|
@@ -40,10 +45,16 @@ extensions: []
|
|
40
45
|
extra_rdoc_files: []
|
41
46
|
|
42
47
|
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Rakefile
|
43
51
|
- lib/mpc.rb
|
52
|
+
- lib/mpc/version.rb
|
53
|
+
- mpc.gemspec
|
44
54
|
- test/mpc_test.rb
|
55
|
+
- test/test_helper.rb
|
45
56
|
has_rdoc: true
|
46
|
-
homepage:
|
57
|
+
homepage: ""
|
47
58
|
licenses: []
|
48
59
|
|
49
60
|
post_install_message:
|
@@ -56,25 +67,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
67
|
requirements:
|
57
68
|
- - ">="
|
58
69
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
|
-
segments:
|
61
|
-
- 0
|
62
70
|
version: "0"
|
63
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
72
|
none: false
|
65
73
|
requirements:
|
66
74
|
- - ">="
|
67
75
|
- !ruby/object:Gem::Version
|
68
|
-
hash: 3
|
69
|
-
segments:
|
70
|
-
- 0
|
71
76
|
version: "0"
|
72
77
|
requirements: []
|
73
78
|
|
74
|
-
rubyforge_project:
|
75
|
-
rubygems_version: 1.
|
79
|
+
rubyforge_project: mpc
|
80
|
+
rubygems_version: 1.5.0
|
76
81
|
signing_key:
|
77
82
|
specification_version: 3
|
78
|
-
summary: MPD client
|
83
|
+
summary: MPD client
|
79
84
|
test_files:
|
80
85
|
- test/mpc_test.rb
|
86
|
+
- test/test_helper.rb
|