cultome_player 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +325 -0
- data/Rakefile +8 -0
- data/bin/cultome_player +39 -0
- data/config/environment.yml +28 -0
- data/cultome_player.gemspec +35 -0
- data/db/001_create_schema.rb +58 -0
- data/lib/cultome_player.rb +107 -0
- data/lib/cultome_player/command.rb +11 -0
- data/lib/cultome_player/command/language.rb +61 -0
- data/lib/cultome_player/command/processor.rb +165 -0
- data/lib/cultome_player/command/reader.rb +86 -0
- data/lib/cultome_player/environment.rb +130 -0
- data/lib/cultome_player/events.rb +29 -0
- data/lib/cultome_player/media.rb +47 -0
- data/lib/cultome_player/objects.rb +15 -0
- data/lib/cultome_player/objects/album.rb +21 -0
- data/lib/cultome_player/objects/artist.rb +18 -0
- data/lib/cultome_player/objects/command.rb +37 -0
- data/lib/cultome_player/objects/drive.rb +26 -0
- data/lib/cultome_player/objects/genre.rb +16 -0
- data/lib/cultome_player/objects/parameter.rb +37 -0
- data/lib/cultome_player/objects/response.rb +42 -0
- data/lib/cultome_player/objects/song.rb +38 -0
- data/lib/cultome_player/player.rb +13 -0
- data/lib/cultome_player/player/adapter.rb +14 -0
- data/lib/cultome_player/player/adapter/mpg123.rb +143 -0
- data/lib/cultome_player/player/interactive.rb +56 -0
- data/lib/cultome_player/player/interface.rb +13 -0
- data/lib/cultome_player/player/interface/basic.rb +96 -0
- data/lib/cultome_player/player/interface/builtin_help.rb +368 -0
- data/lib/cultome_player/player/interface/extended.rb +199 -0
- data/lib/cultome_player/player/interface/helper.rb +300 -0
- data/lib/cultome_player/player/playlist.rb +280 -0
- data/lib/cultome_player/plugins.rb +23 -0
- data/lib/cultome_player/plugins/help.rb +58 -0
- data/lib/cultome_player/state_checker.rb +74 -0
- data/lib/cultome_player/utils.rb +95 -0
- data/lib/cultome_player/version.rb +3 -0
- data/spec/config.yml +0 -0
- data/spec/cultome_player/command/processor_spec.rb +168 -0
- data/spec/cultome_player/command/reader_spec.rb +45 -0
- data/spec/cultome_player/cultome_player_spec.rb +17 -0
- data/spec/cultome_player/environment_spec.rb +65 -0
- data/spec/cultome_player/events_spec.rb +22 -0
- data/spec/cultome_player/media_spec.rb +41 -0
- data/spec/cultome_player/player/adapter/mpg123_spec.rb +82 -0
- data/spec/cultome_player/player/interface/basic_spec.rb +168 -0
- data/spec/cultome_player/player/interface/extended/connect_spec.rb +117 -0
- data/spec/cultome_player/player/interface/extended/search_spec.rb +90 -0
- data/spec/cultome_player/player/interface/extended/show_spec.rb +36 -0
- data/spec/cultome_player/player/interface/extended/shuffle_spec.rb +26 -0
- data/spec/cultome_player/player/interface/extended_spec.rb +136 -0
- data/spec/cultome_player/player/interface/helper_spec.rb +63 -0
- data/spec/cultome_player/player/interface_spec.rb +17 -0
- data/spec/cultome_player/player/playlist_spec.rb +301 -0
- data/spec/cultome_player/plugins/help_spec.rb +21 -0
- data/spec/cultome_player/plugins_spec.rb +19 -0
- data/spec/cultome_player/utils_spec.rb +15 -0
- data/spec/spec_helper.rb +108 -0
- data/spec/test/uno/dos/dos.mp3 +0 -0
- data/spec/test/uno/dos/tres/tres.mp3 +0 -0
- data/spec/test/uno/uno.mp3 +0 -0
- data/tasks/console.rake +19 -0
- data/tasks/db.rake +19 -0
- data/tasks/run.rake +7 -0
- metadata +322 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CultomePlayer::Player::Interface::Helper do
|
4
|
+
let(:t){ TestClass.new }
|
5
|
+
|
6
|
+
it 'raise an error if processing a unknown object' do
|
7
|
+
expect{ t.process_for_search([Parameter.new({type: :object, value: 'unknown'})]) }.to raise_error 'invalid search:unknown type'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'create a progress bar' do
|
11
|
+
t.get_progress_bar(55, 200, 10).should eq "|##________|"
|
12
|
+
t.get_progress_bar(55, 100, 10).should eq "|#####_____|"
|
13
|
+
t.get_progress_bar(55, 100, 20).should eq "|###########_________|"
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'create a progress bar with labels in both sides' do
|
17
|
+
t.get_progress_bar_with_labels(5, 10, 10, "left", "right").should eq "left |#####_____| right"
|
18
|
+
t.get_progress_bar_with_labels(5, 10, 10, "left").should eq "left |#####_____|"
|
19
|
+
t.get_progress_bar_with_labels(5, 10, 10, "", "right").should eq "|#####_____| right"
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'format seconds to minutos:seconds' do
|
23
|
+
t.format_secs(4).should eq "00:04"
|
24
|
+
t.format_secs(75).should eq "01:15"
|
25
|
+
t.format_secs(65).should eq "01:05"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#process_object_for_search' do
|
29
|
+
it 'returns sql criteria and values for object type artist' do
|
30
|
+
artist = double("artist", name: "artist_name")
|
31
|
+
t.should_receive(:current_artist).and_return(artist)
|
32
|
+
|
33
|
+
q,v = t.send(:process_object_for_search, [Parameter.new({type: :object, value: :artist})] )
|
34
|
+
q.should eq 'artists.name = ?'
|
35
|
+
v.should eq ["artist_name"]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns sql criteria and values for object type album' do
|
39
|
+
album = double("album", name: "album_name")
|
40
|
+
t.should_receive(:current_album).and_return(album)
|
41
|
+
|
42
|
+
q,v = t.send(:process_object_for_search, [Parameter.new({type: :object, value: :album})] )
|
43
|
+
q.should eq 'albums.name = ?'
|
44
|
+
v.should eq ["album_name"]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns sql criteria and values for object type song' do
|
48
|
+
song = double("song", name: "song_name")
|
49
|
+
t.should_receive(:current_song).and_return(song)
|
50
|
+
|
51
|
+
q,v = t.send(:process_object_for_search, [Parameter.new({type: :object, value: :song})] )
|
52
|
+
q.should eq 'songs.name = ?'
|
53
|
+
v.should eq ["song_name"]
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns sql criteria and values for object type library' do
|
57
|
+
q,v = t.send(:process_object_for_search, [Parameter.new({type: :object, value: :library})] )
|
58
|
+
q.should eq 'songs.id > 0'
|
59
|
+
v.should be_empty
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CultomePlayer::Player::Interface do
|
4
|
+
let(:t){ TestClass.new }
|
5
|
+
|
6
|
+
it 'respond to basic commands' do
|
7
|
+
[:play , :pause , :stop , :next , :prev , :quit].each do |cmd|
|
8
|
+
t.should respond_to cmd
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'respond to extended commands' do
|
13
|
+
[:show , :enqueue , :search , :shuffle , :connect , :disconnect , :ff , :fb].each do |cmd|
|
14
|
+
t.should respond_to cmd
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,301 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CultomePlayer::Player::Playlist do
|
4
|
+
let(:p){ CultomePlayer::Player::Playlist::Playlists.new }
|
5
|
+
|
6
|
+
it 'add a new playlist' do
|
7
|
+
p.should be_empty
|
8
|
+
p.register(:playlist)
|
9
|
+
p.should have(1).item
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'raise error if trying to use a unregistered playlist' do
|
13
|
+
expect{ p[:playlist] }.to raise_error('unknown playlist:playlist is not registered' )
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a playlist registered' do
|
17
|
+
before :each do
|
18
|
+
p.register(:playlist)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return playlists object' do
|
22
|
+
p[:playlist].should be_instance_of CultomePlayer::Player::Playlist::Playlists
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raise and error if traying to register a previous registered playlist' do
|
26
|
+
expect{ p.register(:playlist) }.to raise_error('invalid registry:playlist already registered')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'get a playlist by name' do
|
30
|
+
p[:playlist].should have(1).item
|
31
|
+
p[:playlist].first.should_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'add an element to an existing playlist' do
|
35
|
+
p[:playlist].first.should be_empty
|
36
|
+
p[:playlist] << "eleme"
|
37
|
+
p[:playlist].first.should have(1).item
|
38
|
+
p[:playlist] << "eleme"
|
39
|
+
p[:playlist].first.should have(2).item
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'replace the content of a playlist' do
|
43
|
+
p[:playlist].first.should be_empty
|
44
|
+
p[:playlist] << "eleme"
|
45
|
+
p[:playlist] << "eleme"
|
46
|
+
p[:playlist].first.should have(2).item
|
47
|
+
p[:playlist] <= %w{uno dos tres cuatro}
|
48
|
+
p[:playlist].first.should have(4).item
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'raise an error if trying to get the next song in an empty list' do
|
52
|
+
expect{ p[:playlist].next }.to raise_error 'playlist empty:no songs in playlists'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'change shuffle status' do
|
56
|
+
p[:playlist].should_not be_shuffling
|
57
|
+
p[:playlist].shuffle
|
58
|
+
p[:playlist].should be_shuffling
|
59
|
+
p[:playlist].order
|
60
|
+
p[:playlist].should_not be_shuffling
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with a full playlist' do
|
64
|
+
before :each do
|
65
|
+
p[:playlist] <= %w{uno dos tres cuatro}
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'shuffle the content of the playlist' do
|
69
|
+
p[:playlist].first.should eq %w{uno dos tres cuatro}
|
70
|
+
p[:playlist].shuffle
|
71
|
+
p[:playlist].shuffle if p[:playlist].first == %w{uno dos tres cuatro}
|
72
|
+
p[:playlist].first.should_not eq %w{uno dos tres cuatro}
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'get an element by index' do
|
76
|
+
p[:playlist].at(0).should eq "uno"
|
77
|
+
p[:playlist].at(3).should eq "cuatro"
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'order the content of the playlist' do
|
81
|
+
p[:playlist].order
|
82
|
+
p[:playlist].first.should eq %w{cuatro dos tres uno}
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'updated the play index' do
|
86
|
+
expect{ p[:playlist].next }.to change{ p[:playlist].play_index }.by(1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'reset the play order when ordered' do
|
90
|
+
p[:playlist].next
|
91
|
+
p[:playlist].play_index.should eq 0
|
92
|
+
p[:playlist].next
|
93
|
+
p[:playlist].play_index.should eq 1
|
94
|
+
|
95
|
+
p[:playlist].order
|
96
|
+
|
97
|
+
p[:playlist].next
|
98
|
+
p[:playlist].play_index.should eq 0
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'reset the play order when shuffled' do
|
102
|
+
p[:playlist].next
|
103
|
+
p[:playlist].play_index.should eq 0
|
104
|
+
p[:playlist].next
|
105
|
+
p[:playlist].play_index.should eq 1
|
106
|
+
|
107
|
+
p[:playlist].shuffle
|
108
|
+
|
109
|
+
p[:playlist].next
|
110
|
+
p[:playlist].play_index.should eq 0
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'repeat the list if repeat is active' do
|
114
|
+
p[:playlist].repeat?.should be_true
|
115
|
+
p[:playlist].next.should eq "uno"
|
116
|
+
p[:playlist].next
|
117
|
+
p[:playlist].next
|
118
|
+
p[:playlist].next.should eq "cuatro"
|
119
|
+
p[:playlist].next.should eq "uno"
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'raise an error if traying to retrive an ended playlist' do
|
123
|
+
p[:playlist].repeat false
|
124
|
+
p[:playlist].repeat?.should be_false
|
125
|
+
p[:playlist].next.should eq "uno"
|
126
|
+
p[:playlist].next
|
127
|
+
p[:playlist].next
|
128
|
+
p[:playlist].next.should eq "cuatro"
|
129
|
+
expect{ p[:playlist].next }.to raise_error("playlist empty:no songs in playlists")
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'return nil if checking current song but playlist has not be played' do
|
133
|
+
p[:playlist].current.should be_nil
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'return the current song in playlist' do
|
137
|
+
p[:playlist].next.should eq "uno"
|
138
|
+
p[:playlist].current.should eq "uno"
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'removes and return the next song from the playlist' do
|
142
|
+
p[:playlist].should have(4).songs
|
143
|
+
p[:playlist].remove_next.should eq "uno"
|
144
|
+
p[:playlist].should have(3).songs
|
145
|
+
p[:playlist].remove_next.should eq "dos"
|
146
|
+
p[:playlist].should have(2).songs
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'iterate over every song' do
|
150
|
+
pl = ":"
|
151
|
+
p[:playlist].each_song do |s|
|
152
|
+
pl << s.to_s
|
153
|
+
end
|
154
|
+
pl.should eq ":unodostrescuatro"
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'check if there are songs remaining in the playlist' do
|
158
|
+
p[:playlist].repeat(false)
|
159
|
+
p[:playlist].repeat?.should be_false
|
160
|
+
p[:playlist].next?.should be_true
|
161
|
+
p[:playlist].next
|
162
|
+
p[:playlist].next
|
163
|
+
p[:playlist].next
|
164
|
+
p[:playlist].next
|
165
|
+
p[:playlist].next?.should be_false
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'pop the last element inserted' do
|
169
|
+
p[:playlist].should have(4).songs
|
170
|
+
p[:playlist] << 'cinco'
|
171
|
+
p[:playlist].should have(5).songs
|
172
|
+
p[:playlist].pop.should eq 'cinco'
|
173
|
+
p[:playlist].pop.should eq 'cuatro'
|
174
|
+
p[:playlist].should have(3).songs
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'rewind the playlist' do
|
178
|
+
p[:playlist].next.should eq 'uno'
|
179
|
+
p[:playlist].next.should eq 'dos'
|
180
|
+
p[:playlist].next.should eq 'tres'
|
181
|
+
p[:playlist].next.should eq 'cuatro'
|
182
|
+
p[:playlist].current.should eq 'cuatro'
|
183
|
+
p[:playlist].rewind_by(1).should eq 'tres'
|
184
|
+
p[:playlist].current.should eq 'tres'
|
185
|
+
p[:playlist].rewind_by(2).should eq 'uno'
|
186
|
+
p[:playlist].current.should eq 'uno'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'with multiple playlist registered' do
|
192
|
+
before :each do
|
193
|
+
p.register(:uno)
|
194
|
+
p.register(:dos)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'get multiples playlists by name' do
|
198
|
+
p[:uno, :dos].should have(2).item
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'add an element to more than one existing playlists' do
|
202
|
+
p[:uno, :dos].each{|p| p.should be_empty }
|
203
|
+
p[:uno, :dos] << "elem"
|
204
|
+
p[:uno, :dos].each{|p| p.should have(1).item }
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'replace the content of more than one existing playlists' do
|
208
|
+
p[:uno, :dos].each{|p| p.should be_empty }
|
209
|
+
p[:uno, :dos] << "elem"
|
210
|
+
p[:uno, :dos] << "elem"
|
211
|
+
p[:uno, :dos].each{|p| p.should have(2).item }
|
212
|
+
p[:uno, :dos].each{|p| p.should eq ["elem", "elem"] }
|
213
|
+
p[:uno, :dos] <= %w{uno dos tres cuatro}
|
214
|
+
p[:uno, :dos].each{|p| p.should have(4).item }
|
215
|
+
p[:uno, :dos].each{|p| p.should eq %w{uno dos tres cuatro} }
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'return elements in aparence order' do
|
219
|
+
p.register(:tres)
|
220
|
+
p[:uno] << "uno"
|
221
|
+
p[:dos] << "dos"
|
222
|
+
p[:tres] << "tres"
|
223
|
+
|
224
|
+
p[:uno, :dos, :tres].next.should eq %w{uno dos tres}
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'return nil if checking current song but playlist has not be played' do
|
228
|
+
p[:uno, :dos].current.should be_nil
|
229
|
+
p[:uno] << "uno"
|
230
|
+
p[:uno].next
|
231
|
+
expect{ p[:uno, :dos].current }.to raise_error "no current:no current song in one of the playlists"
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'return the current song in playlist' do
|
235
|
+
p[:uno] << "uno"
|
236
|
+
p[:dos] << "tres"
|
237
|
+
p[:uno, :dos].next.should eq ["uno", "tres"]
|
238
|
+
p[:uno, :dos].current.should eq ["uno", "tres"]
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'raise an error if getting the next of an empty playlist' do
|
242
|
+
p[:uno] << "uno"
|
243
|
+
expect{ p[:uno, :dos].next }.to raise_error 'playlist empty:no songs in one of the playlists'
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'iterate over every song' do
|
247
|
+
p[:uno] << "uno"
|
248
|
+
p[:dos] << "dos"
|
249
|
+
pl = ":"
|
250
|
+
p.each_song do |s,idx|
|
251
|
+
pl << "#{idx}#{s.to_s}"
|
252
|
+
end
|
253
|
+
pl.should eq ":1uno2dos"
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'check if there are songs remaining in the playlists' do
|
257
|
+
p[:uno, :dos].repeat false
|
258
|
+
p[:uno, :dos].repeat?.should eq [false, false]
|
259
|
+
p[:uno, :dos] << 'uno'
|
260
|
+
p[:uno] << 'dos'
|
261
|
+
p[:uno].next?.should be_true
|
262
|
+
p[:dos].next?.should be_true
|
263
|
+
p[:uno, :dos].next?.should eq [true, true]
|
264
|
+
p[:uno, :dos].next
|
265
|
+
p[:uno, :dos].next?.should eq [true, false]
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'change shuffle status' do
|
269
|
+
p[:uno, :dos].shuffling?.should eq [false, false]
|
270
|
+
p[:uno, :dos].shuffle
|
271
|
+
p[:uno, :dos].shuffling?.should eq [true, true]
|
272
|
+
p[:uno, :dos].order
|
273
|
+
p[:uno, :dos].shuffling?.should eq [false, false]
|
274
|
+
end
|
275
|
+
|
276
|
+
|
277
|
+
it 'pop the last element inserted' do
|
278
|
+
p[:uno].should have(0).songs
|
279
|
+
p[:dos].should have(0).songs
|
280
|
+
p[:uno] << 'cinco'
|
281
|
+
p[:dos] << 'seis'
|
282
|
+
p[:uno].should have(1).songs
|
283
|
+
p[:dos].should have(1).songs
|
284
|
+
p[:uno, :dos].pop.should eq ['cinco', 'seis']
|
285
|
+
p[:uno].should have(0).songs
|
286
|
+
p[:dos].should have(0).songs
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'rewind the playlists' do
|
290
|
+
p[:uno] << 'uno'
|
291
|
+
p[:uno] << 'dos'
|
292
|
+
p[:dos] << 'tres'
|
293
|
+
p[:dos] << 'cuatro'
|
294
|
+
|
295
|
+
p[:uno, :dos].next.should eq ['uno', 'tres']
|
296
|
+
p[:uno, :dos].next.should eq ['dos', 'cuatro']
|
297
|
+
p[:uno, :dos].current.should eq ['dos', 'cuatro']
|
298
|
+
p[:uno, :dos].rewind_by(1).should eq ['uno', 'tres']
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPlugin
|
4
|
+
include CultomePlayer::Plugins::Help
|
5
|
+
end
|
6
|
+
|
7
|
+
describe CultomePlayer::Plugins::Help do
|
8
|
+
let(:p){ TestPlugin.new }
|
9
|
+
|
10
|
+
it 'respond to command_help' do
|
11
|
+
p.should respond_to(:command_help)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'respond to usage_help' do
|
15
|
+
p.should respond_to(:usage_help)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'respond to description_help' do
|
19
|
+
p.should respond_to(:description_help)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CultomePlayer::Plugins do
|
4
|
+
let(:p){
|
5
|
+
class TestPlugin
|
6
|
+
include CultomePlayer::Plugins
|
7
|
+
end
|
8
|
+
|
9
|
+
TestPlugin.new
|
10
|
+
}
|
11
|
+
it 'check if plugins respond to a given command' do
|
12
|
+
p.plugins_respond_to?("help").should be_true
|
13
|
+
p.plugins_respond_to?("nonexistent").should_not be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'return the format for a command' do
|
17
|
+
p.plugin_command_sintaxis("help").should be_instance_of Regexp
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CultomePlayer::Utils do
|
4
|
+
let(:t){ TestClass.new(:rspec) }
|
5
|
+
|
6
|
+
describe 'arrange information in columns' do
|
7
|
+
it 'everything fits in a row' do
|
8
|
+
t.arrange_in_columns(["12345", "1234567890"], [5, 10], 2).should eq "12345 1234567890"
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'data bigger than column span into another row' do
|
12
|
+
t.arrange_in_columns(["12345", "123456789012345"], [5, 10], 2).should eq "12345 1234567890\n 12345"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'database_cleaner'
|
3
|
+
require 'cultome_player'
|
4
|
+
|
5
|
+
Coveralls.wear!
|
6
|
+
|
7
|
+
include CultomePlayer::Environment
|
8
|
+
include CultomePlayer::Utils
|
9
|
+
include CultomePlayer::Objects
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
config.filter_run_excluding :mplayer
|
16
|
+
config.order = 'random'
|
17
|
+
|
18
|
+
config.before(:suite) do
|
19
|
+
prepare_environment(:rspec)
|
20
|
+
with_connection do
|
21
|
+
DatabaseCleaner.strategy = :transaction
|
22
|
+
DatabaseCleaner.clean_with(:truncation)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
config.before(:each) do
|
27
|
+
with_connection { DatabaseCleaner.start }
|
28
|
+
end
|
29
|
+
|
30
|
+
config.after(:each) do
|
31
|
+
with_connection { DatabaseCleaner.clean }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module FakeStatus
|
36
|
+
def current_artist
|
37
|
+
Artist.new(name: 'artist_uno')
|
38
|
+
end
|
39
|
+
|
40
|
+
def current_album
|
41
|
+
Album.new(name: 'album_tres')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module FakeExtractor
|
46
|
+
def extract_from_txt(filepath, opc)
|
47
|
+
filename = filepath[filepath.rindex("/")+1, filepath.length]
|
48
|
+
extension = filename[filename.rindex(".")+1, filename.length]
|
49
|
+
|
50
|
+
file_info = { filename: filename, path: filepath, extension: extension }
|
51
|
+
|
52
|
+
file_info[:relative_path] = filepath.gsub(/#{opc[:root_path]}\//, '') if opc.has_key?(:root_path)
|
53
|
+
|
54
|
+
return file_info
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module MockPlayer
|
59
|
+
def send_to_player(cmd)
|
60
|
+
if cmd == 'pause'
|
61
|
+
if @paused
|
62
|
+
@paused = @stopped = false
|
63
|
+
@playing = true
|
64
|
+
else
|
65
|
+
@paused = true
|
66
|
+
@stopped = @playing = false
|
67
|
+
end
|
68
|
+
elsif cmd.start_with?('load')
|
69
|
+
@is_player_running = @playing = true
|
70
|
+
elsif cmd.start_with?('stop')
|
71
|
+
@is_player_running = @paused = @playing = false
|
72
|
+
@stopped = true
|
73
|
+
elsif cmd.start_with?('jump')
|
74
|
+
# do nothing
|
75
|
+
else
|
76
|
+
puts "ERROR: #{cmd} !!!!!!!"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def control_pipe
|
81
|
+
STDOUT
|
82
|
+
end
|
83
|
+
|
84
|
+
def start_player
|
85
|
+
@play_in_player = true
|
86
|
+
@playing = true
|
87
|
+
@paused = @stopped = false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class TestClass
|
92
|
+
include CultomePlayer
|
93
|
+
include FakeStatus
|
94
|
+
include FakeExtractor
|
95
|
+
include MockPlayer
|
96
|
+
|
97
|
+
def initialize(env=:rspec)
|
98
|
+
prepare_environment(env) unless env.nil?
|
99
|
+
playlists.register(:current)
|
100
|
+
playlists.register(:history)
|
101
|
+
playlists.register(:queue)
|
102
|
+
playlists.register(:focus)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_folder
|
107
|
+
File.join(File.dirname(File.expand_path(__FILE__)), 'test')
|
108
|
+
end
|