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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8eeae806933bcb3dea47f67abd2261b10425369a
4
- data.tar.gz: 10d0e7ced9a2b5bc8788c84721555250e7e25027
3
+ metadata.gz: c7c189fff206a4195c462ee164b839c8650f2fc7
4
+ data.tar.gz: 70e5a4475b5ff5748d093b78516b952bbc3bea19
5
5
  SHA512:
6
- metadata.gz: 1186d114b2d12ebcd21d08f834b6996db3f1cdb983154cca5a25ef4c1c9db8d7e70f9845e005d0b15aba194b445d448fc02a937d36fa0e20a88ab1ffac55a36b
7
- data.tar.gz: 8cd833433f6e9d48b73efb63114d326ac9752bdebdeddbdaf1ce440347e48cab54bba4d5e993ddba990207569f3ef7a739c5a433841bbdf775031328dbe353ab
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
@@ -1,3 +1,3 @@
1
1
  module Itunes
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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
- Player.should_receive(:execute_script).
16
- with('player/add.scpt', file_name).and_return(new_persistent_id)
17
- Track.should_receive(:find_by).
18
- with(persistent_id: new_persistent_id).
19
- and_return([Track.new(persistent_id: new_persistent_id)])
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
- it 'returns an array of track instance' do
23
- expect(add).to be_a(Track)
24
- expect(add.persistent_id).to eq(new_persistent_id)
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.6
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-21 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake