vtools 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/INSTALL +0 -0
  2. data/LICENSE +20 -0
  3. data/README.md +131 -0
  4. data/Rakefile +29 -0
  5. data/bin/vtools +22 -0
  6. data/doc/CONFIG.md +36 -0
  7. data/doc/HOOKS.md +37 -0
  8. data/doc/LIB_EXAMPLE.md +109 -0
  9. data/extconf.rb +7 -0
  10. data/lib/vtools.rb +79 -0
  11. data/lib/vtools/config.rb +91 -0
  12. data/lib/vtools/convert_options.rb +155 -0
  13. data/lib/vtools/converter.rb +98 -0
  14. data/lib/vtools/errors.rb +21 -0
  15. data/lib/vtools/handler.rb +43 -0
  16. data/lib/vtools/harvester.rb +71 -0
  17. data/lib/vtools/job.rb +48 -0
  18. data/lib/vtools/options.rb +101 -0
  19. data/lib/vtools/shared_methods.rb +131 -0
  20. data/lib/vtools/storage.rb +67 -0
  21. data/lib/vtools/thumbnailer.rb +93 -0
  22. data/lib/vtools/thumbs_options.rb +80 -0
  23. data/lib/vtools/version.rb +6 -0
  24. data/lib/vtools/version.rb~ +4 -0
  25. data/lib/vtools/video.rb +158 -0
  26. data/setup.rb +1585 -0
  27. data/spec/config_spec.rb +142 -0
  28. data/spec/convert_options_spec.rb +284 -0
  29. data/spec/converter_spec.rb +167 -0
  30. data/spec/errors_spec.rb +39 -0
  31. data/spec/fixtures/outputs/file_with_iso-8859-1.txt +35 -0
  32. data/spec/fixtures/outputs/file_with_no_audio.txt +18 -0
  33. data/spec/fixtures/outputs/file_with_non_supported_audio.txt +29 -0
  34. data/spec/fixtures/outputs/file_with_start_value.txt +19 -0
  35. data/spec/fixtures/outputs/file_with_surround_sound.txt +19 -0
  36. data/spec/handler_spec.rb +81 -0
  37. data/spec/harvester_spec.rb +189 -0
  38. data/spec/job_spec.rb +130 -0
  39. data/spec/options_spec.rb +52 -0
  40. data/spec/shared_methods_spec.rb +351 -0
  41. data/spec/spec_helper.rb +20 -0
  42. data/spec/storage_spec.rb +106 -0
  43. data/spec/thumbnailer_spec.rb +178 -0
  44. data/spec/thumbs_options_spec.rb +159 -0
  45. data/spec/video_spec.rb +274 -0
  46. data/vtools.gemspec +29 -0
  47. metadata +177 -0
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+ require "errors"
3
+
4
+ #ConfigError
5
+ #FileError
6
+ #FormatError
7
+ #ProcessError
8
+
9
+ describe VTools do
10
+
11
+ # specs
12
+ context "#ConfigError" do
13
+
14
+ it "valid exception tree" do
15
+ expect { raise VTools::ConfigError }.to raise_error ArgumentError
16
+ end
17
+ end
18
+
19
+ context "#FileError" do
20
+
21
+ it "valid exception tree" do
22
+ expect { raise VTools::FileError }.to raise_error Errno::ENOENT
23
+ end
24
+ end
25
+
26
+ context "#FormatError" do
27
+
28
+ it "valid exception tree" do
29
+ expect { raise VTools::FormatError }.to raise_error IOError
30
+ end
31
+ end
32
+
33
+ context "#ProcessError" do
34
+
35
+ it "valid exception tree" do
36
+ expect { raise VTools::ProcessError }.to raise_error IOError
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
2
+ built on Nov 18 2010 13:51:50 with gcc 4.2.1 (Apple Inc. build 5664)
3
+ configuration: --disable-debug --prefix=/usr/local/Cellar/ffmpeg/0.6.1 --enable-shared --enable-pthreads --enable-nonfree --enable-gpl --disable-indev=jack --enable-libx264 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid
4
+ libavutil 50.15. 1 / 50.15. 1
5
+ libavcodec 52.72. 2 / 52.72. 2
6
+ libavformat 52.64. 2 / 52.64. 2
7
+ libavdevice 52. 2. 0 / 52. 2. 0
8
+ libswscale 0.11. 0 / 0.11. 0
9
+ [mov,mp4,m4a,3gp,3g2,mj2 @ 0x10180b000]multiple edit list entries, a/v desync might occur, patch welcome
10
+ [mov,mp4,m4a,3gp,3g2,mj2 @ 0x10180b000]max_analyze_duration reached
11
+
12
+ Seems stream 0 codec frame rate differs from container frame rate: 5000.00 (5000/1) -> 25.00 (25/1)
13
+ Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'spec/fixtures/movies/rails3upgrade.mov':
14
+ Metadata:
15
+ major_brand : qt
16
+ minor_version : 537199360
17
+ compatible_brands: qt
18
+ Duration: 00:24:42.61, start: 0.000000, bitrate: 546 kb/s
19
+ Chapter #0.0: start 142.240000, end 532.679600
20
+ Metadata:
21
+ title : ��R
22
+ Chapter #0.1: start 532.679600, end 788.119600
23
+ Metadata:
24
+ title : ��r
25
+ Chapter #0.2: start 788.119600, end 1160.159600
26
+ Metadata:
27
+ title : ��b
28
+ Chapter #0.3: start 1160.159600, end 1340.359200
29
+ Metadata:
30
+ title : ��A
31
+ Stream #0.0(eng): Video: h264, yuv420p, 1000x600, 480 kb/s, 25 fps, 25 tbr, 2500 tbn, 5k tbc
32
+ Stream #0.1(eng): Data: tmcd / 0x64636D74
33
+ Stream #0.2(eng): Audio: aac, 44100 Hz, mono, s16, 64 kb/s
34
+ Stream #0.3(eng): Subtitle: text / 0x74786574, 0 kb/s
35
+ At least one output file must be specified
@@ -0,0 +1,18 @@
1
+ FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
2
+ built on Nov 18 2010 13:51:50 with gcc 4.2.1 (Apple Inc. build 5664)
3
+ configuration: --disable-debug --prefix=/usr/local/Cellar/ffmpeg/0.6.1 --enable-shared --enable-pthreads --enable-nonfree --enable-gpl --disable-indev=jack --enable-libx264 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid
4
+ libavutil 50.15. 1 / 50.15. 1
5
+ libavcodec 52.72. 2 / 52.72. 2
6
+ libavformat 52.64. 2 / 52.64. 2
7
+ libavdevice 52. 2. 0 / 52. 2. 0
8
+ libswscale 0.11. 0 / 0.11. 0
9
+
10
+ Seems stream 0 codec frame rate differs from container frame rate: 2500.00 (2500/1) -> 25.00 (25/1)
11
+ Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'broken.mov':
12
+ Metadata:
13
+ major_brand : qt
14
+ minor_version : 537199360
15
+ compatible_brands: qt
16
+ Duration: 00:00:23.12, start: 0.000000, bitrate: 28033 kb/s
17
+ Stream #0.0(eng): Video: Apple ProRes 422, 410x620, 28029 kb/s, 25 fps, 25 tbr, 2500 tbn, 2500 tbc
18
+ At least one output file must be specified
@@ -0,0 +1,29 @@
1
+ ffmpeg version 0.8, Copyright (c) 2000-2011 the FFmpeg developers
2
+ built on Jul 20 2011 10:41:26 with gcc 4.2.1 (Apple Inc. build 5664)
3
+ configuration: --prefix=/usr/local/Cellar/ffmpeg/0.8 --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid
4
+ libavutil 51. 9. 1 / 51. 9. 1
5
+ libavcodec 53. 7. 0 / 53. 7. 0
6
+ libavformat 53. 4. 0 / 53. 4. 0
7
+ libavdevice 53. 1. 1 / 53. 1. 1
8
+ libavfilter 2. 23. 0 / 2. 23. 0
9
+ libswscale 2. 0. 0 / 2. 0. 0
10
+ libpostproc 51. 2. 0 / 51. 2. 0
11
+ [aac @ 0x101820400] Audio object type 23 is not supported.
12
+ Last message repeated 471 times
13
+ [mov,mp4,m4a,3gp,3g2,mj2 @ 0x101807c00] max_analyze_duration 5000000 reached at 5002667
14
+
15
+ Seems stream 1 codec frame rate differs from container frame rate: 96000.00 (96000/1) -> 48000.00 (96000/2)
16
+ Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'no_audio_channel_info.mov':
17
+ Metadata:
18
+ major_brand : qt
19
+ minor_version : 537199360
20
+ compatible_brands: qt
21
+ creation_time : 2009-05-26 14:36:22
22
+ Duration: 00:13:15.81, start: 0.000000, bitrate: 4825 kb/s
23
+ Stream #0.0(eng): Audio: aac, stereo, 182 kb/s
24
+ Metadata:
25
+ creation_time : 2009-05-26 14:36:22
26
+ Stream #0.1(eng): Video: h264 (Main), yuv420p, 768x434, 4636 kb/s, 25 fps, 48k tbr, 48k tbn, 96k tbc
27
+ Metadata:
28
+ creation_time : 2009-05-26 14:36:22
29
+ At least one output file must be specified
@@ -0,0 +1,19 @@
1
+ FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
2
+ built on Nov 18 2010 13:51:50 with gcc 4.2.1 (Apple Inc. build 5664)
3
+ configuration: --disable-debug --prefix=/usr/local/Cellar/ffmpeg/0.6.1 --enable-shared --enable-pthreads --enable-nonfree --enable-gpl --disable-indev=jack --enable-libx264 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid
4
+ libavutil 50.15. 1 / 50.15. 1
5
+ libavcodec 52.72. 2 / 52.72. 2
6
+ libavformat 52.64. 2 / 52.64. 2
7
+ libavdevice 52. 2. 0 / 52. 2. 0
8
+ libswscale 0.11. 0 / 0.11. 0
9
+ [mov,mp4,m4a,3gp,3g2,mj2 @ 0x10180b000]max_analyze_duration reached
10
+ Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/druiden/Movies/clips/4cebb32fb35ea857d9000039_4cfe13671ee3ba063400002c.f4v':
11
+ Metadata:
12
+ major_brand : f4v
13
+ minor_version : 0
14
+ compatible_brands: isommp42m4v
15
+ Duration: 00:00:28.11, start: 13.038000, bitrate: 411 kb/s
16
+ Stream #0.0(eng): Video: h264, yuv420p, 320x214 [PAR 1:1 DAR 160:107], 25 tbr, 1k tbn, 50 tbc
17
+ Stream #0.1(eng): Audio: mp3, 44100 Hz, 2 channels, s16, 96 kb/s
18
+ Stream #0.2(eng): Data: amf0 / 0x30666D61
19
+ At least one output file must be specified
@@ -0,0 +1,19 @@
1
+ FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
2
+ built on Nov 18 2010 13:51:50 with gcc 4.2.1 (Apple Inc. build 5664)
3
+ configuration: --disable-debug --prefix=/usr/local/Cellar/ffmpeg/0.6.1 --enable-shared --enable-pthreads --enable-nonfree --enable-gpl --disable-indev=jack --enable-libx264 --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid
4
+ libavutil 50.15. 1 / 50.15. 1
5
+ libavcodec 52.72. 2 / 52.72. 2
6
+ libavformat 52.64. 2 / 52.64. 2
7
+ libavdevice 52. 2. 0 / 52. 2. 0
8
+ libswscale 0.11. 0 / 0.11. 0
9
+
10
+ Seems stream 0 codec frame rate differs from container frame rate: 1200.00 (1200/1) -> 25.00 (25/1)
11
+ Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bigbucksbunny_trailer_720p.mov':
12
+ Metadata:
13
+ major_brand : qt
14
+ minor_version : 537199360
15
+ compatible_brands: qt
16
+ Duration: 00:00:33.00, start: 0.000000, bitrate: 4317 kb/s
17
+ Stream #0.0(eng): Video: h264, yuv420p, 1280x720, 3945 kb/s, 25 fps, 25 tbr, 600 tbn, 1200 tbc
18
+ Stream #0.1(eng): Audio: aac, 48000 Hz, 5.1, s16, 428 kb/s
19
+ At least one output file must be specified
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+ require "handler"
3
+
4
+ describe VTools::Handler do
5
+
6
+ # hooks
7
+ before do
8
+ @handler = VTools::Handler.dup
9
+ @handler.instance_variable_set(:@callbacks, {})
10
+ end
11
+
12
+ # specs
13
+ context "#set" do
14
+
15
+ it "sets valid action" do
16
+ @handler.instance_variable_get(:@callbacks).should == {}
17
+
18
+ block = lambda { |*args| nil }
19
+ other_block = lambda { |*args| false }
20
+
21
+ @handler.set :action_one, &block
22
+ @handler.set "action_two", &other_block
23
+
24
+ @handler.instance_variable_get(:@callbacks).should == {
25
+ :action_one => [ block ], :action_two => [ other_block ]
26
+ }
27
+ end
28
+
29
+ it "skips set when no block given" do
30
+ @handler.set :action_one
31
+ @handler.set :action_one
32
+ @handler.set :action_two
33
+
34
+ @handler.instance_variable_get(:@callbacks).should == {:action_one => [], :action_two => []}
35
+ end
36
+ end
37
+
38
+ context "#exec" do
39
+
40
+ it "executes valid callbacks" do
41
+ # prepare data
42
+ block_one = lambda { |*args| nil }
43
+ block_two = lambda { |*args| nil }
44
+ block_three = lambda { |*args| nil }
45
+ @handler.instance_variable_set( :@callbacks, {:action_one => [block_one], :action_two => [block_two, block_three]} )
46
+
47
+ block_one.should_receive(:call).with("one").once
48
+ block_two.should_receive(:call).with("two", "and", "three").once
49
+ block_three.should_receive(:call).with("two", "and", "three").once
50
+
51
+ @handler.exec :action_one, "one"
52
+ @handler.exec :action_two, "two", "and", "three"
53
+ end
54
+
55
+ it "skips empty or invalid callbacks" do
56
+ @handler.instance_variable_set(:@callbacks, {:action_one => [], :action_two => "test"} )
57
+
58
+ callbacks = @handler.instance_variable_get(:@callbacks)
59
+ callbacks[:action_one].should_receive :each
60
+ callbacks[:action_two].should_not_receive :each
61
+
62
+ # nil can't be called so we just must ensure, that error is not raised
63
+ expect { @handler.exec :action_one, "one" }.to_not raise_error
64
+ expect { @handler.exec :action_two, "two", "and", "three" }.to_not raise_error
65
+ end
66
+ end
67
+
68
+ context "#collection" do
69
+
70
+ it "executes valid scope" do
71
+ VTools::Handler.should_receive(:instance_eval).once
72
+
73
+ VTools::Handler.collection do
74
+ self.should be_a_kind_of(VTools::Handler)
75
+ self.should respond_to(:set)
76
+ self.should respond_to(:get)
77
+ self.should respond_to(:collection)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,189 @@
1
+ require "spec_helper"
2
+ require "harvester"
3
+
4
+ describe VTools::Harvester do
5
+
6
+ # hooks
7
+ before do
8
+ @harvester = VTools::Harvester.dup
9
+ end
10
+
11
+ context "#add_job" do
12
+
13
+ def stub_methods
14
+
15
+ Thread.stub!(:new) do |*args, block|
16
+ block.call(*args)
17
+ end
18
+
19
+ job_mock = double(nil)
20
+ job_mock.stub(:id).and_return 10
21
+ job_mock.stub(:execute).and_return "test.executed"
22
+
23
+ VTools::Job.stub!(:new).and_return { job_mock }
24
+
25
+ @harvester.stub!(:finish).and_return nil
26
+ @harvester.stub!(:with_error_handle).and_return { |blk| blk.call }
27
+ job_mock
28
+ end
29
+
30
+ it "accepts valid config" do
31
+
32
+ config = OpenStruct.new(:action => "test.action")
33
+ job = stub_methods
34
+
35
+ VTools::Storage.stub!(:send).and_return do |hsh|
36
+ hsh.should include :data => "test.executed", :action => "test.action"
37
+ end
38
+
39
+ @harvester.should_receive(:finish).with(job).twice
40
+ VTools::Storage.should_receive(:send).twice
41
+ VTools::Job.should_receive(:new).with(config).twice
42
+
43
+ @harvester.add_job config
44
+ @harvester.add_job config
45
+
46
+ @harvester.instance_variable_get(:@jobs).should include 10 => job, 10 => job
47
+ @harvester.instance_variable_get(:@run_jobs).should == 2
48
+ end
49
+ end
50
+
51
+ context "#finish" do
52
+
53
+ def make_stubs ret = true
54
+ VTools::Job.stub!(:id).and_return 10
55
+ VTools::Job.stub!(:is_a?).and_return ret
56
+ end
57
+
58
+ it "accepts data" do
59
+ make_stubs
60
+
61
+ job = VTools::Job
62
+
63
+ # place job
64
+ @harvester.instance_variable_set :@jobs, 10 => true
65
+ @harvester.instance_variable_set :@run_jobs, 2
66
+
67
+ @harvester.method(:finish).call(job)
68
+
69
+ @harvester.instance_variable_get(:@jobs).should_not include 10 => true
70
+ @harvester.instance_variable_get(:@run_jobs).should == 1
71
+ end
72
+
73
+ it "denies data" do
74
+ make_stubs
75
+
76
+ job = VTools::Job
77
+
78
+ # place job
79
+ @harvester.instance_variable_set :@jobs, 1 => true
80
+ @harvester.instance_variable_set :@run_jobs, 2
81
+
82
+ jobs = @harvester.instance_variable_get(:@jobs)
83
+ jobs.should_not_receive(:delete)
84
+
85
+ @harvester.method(:finish).call(job)
86
+
87
+ jobs.should include 1 => true
88
+ @harvester.instance_variable_get(:@run_jobs).should == 2
89
+ end
90
+
91
+ it "non Job passed" do
92
+ make_stubs false
93
+
94
+ job = VTools::Job
95
+
96
+ jobs = @harvester.instance_variable_get(:@jobs)
97
+ jobs.should_not_receive(:delete)
98
+
99
+ @harvester.method(:finish).call(job)
100
+ end
101
+ end
102
+
103
+ context "#with_error_handle" do
104
+
105
+ def handle_error type, message_rx
106
+ @harvester.stub(:log).and_return do |e_level, mess|
107
+ e_level.should == type
108
+ mess.should =~ message_rx
109
+ end
110
+ end
111
+
112
+ it "passes data with no exception" do
113
+ expect { @harvester.method(:with_error_handle).call }.to_not raise_error
114
+ expect { @harvester.method(:with_error_handle).call {a = "some block"} }.to_not raise_error
115
+ end
116
+
117
+ it "raises known exception" do
118
+ handle_error :error, /test\.error/
119
+
120
+ [VTools::ConfigError, VTools::FileError, VTools::FormatError, VTools::ProcessError].each do |execpt|
121
+ @harvester.should_receive(:log)
122
+
123
+ expect do
124
+ @harvester.method(:with_error_handle).call { raise execpt, "test.error" }
125
+ end.to_not raise_error
126
+ end
127
+ end
128
+
129
+ it "raises unknown exception" do
130
+ handle_error :fatal, /test\.fatal/
131
+ @harvester.should_receive(:log).with(:fatal, "test.fatal")
132
+
133
+ expect do
134
+ @harvester.method(:with_error_handle).call { raise "test.fatal" }
135
+ end.to raise_error
136
+ end
137
+ end
138
+
139
+ # specs
140
+ context "#daemonize!" do
141
+
142
+ def stub_methods
143
+ @harvester.stub!(:loop).and_return{ |block| block.yield }
144
+ @harvester.stub!(:sleep)
145
+
146
+ VTools::Storage.stub!(:connect).and_return nil
147
+ VTools::Storage.stub!(:recv).and_return "recvd"
148
+ @harvester.stub!(:with_error_handle).and_return {|blk| blk.call}
149
+ end
150
+
151
+ # CONFIG[:max_jobs] > @run_jobs, should[_not]_receive [__messages__]
152
+ it "loops trough jobs" do
153
+ stub_methods
154
+
155
+ config = OpenStruct.new( :config => 'tested' )
156
+ @harvester.stub!(:json_to_obj).and_return { config }
157
+
158
+ VTools::CONFIG[:harvester_timer] = 0
159
+ VTools::CONFIG[:max_jobs] = 2
160
+ @harvester.instance_variable_set :@run_jobs, 1
161
+
162
+ @harvester.should_receive(:sleep).with(0).once
163
+ VTools::Storage.should_receive(:connect).once
164
+ VTools::Storage.should_receive(:recv).once
165
+ @harvester.should_receive(:json_to_obj).with("recvd").once
166
+ @harvester.should_receive(:add_job).with(config).once
167
+ @harvester.should_receive(:with_error_handle).once
168
+
169
+ @harvester.daemonize!
170
+ end
171
+
172
+ it "does not takes job (queue if full)" do
173
+ stub_methods
174
+
175
+ VTools::CONFIG[:harvester_timer] = 1
176
+ VTools::CONFIG[:max_jobs] = 2
177
+ @harvester.instance_variable_set :@run_jobs, 2
178
+
179
+ @harvester.should_receive(:sleep).with(1).once
180
+ VTools::Storage.should_receive(:connect).once
181
+ VTools::Storage.should_not_receive(:recv)
182
+ @harvester.should_not_receive(:json_to_obj)
183
+ @harvester.should_not_receive(:add_job)
184
+ @harvester.should_not_receive(:with_error_handle)
185
+
186
+ @harvester.daemonize!
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,130 @@
1
+ require "spec_helper"
2
+ require "job"
3
+
4
+ describe VTools::Job do
5
+
6
+ let (:config) { OpenStruct.new :action => "info", :file => "test/file"}
7
+ let (:video) { @video }
8
+
9
+ # hooks
10
+ before do
11
+ @video = double nil
12
+ VTools::Video.stub!(:new).and_return video
13
+ @job = VTools::Job.new config
14
+ end
15
+
16
+ # specs
17
+ context "#execute" do
18
+
19
+ def stub_methods
20
+ VTools::Handler.stub!(:exec).and_return nil
21
+
22
+ @video.stub(:get_info).and_return {"info.result"}
23
+ @video.stub(:convert).and_return {"encoded.result"}
24
+ @video.stub(:create_thumbs).and_return {"thumbs.result"}
25
+ end
26
+
27
+ def set_action action
28
+ options = @job.instance_variable_get :@config
29
+ options.action = action
30
+ @job.instance_variable_set :@config, options
31
+ end
32
+
33
+ it "receives video info" do
34
+ stub_methods
35
+ set_action "info"
36
+
37
+ VTools::Handler.should_receive(:exec).with(:job_started, @video, "info")
38
+ VTools::Handler.should_receive(:exec).with(:job_finished, "info.result", @video, "info")
39
+ @video.should_receive(:get_info)
40
+
41
+ @job.execute.should == "info.result"
42
+ end
43
+
44
+ it "starts video encoding" do
45
+ stub_methods
46
+ set_action "convert"
47
+
48
+ VTools::Handler.should_receive(:exec).with(:job_started, @video, "convert")
49
+ VTools::Handler.should_receive(:exec).with(:job_finished, "encoded.result", @video, "convert")
50
+ @video.should_receive(:convert)
51
+
52
+ @job.execute.should == "encoded.result"
53
+ end
54
+
55
+ it "creates thumbnails" do
56
+ stub_methods
57
+ set_action "thumbs"
58
+
59
+ VTools::Handler.should_receive(:exec).with(:job_started, @video, "thumbs")
60
+ VTools::Handler.should_receive(:exec).with(:job_finished, "thumbs.result", @video, "thumbs")
61
+ @video.should_receive(:create_thumbs)
62
+
63
+ @job.execute.should == "thumbs.result"
64
+ end
65
+ end
66
+
67
+ # specs
68
+ context "#validate" do
69
+
70
+ it "accepts options" do
71
+
72
+ ["convert", "thumbs", "info"].each do |action|
73
+ conf = config.dup
74
+ conf.action = action
75
+ conf.setup = "setup.test" unless action == "info"
76
+
77
+ expect { @job.validate(conf).should == conf }.to_not raise_error
78
+ end
79
+ end
80
+
81
+ it "rases exception with invalid config" do
82
+
83
+ def validate_exception conf, message_rx
84
+ expect { @job.validate(conf) }.to raise_error VTools::ConfigError, message_rx
85
+ end
86
+
87
+
88
+ ["convert", "thumbs", "info"].each do |action|
89
+ # empty config
90
+ conf = OpenStruct.new({})
91
+ validate_exception conf, /Invalid action \(config: /
92
+
93
+ # +action -file
94
+ conf.action = action
95
+ validate_exception conf, /Invalid action \(config: /
96
+
97
+ # empty file
98
+ conf.file = ""
99
+ validate_exception conf, /Invalid action \(config: /
100
+
101
+ # +file -config
102
+ conf.file = "test/file"
103
+ validate_exception conf, "Configuration is empty" unless action == "info"
104
+ end
105
+ end
106
+ end
107
+
108
+ # specs
109
+ context "#initialize" do
110
+
111
+ it "passes valid params" do
112
+
113
+ VTools::Job.any_instance.stub(:validate).and_return { |obj| obj }
114
+
115
+ job = nil
116
+ expect { job = VTools::Job.new config }.to_not raise_error
117
+
118
+ job.id.should == job.object_id
119
+ job.instance_variable_get(:@config).should == config
120
+ job.instance_variable_get(:@video).should == video
121
+ end
122
+
123
+ it "raises error on invalid config (validate)" do
124
+ VTools::Job.any_instance.stub(:validate).and_return { raise "test.exception" }
125
+
126
+ expect { job = VTools::Job.new config }.to raise_error "test.exception"
127
+ end
128
+ end
129
+
130
+ end