spinna 0.0.1

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.
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'spinna/music_library'
3
+
4
+ describe Spinna::MusicLibrary do
5
+ describe '.new' do
6
+ let(:config) { stub }
7
+ let(:history) { stub }
8
+
9
+ subject { Spinna::MusicLibrary.new(config, history) }
10
+
11
+ it 'assigns the config to an instance variable' do
12
+ subject.instance_variable_get(:@config).must_equal config
13
+ end
14
+
15
+ it 'assigns the history to an instance variable' do
16
+ subject.instance_variable_get(:@history).must_equal history
17
+ end
18
+ end
19
+
20
+ describe '.pickable_albums' do
21
+ let(:config) { stub_everything }
22
+ let(:history) { stub_everything }
23
+
24
+ before do
25
+ Dir.stubs(:entries).returns(['.', '..', '.hidden', 'album 1', 'album 2', 'album 3'])
26
+ history.stubs(:log).returns(['album 1'])
27
+ end
28
+
29
+ subject { Spinna::MusicLibrary.new(config, history) }
30
+
31
+ context 'when not given a pattern and some albums are pickable' do
32
+ it 'returns those albums as an array' do
33
+ subject.pickable_albums.must_equal ['album 2', 'album 3']
34
+ end
35
+ end
36
+
37
+ context 'when not given a pattern and no albums are pickable' do
38
+ before do
39
+ history.stubs(:log).returns(['album 1', 'album 2', 'album 3'])
40
+ end
41
+
42
+ it 'returns an empty array' do
43
+ subject.pickable_albums.must_equal []
44
+ end
45
+ end
46
+
47
+ context 'when given a pattern and some albums match that pattern' do
48
+ it 'returns those albums as an array' do
49
+ subject.pickable_albums('album 2').must_equal ['album 2']
50
+ end
51
+ end
52
+
53
+ context 'when given a pattern and no albums match' do
54
+ it 'returns an empty array' do
55
+ subject.pickable_albums('foobar').must_equal []
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,250 @@
1
+ require 'spec_helper'
2
+ require 'spinna/picker'
3
+
4
+ describe Spinna::Picker do
5
+ describe '.new' do
6
+ let(:config) { stub }
7
+ let(:history) { stub }
8
+ let(:library) { stub }
9
+
10
+ subject do
11
+ Spinna::Picker.new(config, history, library)
12
+ end
13
+
14
+ it 'assigns the config to an instance variable' do
15
+ subject.instance_variable_get(:@config).must_equal config
16
+ end
17
+
18
+ it 'assigns the history to an instance variable' do
19
+ subject.instance_variable_get(:@history).must_equal history
20
+ end
21
+
22
+ it 'assigns the library to an instance variable' do
23
+ subject.instance_variable_get(:@library).must_equal library
24
+ end
25
+ end
26
+
27
+ describe '#pick' do
28
+ let(:source_dir) { File.expand_path("../../fixtures/source_dir", __FILE__) }
29
+ let(:config) { stub(:source_dir => source_dir) }
30
+ let(:history) do
31
+ history = stub(
32
+ :include? => false,
33
+ :log => [],
34
+ :append => nil,
35
+ :save => nil
36
+ )
37
+ end
38
+ let(:library) { stub }
39
+
40
+ before do
41
+ FileUtils.stubs(:cp_r)
42
+ end
43
+
44
+ context 'when not given a number_of_picks parameter' do
45
+ subject do
46
+ picker = Spinna::Picker.new(config, history, library)
47
+ end
48
+
49
+ it 'raises an error' do
50
+ proc { subject.pick }.must_raise ArgumentError
51
+ end
52
+ end
53
+
54
+ context 'when given a number_of_picks but no pattern' do
55
+ context 'and there are more albums to choose from' do
56
+ let(:albums) { ['album 1', 'album 2', 'album 3'] }
57
+ let(:library) { stub(:pickable_albums => albums) }
58
+
59
+ subject do
60
+ Spinna::Picker.new(config, history, library).pick(1)
61
+ end
62
+
63
+ before do
64
+ albums.expects(:sample).with(1).returns(['album 1'])
65
+ end
66
+
67
+ it 'request the pickable albums from the library' do
68
+ library
69
+ .expects(:pickable_albums)
70
+ .with(nil)
71
+ .returns(albums)
72
+ capture_io { subject }
73
+ end
74
+
75
+ it 'returns that number of picks in an array' do
76
+ capture_io do
77
+ subject.size.must_equal 1
78
+ end
79
+ end
80
+
81
+ it 'copies the picks' do
82
+ FileUtils.expects(:cp_r).once
83
+ capture_io { subject }
84
+ end
85
+
86
+ it 'adds the picks to the history' do
87
+ history.expects(:append).once
88
+ capture_io { subject }
89
+ end
90
+
91
+ it 'saves the history' do
92
+ history.expects(:save).once
93
+ capture_io do
94
+ subject
95
+ end
96
+ end
97
+
98
+ it 'outputs the picks to the screen' do
99
+ out, err = capture_io do
100
+ subject
101
+ end
102
+ out.must_match %r{Copying album 1\.\.\.}
103
+ end
104
+ end
105
+
106
+ context 'and there are not enough albums to choose from' do
107
+ let(:albums) { ['album 1', 'album 2', 'album 3'] }
108
+ let(:library) { stub(:pickable_albums => albums) }
109
+
110
+ subject do
111
+ Spinna::Picker.new(config, history, library).pick(5)
112
+ end
113
+
114
+ it 'request the pickable albums from the library' do
115
+ library
116
+ .expects(:pickable_albums)
117
+ .with(nil)
118
+ .returns(albums)
119
+ capture_io { subject }
120
+ end
121
+
122
+ it 'returns all the remaining albums' do
123
+ capture_io do
124
+ subject.size.must_equal 3
125
+ end
126
+ end
127
+
128
+ it 'adds the picks to the history' do
129
+ history.expects(:append).times(3)
130
+ capture_io { subject }
131
+ end
132
+
133
+ it 'saves the history' do
134
+ history.expects(:save).once
135
+ capture_io { subject }
136
+ end
137
+
138
+ it 'outputs the picks on the screen' do
139
+ out, err = capture_io do
140
+ subject
141
+ end
142
+ lines = out.split("\n")
143
+ lines.size.must_equal 3
144
+ lines.each do |line|
145
+ line.must_match %r{Copying album [1-3]\.\.\.}
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ context 'when given a number_of_picks and a pattern' do
152
+ context 'and there are more albums that match than requested' do
153
+ let(:albums) do
154
+ albums = ['album 1', 'album 2', 'album 3']
155
+ albums.stubs(:sample).returns(picks)
156
+ albums
157
+ end
158
+ let(:picks) { ['album 1', 'album 2'] }
159
+ let(:library) { stub(:pickable_albums => albums) }
160
+
161
+ subject do
162
+ Spinna::Picker.new(config, history, library).pick(2, 'album')
163
+ end
164
+
165
+ it 'requests the pickable albums from the library' do
166
+ library
167
+ .expects(:pickable_albums)
168
+ .with('album')
169
+ .returns(albums)
170
+ capture_io { subject }
171
+ end
172
+
173
+ it 'randomly selects albums from the available ones' do
174
+ albums.expects(:sample).with(2).returns(picks)
175
+ capture_io { subject }
176
+ end
177
+
178
+ it 'returns the albums that match' do
179
+ capture_io do
180
+ subject.must_equal picks
181
+ end
182
+ end
183
+
184
+ it 'adds the picks to the history' do
185
+ history.expects(:append).times(picks.size)
186
+ capture_io { subject }
187
+ end
188
+
189
+ it 'saves the history' do
190
+ history.expects(:save).once
191
+ capture_io { subject }
192
+ end
193
+
194
+ it 'outputs the picks on the screen' do
195
+ out, err = capture_io do
196
+ subject
197
+ end
198
+ lines = out.split("\n")
199
+ lines.size.must_equal picks.size
200
+ lines.each do |line|
201
+ line.must_match %r{Copying album [1-3]\.\.\.}
202
+ end
203
+ end
204
+ end
205
+
206
+ context 'and there are not enough albums to choose from' do
207
+ let(:albums) { ['album 1', 'album 2', 'album 3'] }
208
+ let(:library) { stub(:pickable_albums => albums) }
209
+ let(:picks) { ['album 1', 'album 2', 'album 3'] }
210
+
211
+ subject do
212
+ Spinna::Picker.new(config, history, library).pick(5, 'album')
213
+ end
214
+
215
+ it 'requests the pickable_albums from the library' do
216
+ library
217
+ .expects(:pickable_albums)
218
+ .with('album')
219
+ .returns(albums)
220
+ capture_io { subject }
221
+ end
222
+
223
+ it 'returns all the pickable albums that match the pattern' do
224
+ capture_io { subject.must_equal picks }
225
+ end
226
+
227
+ it 'adds the picks to the history' do
228
+ history.expects(:append).times(picks.size)
229
+ capture_io { subject }
230
+ end
231
+
232
+ it 'saves the history' do
233
+ history.expects(:save).once
234
+ capture_io { subject }
235
+ end
236
+
237
+ it 'outputs the picks on the screen' do
238
+ out, err = capture_io do
239
+ subject
240
+ end
241
+ lines = out.split("\n")
242
+ lines.size.must_equal picks.size
243
+ lines.each do |line|
244
+ line.must_match %r{Copying album [1-3]\.\.\.}
245
+ end
246
+ end
247
+ end
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spinna/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spinna"
8
+ spec.version = Spinna::VERSION
9
+ spec.authors = ["Patrick Paul-Hus"]
10
+ spec.email = ["hydrozen@gmail.com"]
11
+ spec.summary = %q{Randomly picks albums from your music library to keep things fresh.}
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/hydrozen/spinna"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.3"
24
+ spec.add_development_dependency "minitest-spec-context", "~> 0.0"
25
+ spec.add_development_dependency "pry", "~> 0.10"
26
+ spec.add_development_dependency "mocha", "~> 1.1"
27
+ spec.add_development_dependency "minitest-reporters", "~> 1.0"
28
+
29
+ spec.add_runtime_dependency "thor", "~> 0.19"
30
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spinna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Paul-Hus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-spec-context
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.19'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.19'
125
+ description: ''
126
+ email:
127
+ - hydrozen@gmail.com
128
+ executables:
129
+ - spinna
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/spinna
140
+ - lib/spinna.rb
141
+ - lib/spinna/cli.rb
142
+ - lib/spinna/client.rb
143
+ - lib/spinna/config.rb
144
+ - lib/spinna/history.rb
145
+ - lib/spinna/music_library.rb
146
+ - lib/spinna/picker.rb
147
+ - lib/spinna/version.rb
148
+ - spec/fixtures/data_dir/config.yml
149
+ - spec/fixtures/data_dir/config1.yml
150
+ - spec/fixtures/data_dir/config2.yml
151
+ - spec/fixtures/data_dir/config3.yml
152
+ - spec/fixtures/data_dir/config4.yml
153
+ - spec/fixtures/data_dir/history.log
154
+ - spec/fixtures/source_dir/album1/.gitkeep
155
+ - spec/fixtures/source_dir/album2/.gitkeep
156
+ - spec/fixtures/source_dir/album3/.gitkeep
157
+ - spec/functional/get_spec.rb
158
+ - spec/spec_helper.rb
159
+ - spec/unit/client_spec.rb
160
+ - spec/unit/config_spec.rb
161
+ - spec/unit/history_spec.rb
162
+ - spec/unit/music_library_spec.rb
163
+ - spec/unit/picker_spec.rb
164
+ - spinna.gemspec
165
+ homepage: https://github.com/hydrozen/spinna
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.2.2
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Randomly picks albums from your music library to keep things fresh.
189
+ test_files:
190
+ - spec/fixtures/data_dir/config.yml
191
+ - spec/fixtures/data_dir/config1.yml
192
+ - spec/fixtures/data_dir/config2.yml
193
+ - spec/fixtures/data_dir/config3.yml
194
+ - spec/fixtures/data_dir/config4.yml
195
+ - spec/fixtures/data_dir/history.log
196
+ - spec/fixtures/source_dir/album1/.gitkeep
197
+ - spec/fixtures/source_dir/album2/.gitkeep
198
+ - spec/fixtures/source_dir/album3/.gitkeep
199
+ - spec/functional/get_spec.rb
200
+ - spec/spec_helper.rb
201
+ - spec/unit/client_spec.rb
202
+ - spec/unit/config_spec.rb
203
+ - spec/unit/history_spec.rb
204
+ - spec/unit/music_library_spec.rb
205
+ - spec/unit/picker_spec.rb
206
+ has_rdoc: