jimmy_jukebox 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/jimmy_jukebox/jukebox.rb +2 -1
- data/lib/jimmy_jukebox/song.rb +1 -1
- data/lib/jimmy_jukebox/version.rb +2 -2
- data/spec/jimmy_jukebox_spec.rb +39 -17
- data/spec/song_spec.rb +34 -73
- data/spec/user_config_spec.rb +0 -1
- metadata +82 -71
@@ -2,6 +2,8 @@ require 'jimmy_jukebox/user_config'
|
|
2
2
|
|
3
3
|
module JimmyJukebox
|
4
4
|
|
5
|
+
RUNNING_JRUBY = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby') || RUBY_PLATFORM == 'java'
|
6
|
+
|
5
7
|
class Jukebox
|
6
8
|
|
7
9
|
class NoSongsException < Exception; end
|
@@ -134,7 +136,6 @@ module JimmyJukebox
|
|
134
136
|
self.songs_played << song
|
135
137
|
current_song.play(user_config, self)
|
136
138
|
p "Finished playing"
|
137
|
-
#p "Songs played: " + songs_played.to_s
|
138
139
|
self.current_song = nil
|
139
140
|
self.playing = false
|
140
141
|
rescue Song::SongTerminatedPrematurelyException
|
data/lib/jimmy_jukebox/song.rb
CHANGED
data/spec/jimmy_jukebox_spec.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
2
|
+
require 'jimmy_jukebox/song'
|
3
|
+
require 'jimmy_jukebox/jukebox'
|
3
4
|
include JimmyJukebox
|
4
5
|
|
5
6
|
# don't actually play music
|
6
7
|
module JimmyJukebox
|
7
8
|
class Song
|
8
|
-
def spawn_method
|
9
|
-
|
9
|
+
def spawn_method
|
10
|
+
if JimmyJukebox::RUNNING_JRUBY
|
11
|
+
gem 'spoon'
|
12
|
+
require 'spoon'
|
13
|
+
lambda { |command, arg| Spoon.spawnp('sleep 2') }
|
14
|
+
else
|
15
|
+
gem 'posix-spawn'
|
16
|
+
require 'posix/spawn'
|
17
|
+
lambda { |command, arg| POSIX::Spawn::spawn('sleep 2') }
|
18
|
+
end
|
10
19
|
end
|
11
20
|
end
|
12
21
|
end
|
@@ -19,50 +28,63 @@ describe Jukebox do
|
|
19
28
|
ARGV.clear
|
20
29
|
end
|
21
30
|
|
22
|
-
let(:
|
23
|
-
|
24
|
-
let(:uc) { double('user_config').as_null_object }
|
31
|
+
let(:uc) { UserConfig.new }
|
25
32
|
|
26
33
|
context "with no command line parameter" do
|
27
34
|
|
28
35
|
context "when no songs available" do
|
36
|
+
|
37
|
+
let(:jb) { Jukebox.new(uc, false) }
|
38
|
+
|
29
39
|
it "raises exception when no songs available" do
|
30
40
|
expect { jb }.to raise_error(Jukebox::NoSongsException)
|
31
41
|
end
|
42
|
+
|
32
43
|
end
|
33
44
|
|
34
45
|
context "when songs exist" do
|
35
46
|
|
36
|
-
let(:
|
37
|
-
let(:
|
38
|
-
let(:
|
47
|
+
let(:song1_path) { File.expand_path('~/Music/Rock/Beatles/Abbey_Road.mp3') }
|
48
|
+
let(:song2_path) { File.expand_path('~/Music/Rock/Beatles/Sgt_Pepper.mp3') }
|
49
|
+
let(:song3_path) { File.expand_path('~/Music/Rock/Eagles/Hotel_California.ogg') }
|
50
|
+
let(:jb) { Jukebox.new(uc) }
|
39
51
|
|
40
52
|
before do
|
41
|
-
[
|
53
|
+
[song1_path, song2_path, song3_path].each do |song|
|
42
54
|
FileUtils.mkdir_p(File.dirname(song))
|
43
55
|
FileUtils.touch(song)
|
44
56
|
Dir.chdir(File.expand_path('~'))
|
45
57
|
end
|
46
|
-
File.exists?(
|
58
|
+
File.exists?(song1_path).should be_true
|
47
59
|
end
|
48
60
|
|
49
61
|
it "generates a non-empty song list" do
|
50
62
|
jb.songs.should_not be_nil
|
51
63
|
jb.songs.should_not be_empty
|
52
64
|
jb.songs.length.should == 3
|
53
|
-
jb.songs.
|
65
|
+
jb.songs.grep(/Abbey_Road.mp3/).length.should == 1
|
54
66
|
end
|
55
67
|
|
56
68
|
it "can quit" do
|
57
69
|
jb.should_not be_nil
|
70
|
+
#jb.stub(:songs).and_return([song1, song2, song3])
|
71
|
+
#jb.stub(:next_song).and_return(song1)
|
72
|
+
play_loop_thread = Thread.new do
|
73
|
+
jb.play_loop
|
74
|
+
end
|
75
|
+
sleep 0.5
|
76
|
+
jb.playing?.should be_true
|
77
|
+
p jb.current_song
|
58
78
|
jb.quit
|
59
79
|
end
|
60
80
|
|
61
|
-
it "calls
|
62
|
-
jb.
|
63
|
-
|
64
|
-
|
65
|
-
|
81
|
+
it "calls play_next_song" do
|
82
|
+
jb.should_receive(:play_next_song).at_least(:once)
|
83
|
+
play_loop_thread = Thread.new do
|
84
|
+
jb.play_loop
|
85
|
+
end
|
86
|
+
sleep 0.1
|
87
|
+
play_loop_thread.exit
|
66
88
|
end
|
67
89
|
|
68
90
|
it "has a user_config method" do
|
data/spec/song_spec.rb
CHANGED
@@ -8,17 +8,20 @@ include JimmyJukebox
|
|
8
8
|
# don't actually play music
|
9
9
|
module JimmyJukebox
|
10
10
|
class Song
|
11
|
-
def spawn_method
|
12
|
-
|
11
|
+
def spawn_method
|
12
|
+
if JimmyJukebox::RUNNING_JRUBY
|
13
|
+
require 'spoon'
|
14
|
+
lambda { |command, arg| Spoon.spawnp('sleep 2') }
|
15
|
+
else
|
16
|
+
require 'posix/spawn'
|
17
|
+
lambda { |command, arg| POSIX::Spawn::spawn('sleep 2') }
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
23
|
describe Song do
|
18
24
|
|
19
|
-
before(:each) do
|
20
|
-
end
|
21
|
-
|
22
25
|
describe "#initialize" do
|
23
26
|
|
24
27
|
it "requires a parameter" do
|
@@ -49,109 +52,67 @@ describe Song do
|
|
49
52
|
|
50
53
|
before(:each) do
|
51
54
|
@uc = UserConfig.new
|
52
|
-
@jj = Jukebox.new(@uc)
|
55
|
+
@jj = Jukebox.new(@uc, false)
|
53
56
|
@song = Song.new("~/Music/JAZZ/art_tatum.mp3")
|
54
57
|
end
|
55
58
|
|
56
59
|
it "is initially not paused" do
|
57
|
-
@
|
60
|
+
@jj.play_song(@song)
|
58
61
|
@song.paused?.should be_false
|
59
62
|
end
|
60
63
|
|
61
64
|
it "is paused after calling #pause" do
|
62
|
-
@song
|
63
|
-
@
|
65
|
+
@jj.play_song(@song)
|
66
|
+
@jj.pause_current_song
|
64
67
|
@song.paused?.should be_true
|
65
68
|
end
|
66
69
|
|
67
70
|
it "is unpaused after calling #pause and #unpause" do
|
71
|
+
@jj.play_song(@song)
|
68
72
|
@song.pause
|
73
|
+
@song.paused?.should be_true
|
69
74
|
@song.unpause
|
70
75
|
@song.paused?.should be_false
|
71
76
|
end
|
72
77
|
|
73
78
|
end
|
74
79
|
|
75
|
-
describe "#
|
80
|
+
describe "#skip_song" do
|
76
81
|
|
77
82
|
before(:each) do
|
78
|
-
@
|
79
|
-
@
|
80
|
-
|
81
|
-
|
82
|
-
let(:uc) { double('user_config').as_null_object }
|
83
|
-
let(:ps) { double('process_status').as_null_object}
|
84
|
-
|
85
|
-
it "calls #play_with_player" do
|
86
|
-
ps.stub(:exitstatus).and_return(0)
|
87
|
-
@song.should_receive(:play_with_player).and_return(ps)
|
88
|
-
uc.stub(:mp3_player) {"play"}
|
89
|
-
uc.stub(:ogg_player) {"play"}
|
90
|
-
@song.play(uc)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "raises error when exitstatus != 0" do
|
94
|
-
ps.stub(:exitstatus).and_return(1)
|
95
|
-
@song.should_receive(:play_with_player).and_return(ps)
|
96
|
-
uc.stub(:mp3_player) {"play"}
|
97
|
-
uc.stub(:ogg_player) {"play"}
|
98
|
-
expect{@song.play(uc)}.to raise_error
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "#play_with_player" do
|
104
|
-
|
105
|
-
before(:each) do
|
106
|
-
@music_file = "~/Music/JAZZ/art_tatum.mp3"
|
107
|
-
@song = Song.new(@music_file)
|
108
|
-
end
|
109
|
-
|
110
|
-
let(:uc) { double('user_config').as_null_object }
|
111
|
-
let(:ps) { double('process_status').as_null_object}
|
112
|
-
|
113
|
-
it "calls #system_yield_pid" do
|
114
|
-
uc.stub(:mp3_player) {"play"}
|
115
|
-
uc.stub(:ogg_player) {"play"}
|
116
|
-
@song.set_player(uc)
|
117
|
-
@song.should_receive(:system_yield_pid).with("play",File.expand_path(@music_file)).and_return(ps)
|
118
|
-
@song.play_with_player
|
83
|
+
@uc = UserConfig.new
|
84
|
+
@jj = Jukebox.new(@uc, false)
|
85
|
+
@song = Song.new("~/Music/JAZZ/art_tatum.mp3")
|
119
86
|
end
|
120
87
|
|
121
|
-
it "
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
@song.
|
126
|
-
@song.should_receive(:system_yield_pid).with("play",File.expand_path(@music_file)).and_yield(1469)
|
127
|
-
@song.play_with_player
|
128
|
-
@song.playing_pid.should == 1469
|
88
|
+
it "is initially not paused" do
|
89
|
+
@jj.play_song(@song)
|
90
|
+
@song.playing_pid.should be_kind_of(Integer)
|
91
|
+
@jj.skip_song
|
92
|
+
@song.playing_pid.should be_nil
|
129
93
|
end
|
130
94
|
|
131
95
|
end
|
132
96
|
|
133
|
-
describe "#
|
97
|
+
describe "#play_loop" do
|
134
98
|
|
135
99
|
before(:each) do
|
100
|
+
@uc = UserConfig.new
|
101
|
+
#FileUtils.mkdir_p(File.expand_path("~/Music/JAZZ"))
|
136
102
|
@song = Song.new("~/Music/JAZZ/art_tatum.mp3")
|
103
|
+
Jukebox.any_instance.stub(:songs).and_return([@song])
|
104
|
+
Jukebox.any_instance.stub(:next_song).and_return(@song)
|
137
105
|
end
|
138
106
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
it "is not nil after #play" do
|
146
|
-
uc.stub(:mp3_player) {"play"}
|
147
|
-
uc.stub(:ogg_player) {"play"}
|
148
|
-
thread = Thread.new do
|
149
|
-
@song.play(uc)
|
107
|
+
it "should automatically play the first song" do
|
108
|
+
@jj = Jukebox.new(@uc)
|
109
|
+
play_loop_thread = Thread.new do
|
110
|
+
@jj.play_loop
|
150
111
|
end
|
151
112
|
sleep 0.1
|
152
|
-
@
|
113
|
+
@jj.playing?.should be_true
|
114
|
+
play_loop_thread.exit
|
153
115
|
end
|
154
|
-
|
155
116
|
end
|
156
117
|
|
157
118
|
end
|
data/spec/user_config_spec.rb
CHANGED
metadata
CHANGED
@@ -1,114 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jimmy_jukebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Lavin
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
|
17
|
-
none: false
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
|
-
- -
|
18
|
+
- - ">="
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
version: !binary |-
|
21
|
+
MA==
|
25
22
|
none: false
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
|
-
- -
|
25
|
+
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
27
|
+
version: !binary |-
|
28
|
+
MA==
|
29
|
+
none: false
|
30
|
+
prerelease: false
|
31
|
+
type: :development
|
30
32
|
- !ruby/object:Gem::Dependency
|
31
33
|
name: rspec-core
|
32
|
-
|
33
|
-
none: false
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
35
|
requirements:
|
35
|
-
- -
|
36
|
+
- - ">="
|
36
37
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
38
|
-
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
version: !binary |-
|
39
|
+
MA==
|
41
40
|
none: false
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: !binary |-
|
46
|
+
MA==
|
47
|
+
none: false
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
46
50
|
- !ruby/object:Gem::Dependency
|
47
51
|
name: rspec-mocks
|
48
|
-
|
49
|
-
none: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
53
|
requirements:
|
51
|
-
- -
|
54
|
+
- - ">="
|
52
55
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
version: !binary |-
|
57
|
+
MA==
|
57
58
|
none: false
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
58
60
|
requirements:
|
59
|
-
- -
|
61
|
+
- - ">="
|
60
62
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
63
|
+
version: !binary |-
|
64
|
+
MA==
|
65
|
+
none: false
|
66
|
+
prerelease: false
|
67
|
+
type: :development
|
62
68
|
- !ruby/object:Gem::Dependency
|
63
69
|
name: rspec-expectations
|
64
|
-
|
65
|
-
none: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
71
|
requirements:
|
67
|
-
- -
|
72
|
+
- - ">="
|
68
73
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
70
|
-
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
version: !binary |-
|
75
|
+
MA==
|
73
76
|
none: false
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
74
78
|
requirements:
|
75
|
-
- -
|
79
|
+
- - ">="
|
76
80
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
81
|
+
version: !binary |-
|
82
|
+
MA==
|
83
|
+
none: false
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
78
86
|
- !ruby/object:Gem::Dependency
|
79
87
|
name: fakefs
|
80
|
-
|
81
|
-
none: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
89
|
requirements:
|
83
|
-
- -
|
90
|
+
- - ">="
|
84
91
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
-
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
version: !binary |-
|
93
|
+
MA==
|
89
94
|
none: false
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
90
96
|
requirements:
|
91
|
-
- -
|
97
|
+
- - ">="
|
92
98
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
99
|
+
version: !binary |-
|
100
|
+
MA==
|
101
|
+
none: false
|
102
|
+
prerelease: false
|
103
|
+
type: :development
|
94
104
|
- !ruby/object:Gem::Dependency
|
95
105
|
name: fakeweb
|
96
|
-
|
97
|
-
none: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
98
107
|
requirements:
|
99
|
-
- -
|
108
|
+
- - ">="
|
100
109
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
102
|
-
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
version: !binary |-
|
111
|
+
MA==
|
105
112
|
none: false
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
106
114
|
requirements:
|
107
|
-
- -
|
115
|
+
- - ">="
|
108
116
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
-
|
111
|
-
|
117
|
+
version: !binary |-
|
118
|
+
MA==
|
119
|
+
none: false
|
120
|
+
prerelease: false
|
121
|
+
type: :development
|
122
|
+
description: jimmy_jukebox downloads great music and plays random MP3 & OGG songs under a directory (or set of directories)
|
112
123
|
email: james@jameslavin.com
|
113
124
|
executables:
|
114
125
|
- play_jukebox
|
@@ -173,27 +184,28 @@ files:
|
|
173
184
|
- bin/load_jukebox
|
174
185
|
homepage: https://github.com/JamesLavin/jimmy_jukebox
|
175
186
|
licenses: []
|
176
|
-
post_install_message: I really hope you enjoy the great jazz and classical music downloadable
|
177
|
-
using this gem!
|
187
|
+
post_install_message: I really hope you enjoy the great jazz and classical music downloadable using this gem!
|
178
188
|
rdoc_options: []
|
179
189
|
require_paths:
|
180
190
|
- lib
|
181
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
-
none: false
|
183
192
|
requirements:
|
184
|
-
- -
|
193
|
+
- - ">="
|
185
194
|
- !ruby/object:Gem::Version
|
186
|
-
version:
|
187
|
-
|
195
|
+
version: !binary |-
|
196
|
+
MA==
|
188
197
|
none: false
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
199
|
requirements:
|
190
|
-
- -
|
200
|
+
- - ">="
|
191
201
|
- !ruby/object:Gem::Version
|
192
|
-
version:
|
202
|
+
version: !binary |-
|
203
|
+
MA==
|
204
|
+
none: false
|
193
205
|
requirements: []
|
194
206
|
rubyforge_project: jimmy_jukebox
|
195
|
-
rubygems_version: 1.8.
|
196
|
-
signing_key:
|
207
|
+
rubygems_version: 1.8.24
|
208
|
+
signing_key:
|
197
209
|
specification_version: 3
|
198
210
|
summary: plays your MP3 & OGG files and lets you easily download music
|
199
211
|
test_files:
|
@@ -203,4 +215,3 @@ test_files:
|
|
203
215
|
- spec/artists_spec.rb
|
204
216
|
- spec/song_spec.rb
|
205
217
|
- spec/spec_helper.rb
|
206
|
-
has_rdoc:
|