spinna 0.0.3 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0db8fb458a101ffcb7deebae97f3c721aae130ad
4
- data.tar.gz: 6d9b9b2daf0069039b511e80f5b68ba3f665b927
3
+ metadata.gz: f36240defb27579b06167812df1cf88fabc13db1
4
+ data.tar.gz: 408ef8b78af8699adcd8c40956f9b9fab70bad14
5
5
  SHA512:
6
- metadata.gz: 19b8427129a40acb143947a212498a8e8194880bc8ee99046f21244f09c9df61c8318640a94cda5fc97c885c46ae0524b89cf2667fc4242c1d06af93d40874b3
7
- data.tar.gz: 561ab20d83b2797b94799c22a7f367348b682a4a3712499ed652155e5029fbdff166ba5222da4fdcbe1ad2b9061966d2ca2fc521069e2e013e557cbcbc908fbe
6
+ metadata.gz: 88f5ac62c36e40617f5ec835da4f4809a9904ae4ffb16ba413ef479f3e4002f40a4f23f035979b7088dfe6751e3ef23d9d528313e8647b61ac5a6a370a63963c
7
+ data.tar.gz: 9af06e83001c5f2bead99012b865b0c1ada8e16c06f1b9bf19a5742726281538c7d8f5cb010c2c7655367dca7761c14208db7ff3db6b744f2c45ca4f7834634a
@@ -1,7 +1,7 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## 0.0.3 - 2015-07-06
4
+ ## 0.0.5 - 2015-07-06
5
5
 
6
6
  ### Added
7
7
  - Nothing
@@ -1,3 +1,3 @@
1
1
  module Spinna
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,8 +13,9 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/hydrozen/spinna"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
19
  spec.require_paths = ["lib"]
19
20
 
20
21
  spec.add_development_dependency "bundler", "~> 1.8"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Paul-Hus
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2015-07-06 00:00:00.000000000 Z
12
12
  dependencies:
@@ -153,7 +153,8 @@ dependencies:
153
153
  description: Picks albums from your music collection so you don’t have to.
154
154
  email:
155
155
  - hydrozen@gmail.com
156
- executables: []
156
+ executables:
157
+ - spinna
157
158
  extensions: []
158
159
  extra_rdoc_files: []
159
160
  files:
@@ -173,24 +174,6 @@ files:
173
174
  - lib/spinna/music_library.rb
174
175
  - lib/spinna/picker.rb
175
176
  - lib/spinna/version.rb
176
- - spec/fixtures/data_dir/config.yml
177
- - spec/fixtures/data_dir/config1.yml
178
- - spec/fixtures/data_dir/config2.yml
179
- - spec/fixtures/data_dir/config3.yml
180
- - spec/fixtures/data_dir/config4.yml
181
- - spec/fixtures/data_dir/history.log
182
- - spec/fixtures/data_dir_without_config/.gitkeep
183
- - spec/fixtures/data_dir_without_history/config.yml
184
- - spec/fixtures/source_dir/album1/.gitkeep
185
- - spec/fixtures/source_dir/album2/.gitkeep
186
- - spec/fixtures/source_dir/album3/.gitkeep
187
- - spec/functional/get_spec.rb
188
- - spec/spec_helper.rb
189
- - spec/unit/client_spec.rb
190
- - spec/unit/config_spec.rb
191
- - spec/unit/history_spec.rb
192
- - spec/unit/music_library_spec.rb
193
- - spec/unit/picker_spec.rb
194
177
  - spinna.gemspec
195
178
  homepage: https://github.com/hydrozen/spinna
196
179
  licenses:
@@ -216,22 +199,4 @@ rubygems_version: 2.4.5
216
199
  signing_key:
217
200
  specification_version: 4
218
201
  summary: Randomly picks albums from your music library so you don’t have to.
