spec/handbrake/cli_spec.rb in handbrake-0.3.1 vs spec/handbrake/cli_spec.rb in handbrake-0.4.0
- old
+ new
@@ -21,10 +21,42 @@
it "can be set" do
HandBrake::CLI.new(:trace => true).trace?.should == true
end
end
+ describe '#runner' do
+ let(:default_runner_class) { HandBrake::CLI::PopenRunner }
+
+ it 'is a PopenRunner by default' do
+ HandBrake::CLI.new.runner.should be_a default_runner_class
+ end
+
+ it 'can be set with a static value' do
+ HandBrake::CLI.new(:runner => HandBrake::Spec::StaticRunner.new).runner.
+ should be_a HandBrake::Spec::StaticRunner
+ end
+
+ describe 'set from a lambda' do
+ let(:recorder_class) { Struct.new(:input) }
+ let(:runner_constructor) { lambda { |cli| recorder_class.new(cli) } }
+ let(:cli) { HandBrake::CLI.new(:runner => runner_constructor) }
+
+ it 'calls the lambda' do
+ cli.runner.should be_a recorder_class
+ end
+
+ it 'yields the CLI instance' do
+ cli.runner.input.should be cli
+ end
+
+ it 'uses the default if the lambda returns nil' do
+ HandBrake::CLI.new(:runner => lambda { |cli| nil }).runner.
+ should be_a default_runner_class
+ end
+ end
+ end
+
describe "building a command" do
let(:cli) { HandBrake::CLI.new }
it "works for a parameter without an argument" do
cli.markers.arguments.should == %w(--markers)
@@ -351,9 +383,32 @@
it 'returns a hash containing the actual args for a particular preset' do
cli.preset_list['Regular']['Normal'].should ==
'-e x264 -q 20.0 -a 1 -E faac -B 160 -6 dpl2 -R Auto -D 0.0 -f mp4 --strict-anamorphic -m -x ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0'
end
+ end
+ end
+ end
+
+ describe CLI::PopenRunner do
+ describe '#command' do
+ subject { CLI::PopenRunner.new(CLI.new(:bin_path => '/foo/hbcli')) }
+
+ it 'starts with the bin path' do
+ subject.command(%w(--bar)).should =~ %r{^'/foo/hbcli'}
+ end
+
+ it 'quotes the arguments' do
+ subject.command(%w(--bar)).should =~ %r{'--bar'}
+ end
+
+ it 'redirects stderr to stdout' do
+ subject.command([]).should =~ %r{2>&1$}
+ end
+
+ it 'escapes single quotes in the arguments' do
+ subject.command(["--output", "/quux/boo's.m4v"]).
+ should == %('/foo/hbcli' '--output' '/quux/boo'\\''s.m4v' 2>&1)
end
end
end
end