itunes-client 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itunes/player.rb +6 -0
- data/lib/itunes/version.rb +1 -1
- data/spec/itunes/player_spec.rb +35 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c189fff206a4195c462ee164b839c8650f2fc7
|
4
|
+
data.tar.gz: 70e5a4475b5ff5748d093b78516b952bbc3bea19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b2e8948ff6cf54e8b6c4165ed9292293be30133c32ce3dc8f33fefc0f5c82141b914a5faae9461a4845936f281e8aadc1e9c4d8a2eaa2037c816b3354f1a5fe
|
7
|
+
data.tar.gz: c55a3960ba159490b62fca65c482cee299b1f7cd2125ad31c06604cec368cbf880b6861815de61f34208629d9b484b030fc02778a921cb09facbe838e1d77e2d
|
data/lib/itunes/player.rb
CHANGED
@@ -8,8 +8,14 @@ module Itunes
|
|
8
8
|
class Player
|
9
9
|
extend Itunes::Util::Executor
|
10
10
|
|
11
|
+
class FileNotFoundError < StandardError; end;
|
12
|
+
class EmptyFileError < StandardError; end;
|
13
|
+
|
11
14
|
class << self
|
12
15
|
def add(file_path)
|
16
|
+
raise FileNotFoundError unless File.exist?(file_path)
|
17
|
+
raise EmptyFileError unless File.open(file_path).size > 0
|
18
|
+
|
13
19
|
persistent_id = execute_script("#{script_dir}/add.scpt", file_path)
|
14
20
|
Track.find_by(persistent_id: persistent_id).first
|
15
21
|
end
|
data/lib/itunes/version.rb
CHANGED
data/spec/itunes/player_spec.rb
CHANGED
@@ -8,20 +8,46 @@ describe Player do
|
|
8
8
|
describe '.add' do
|
9
9
|
subject(:add) { Player.add(file_name) }
|
10
10
|
|
11
|
-
let(:file_name) { 'foo.wav' }
|
11
|
+
let(:file_name) { '/tmp/foo.wav' }
|
12
12
|
let(:new_persistent_id) { 'foo' }
|
13
13
|
|
14
14
|
before do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
FileUtils.rm_f(file_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when existent file is given' do
|
19
|
+
before do
|
20
|
+
`echo "foo" > #{file_name}`
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
Player.should_receive(:execute_script).
|
25
|
+
with('player/add.scpt', file_name).and_return(new_persistent_id)
|
26
|
+
Track.should_receive(:find_by).
|
27
|
+
with(persistent_id: new_persistent_id).
|
28
|
+
and_return([Track.new(persistent_id: new_persistent_id)])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns an array of track instance', fakefs: true do
|
32
|
+
expect(add).to be_a(Track)
|
33
|
+
expect(add.persistent_id).to eq(new_persistent_id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when zero byte file is given' do
|
38
|
+
before do
|
39
|
+
FileUtils.touch(file_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises an EmptyFileError', fakefs: true do
|
43
|
+
expect { add }.to raise_error(Itunes::Player::EmptyFileError)
|
44
|
+
end
|
20
45
|
end
|
21
46
|
|
22
|
-
|
23
|
-
|
24
|
-
|
47
|
+
context 'when non existent file is given' do
|
48
|
+
it 'raises a FileNotFoundrror', fakefs: true do
|
49
|
+
expect { add }.to raise_error(Itunes::Player::FileNotFoundError)
|
50
|
+
end
|
25
51
|
end
|
26
52
|
end
|
27
53
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryo katsuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|