219
- test_files:
220
- - spec/fixtures/data_dir/config.yml
221
- - spec/fixtures/data_dir/config1.yml
222
- - spec/fixtures/data_dir/config2.yml
223
- - spec/fixtures/data_dir/config3.yml
224
- - spec/fixtures/data_dir/config4.yml
225
- - spec/fixtures/data_dir/history.log
226
- - spec/fixtures/data_dir_without_config/.gitkeep
227
- - spec/fixtures/data_dir_without_history/config.yml
228
- - spec/fixtures/source_dir/album1/.gitkeep
229
- - spec/fixtures/source_dir/album2/.gitkeep
230
- - spec/fixtures/source_dir/album3/.gitkeep
231
- - spec/functional/get_spec.rb
232
- - spec/spec_helper.rb
233
- - spec/unit/client_spec.rb
234
- - spec/unit/config_spec.rb
235
- - spec/unit/history_spec.rb
236
- - spec/unit/music_library_spec.rb
237
- - spec/unit/picker_spec.rb
202
+ test_files: []
@@ -1,3 +0,0 @@
1
- source_dir: '/tmp'
2
- history_size: 10
3
- number_of_picks: 5
@@ -1,2 +0,0 @@
1
- This is not a valid configuration file
2
- so it will blow up.
@@ -1,3 +0,0 @@
1
- # This configuration does not have a source_dir set.
2
- foo: 'meh'
3
- bar: 'blah'
@@ -1,4 +0,0 @@
1
- # This configuration does not set the history_size
2
-
3
- source_dir: '/foo'
4
- number_of_picks: 5
@@ -1,4 +0,0 @@
1
- # This configuration does not set the number of picks.
2
-
3
- source_dir: '/foo'
4
- history_size: 10
@@ -1,3 +0,0 @@
1
- album 1
2
- album 2
3
- album 3
@@ -1,3 +0,0 @@
1
- source_dir: '/tmp'
2
- history_size: 10
3
- number_of_picks: 5
File without changes
File without changes
File without changes
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
- require 'open3'
3
-
4
- describe 'spinna get' do
5
- before do
6
- create_fake_source_dir
7
- create_fake_data_dir
8
- @download_dir = create_tmp_download_dir
9
- ENV['SPINNA_DATA_DIR'] = File.join(Dir.tmpdir, 'spinna')
10
- @wd = Dir.getwd
11
- Dir.chdir(@download_dir)
12
- end
13
-
14
- after do
15
- ENV.delete('SPINNA_DATA_DIR')
16
- Dir.chdir(@wd)
17
- end
18
-
19
- context 'when used without any options' do
20
- before do
21
- Open3.popen3("#{@wd}/exe/spinna get") do |stdin, stdout, stderr, wait_thr|
22
- @stdout = stdout.read
23
- @stderr = stderr.read
24
- @exit_status = wait_thr.value
25
- end
26
- end
27
-
28
- it 'gets the number of albums set in the config from source_dir' do
29
- # It must not have output any errors.
30
- @stderr.must_be_empty
31
-
32
- # Gets the correct number of picks
33
- picks = @stdout.split("\n")
34
- picks.size.must_equal 2
35
-
36
- # Exits with a successful exit code
37
- @exit_status.success?.must_equal true
38
-
39
- # It added the picks to the history log
40
- history = File.read("#{ENV['SPINNA_DATA_DIR']}/history.log")
41
- history.split("\n").size.must_equal 2
42
- end
43
- end
44
-
45
- context 'when given a -n (--number_of_picks) option' do
46
- before do
47
- Open3.popen3("#{@wd}/exe/spinna get -n 3") do |stdin, stdout, stderr, wait_thr|
48
- @stdout = stdout.read
49
- @stderr = stderr.read
50
- @exit_status = wait_thr.value
51
- end
52
- end
53
-
54
- it 'gets that number of albums from source_dir' do
55
- # It must not output any errors
56
- @stderr.must_be_empty
57
-
58
- # Gets the correct number of picks
59
- # picks = @stdout.split("\n")
60
- # picks.size.must_equal 3
61
-
62
- # Exits with a successful exit code
63
- @exit_status.success?.must_equal true
64
-
65
- # It updates the history log
66
- history = File.read("#{ENV['SPINNA_DATA_DIR']}/history.log")
67
- history.split("\n").size.must_equal 3
68
- end
69
- end
70
-
71
- context 'when given a -p (--pattern) option' do
72
- before do
73
- Open3.popen3("#{@wd}/exe/spinna get -p \"album 1\" -n 1") do |stdin, stdout, stderr, wait_thr|
74
- @stdout = stdout.read
75
- @stderr = stderr.read
76
- @exit_status = wait_thr.value
77
- end
78
- end
79
-
80
- it 'picks only albums that match the given pattern' do
81
- # It must not output any errors
82
- @stderr.must_be_empty
83
-
84
- # Gets the correct number of picks
85
- picks = @stdout.split("\n")
86
- picks.size.must_equal 1
87
-
88
- # The pick should match the given pattern
89
- picks.first.must_equal "Copying album 1..."
90
-
91
- # Exits with a successful exit code
92
- @exit_status.success?.must_equal true
93
-
94
- # It updates the history log
95
- history = File.read("#{ENV['SPINNA_DATA_DIR']}/history.log")
96
- history.split("\n").size.must_equal 1
97
- end
98
- end
99
- end
@@ -1,51 +0,0 @@
1
- # Code coverage
2
- require 'simplecov'
3
- require 'coveralls'
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
- SimpleCov.start
10
-
11
- require 'minitest/autorun'
12
- require 'minitest/spec'
13
- require 'minitest/pride'
14
- require 'minitest-spec-context'
15
- require 'mocha/mini_test'
16
- require 'minitest/reporters'
17
- require 'tmpdir'
18
- require 'fileutils'
19
-
20
- Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(:color => true)
21
-
22
- def create_fake_source_dir
23
- path = File.join(Dir.tmpdir, 'spinna_source_dir')
24
- FileUtils.rm_rf(path)
25
- FileUtils.mkdir(path)
26
- 5.times do |i|
27
- FileUtils.mkdir(File.join(path, "album #{i+1}"))
28
- end
29
- end
30
-
31
- def create_fake_data_dir
32
- path = File.join(Dir.tmpdir, 'spinna')
33
- FileUtils.rm_rf(path)
34
- FileUtils.mkdir(path)
35
- config = {
36
- 'source_dir' => File.join(Dir.tmpdir, 'spinna_source_dir'),
37
- 'history_size' => 4,
38
- 'number_of_picks' => 2
39
- }
40
- config_path = File.join(path, 'config.yml')
41
- File.open(config_path, 'w+') do |f|
42
- f.write config.to_yaml
43
- end
44
- end
45
-
46
- def create_tmp_download_dir
47
- path = File.join(Dir.tmpdir, 'spinna_download_dir')
48
- FileUtils.rm_rf(path)
49
- FileUtils.mkdir(path)
50
- path
51
- end
@@ -1,115 +0,0 @@
1
- require 'spec_helper'
2
- require 'spinna/client'
3
-
4
- describe Spinna::Client do
5
- describe '.new' do
6
- let(:config) { stub() }
7
- let(:history) { stub() }
8
- let(:picker) { stub() }
9
- let(:music_library) { stub() }
10
-
11
- before do
12
- Spinna::Config.expects(:new).returns(config)
13
- Spinna::History.expects(:new).returns(history)
14
- Spinna::MusicLibrary.expects(:new).returns(music_library)
15
- end
16
-
17
- subject { Spinna::Client.new }
18
-
19
- it 'assigns a config object to an instance variable' do
20
- subject.config.must_equal config
21
- end
22
-
23
- it 'assigns a history object to an instance variable' do
24
- subject.history.must_equal history
25
- end
26
-
27
- it 'assigns a music_library object to an instance variable' do
28
- subject.library.must_equal music_library
29
- end
30
- end
31
-
32
- describe '#get' do
33
- let(:default_number_of_picks) { 2 }
34
- let(:picker) { stub }
35
- let(:music_library) { stub }
36
- let(:picks) { ['album 1', 'album 2'] }
37
-
38
- before do
39
- Spinna::Config.stubs(:new).returns(config)
40
- Spinna::History.stubs(:new).returns(history)
41
- Spinna::Picker.stubs(:new).returns(picker)
42
- Spinna::MusicLibrary.stubs(:new).returns(music_library)
43
- end
44
-
45
- context 'when called without arguments' do
46
- let(:config) do
47
- stub(
48
- :number_of_picks => default_number_of_picks,
49
- :source_dir => File.expand_path("../../fixtures/source_dir", __FILE__)
50
- )
51
- end
52
- let(:history) { stub }
53
- let(:picker) do
54
- picker = stub
55
- picker.stubs(:pick).returns(picks)
56
- picker
57
- end
58
-
59
- subject { Spinna::Client.new }
60
-
61
- it 'requests the default number of picks from the picker' do
62
- picker.expects(:pick).with(default_number_of_picks, nil)
63
- subject.get
64
- end
65
-
66
- it 'returns the picks from the picker' do
67
- subject.get.must_equal picks
68
- end
69
- end
70
-
71
- context 'when given a number_of_picks option' do
72
- let(:config) do
73
- stub(
74
- :number_of_picks => default_number_of_picks,
75
- :source_dir => File.expand_path("../../fixtures/source_dir", __FILE__)
76
- )
77
- end
78
- let(:history) { stub }
79
- let(:picker) { stub(:pick => [picks.first]) }
80
-
81
- subject { Spinna::Client.new }
82
-
83
- it 'requests the given number of picks from the picker' do
84
- picker.expects(:pick).with(1, nil).returns([picks.first])
85
- subject.get(:number_of_picks => 1)
86
- end
87
-
88
- it 'returns the picks from the picker' do
89
- subject.get(:number_of_picks => 1).must_equal [picks.first]
90
- end
91
- end
92
-
93
- context 'when given a pattern' do
94
- let(:config) do
95
- stub(
96
- :number_of_picks => default_number_of_picks,
97
- :source_dir => File.expand_path("../../fixtures/source_dir", __FILE__)
98
- )
99
- end
100
- let(:history) { stub }
101
- let(:picker) { stub(:pick => [picks.first]) }
102
-
103
- subject { Spinna::Client.new }
104
-
105
- it 'requests the picks from the picker with the correct options' do
106
- picker.expects(:pick).with(1, 'foo').returns([picks.first])
107
- subject.get(:number_of_picks => 1, :pattern => 'foo')
108
- end
109
-
110
- it 'returns the picks from the picker' do
111
- subject.get(:number_of_picks => 1, :pattern => 'foo').must_equal [picks.first]
112
- end
113
- end
114
- end
115
- end
@@ -1,147 +0,0 @@
1
- require 'spec_helper'
2
- require 'spinna/config'
3
-
4
- describe Spinna::Config do
5
- describe 'DEFAULT_HISTORY_SIZE' do
6
- it 'is set to 50' do
7
- Spinna::Config::DEFAULT_HISTORY_SIZE.must_equal 50
8
- end
9
- end
10
-
11
- describe 'DEFAULT_NUMBER_OF_PICKS' do
12
- it 'is set to 10' do
13
- Spinna::Config::DEFAULT_NUMBER_OF_PICKS.must_equal 10
14
- end
15
- end
16
-
17
- describe '#new' do
18
- let(:data_dir) { File.expand_path("../../fixtures/data_dir", __FILE__) }
19
- let(:non_existing_data_dir) { File.join(Dir.home, '.nonexisting') }
20
- let(:data_dir_without_config) { File.expand_path("../../fixtures/data_dir_without_config", __FILE__) }
21
-
22
- context 'when the data_dir does not exist' do
23
- let(:opts) { {:data_dir => non_existing_data_dir} }
24
-
25
- it 'creates it and raises error because the configuration file is missing' do
26
- Dir.expects(:mkdir).with(opts[:data_dir], 0700)
27
- proc { Spinna::Config.new(opts) }.must_raise Spinna::ConfigFileNotFoundError
28
- end
29
- end
30
-
31
- context 'when the configuration file does not exist' do
32
- let(:opts) { {:data_dir => data_dir_without_config} }
33
-
34
- subject do
35
- Spinna::Config.new(opts)
36
- end
37
-
38
- before do
39
- Dir.stubs(:mkdir)
40
- end
41
-
42
- it 'throws an exception' do
43
- err = proc { subject }.must_raise Spinna::ConfigFileNotFoundError
44
- err.message.must_match %r{Could not find the configuration file.}
45
- end
46
- end
47
-
48
- context 'when the configuration file is not valid json' do
49
- before do
50
- YAML.stubs(:load_file).returns("&&&foo")
51
- end
52
-
53
- it 'throws an exception' do
54
- opts = {
55
- :data_dir => data_dir
56
- }
57
- err = proc { Spinna::Config.new(opts) }.must_raise Spinna::InvalidConfigFileError
58
- err.message.must_match %r{Could not parse the configuration file.}
59
- end
60
- end
61
-
62
- context 'when the source_dir config parameter is missing' do
63
- before do
64
- YAML.stubs(:load_file).returns({'foo' => 'bar'})
65
- end
66
-
67
- it 'throws an exception' do
68
- opts = {:data_dir => data_dir}
69
- err = proc { Spinna::Config.new(opts) }.must_raise Spinna::InvalidConfigFileError
70
- err.message.must_match %r{You must set a source_dir in your configuration file.}
71
- end
72
- end
73
-
74
- context 'when the source_dir does not actually exist on the filesystem' do
75
- before do
76
- YAML.stubs(:load_file).returns({
77
- 'source_dir' => '/this/dir/does/not/exist'
78
- })
79
- end
80
-
81
- it 'throws an exception' do
82
- opts = {
83
- :data_dir => data_dir
84
- }
85
- proc { Spinna::Config.new(opts) }.must_raise Spinna::InvalidSourceDirError
86
- end
87
- end
88
-
89
- context 'when the configuration is valid and all parameters were provided' do
90
- it 'sets the source_dir' do
91
- opts = {
92
- :data_dir => data_dir,
93
- :config_file => 'config.yml'
94
- }
95
- config = Spinna::Config.new(opts)
96
- config.source_dir.must_equal '/tmp'
97
- end
98
-
99
- it 'sets the history_size' do
100
- opts = {
101
- :data_dir => data_dir,
102
- :config_file => 'config.yml'
103
- }
104
- config = Spinna::Config.new(opts)
105
- config.history_size.must_equal 10
106
- end
107
-
108
- it 'sets the number_of_picks' do
109
- opts = {
110
- :data_dir => data_dir,
111
- :config_file => 'config.yml'
112
- }
113
- config = Spinna::Config.new(opts)
114
- config.number_of_picks.must_equal 5
115
- end
116
- end
117
-
118
- context 'when the configuration is valid but the history_size was not provided' do
119
- let(:opts) { {:data_dir => data_dir} }
120
-
121
- subject { Spinna::Config.new(opts) }
122
-
123
- before do
124
- YAML.stubs(:load_file).returns({'source_dir' => '/tmp'})
125
- end
126
-
127
- it 'uses the default value' do
128
- subject.history_size.must_equal Spinna::Config::DEFAULT_HISTORY_SIZE
129
- end
130
- end
131
-
132
- context 'when the configuration is valid but the number_of_picks was not provided' do
133
- let(:opts) { {:data_dir => data_dir} }
134
-
135
- subject { Spinna::Config.new(opts) }
136
-
137
- before do
138
- YAML.stubs(:load_file).returns({'source_dir' => '/tmp'})
139
- end
140
-
141
- it 'uses the default value' do
142
- subject.number_of_picks.must_equal Spinna::Config::DEFAULT_NUMBER_OF_PICKS
143
- end
144
- end
145
- end
146
- end
147
-
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
- require 'spinna/history'
3
- require 'spinna/config'
4
-
5
- describe Spinna::History do
6
- let(:data_dir) { File.expand_path("../../fixtures/data_dir", __FILE__) }
7
- let(:data_dir_without_history) { File.expand_path("../../fixtures/data_dir_without_history", __FILE__) }
8
- let(:opts) { {:data_dir => data_dir} }
9
- let(:config) { stub(:data_dir => data_dir, :history_size => 10) }
10
- let(:history_size) { 3 }
11
-
12
- describe '#new' do
13
- subject { Spinna::History.new(config) }
14
-
15
- it 'saves the passed in config in an instance variable' do
16
- subject.config.must_equal config
17
- end
18
-
19
- context 'when the history log file exists' do
20
- it 'reads the history log from the filesystem' do
21
- subject.log.size.must_equal history_size
22
- end
23
- end
24
-
25
- context 'when the history log does not exist' do
26
- let(:config) { stub(:data_dir => data_dir_without_history, :history_size => 10) }
27
-
28
- subject { Spinna::History.new(config) }
29
-
30
- it 'does not read the history log from the filesystem' do
31
- File.expects(:read).never
32
- subject
33
- end
34
-
35
- it 'inits the log as an empty array' do
36
- subject.log.size.must_equal 0
37
- end
38
- end
39
- end
40
-
41
- describe '#append' do
42
- subject { Spinna::History.new(config) }
43
-
44
- context 'when the album is not in the history' do
45
- it 'appends the album at the end of the history log' do
46
- size_before_append = subject.log.size
47
- subject.append('album 11')
48
- subject.log.size.must_equal size_before_append + 1
49
- subject.log.last.must_equal 'album 11'
50
- end
51
- end
52
-
53
- context 'when the album is already in the history' do
54
- it 'does nothing' do
55
- size_before_append = subject.log.size
56
- subject.append('album 1')
57
- subject.log.size.must_equal size_before_append
58
- end
59
- end
60
-
61
- context 'when the history log is full' do
62
- let(:config) { stub(:data_dir => data_dir, :history_size => 3) }
63
- it 'removes the old albums from the log to make room for the new albums' do
64
- subject.append('album 4')
65
- subject.log.size.must_equal 3
66
- subject.log.first.must_equal 'album 2'
67
- subject.log.last.must_equal 'album 4'
68
- end
69
- end
70
- end
71
-
72
- describe '#include?' do
73
- subject { Spinna::History.new(config) }
74
-
75
- context 'when the album is in the log' do
76
- it 'returns true' do
77
- subject.include?('album 1').must_equal true
78
- end
79
- end
80
-
81
- context 'when the album is not in the log' do
82
- it 'returns false' do
83
- subject.include?('album 99').must_equal false
84
- end
85
- end
86
- end
87
-
88
- describe '#save' do
89
- # This is used to fake writing the history.log file.
90
- let(:history_log) { StringIO.new('', 'w+') }
91
-
92
- subject { Spinna::History.new(config) }
93
- it 'saves the log to the filesystem' do
94
- File.expects(:open).with(subject.history_path, 'w+').yields(history_log)
95
- subject.save
96
- history_log.string.must_equal "album 1\nalbum 2\nalbum 3\n"
97
- end
98
- end
99
- end
100
-
@@ -1,59 +0,0 @@
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
@@ -1,250 +0,0 @@
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