spec/handbrake/cli_spec.rb in handbrake-0.2.1 vs spec/handbrake/cli_spec.rb in handbrake-0.3.0

- old
+ new

@@ -161,84 +161,103 @@ cli.output(filename) it_should_have_run end end - context 'true' do - let(:expected_temporary_file) { File.join(tmpdir, "foo.handbraking.m4v") } - + shared_examples 'atomic enabled' do it 'outputs to the temporary file with ".handbraking" inserted before the extension' do - cli.output(filename, :atomic => true) + cli.output(filename, :atomic => atomic_option_value) it_should_have_run(expected_temporary_file) end it 'appends .handbraking if the output file does not have an extension' do - cli.output(File.join(tmpdir('a.b.c'), 'foo'), :atomic => true) - it_should_have_run(File.join(tmpdir('a.b.c'), 'foo.handbraking')) + cli.output(File.join(tmpdir('a.b.c'), 'foo'), :atomic => atomic_option_value) + it_should_have_run(expected_no_extension_temporary_filename) end it 'copies the output to the desired filename' do - cli.output(filename, :atomic => true) + cli.output(filename, :atomic => atomic_option_value) File.read(filename).should == 'This is the file created by --output' end it 'removes the temporary file' do - cli.output(filename, :atomic => true) + cli.output(filename, :atomic => atomic_option_value) File.exist?(expected_temporary_file).should be_false end it 'overwrites the temporary file if it exists' do FileUtils.touch expected_temporary_file - cli.output(filename, :atomic => true) + cli.output(filename, :atomic => atomic_option_value) it_should_have_run(expected_temporary_file) end describe 'and :overwrite' do describe 'false' do it 'throws an exception if the target filename exists initially' do FileUtils.touch filename - lambda { cli.output(filename, :atomic => true, :overwrite => false) }. + lambda { cli.output(filename, :atomic => atomic_option_value, :overwrite => false) }. should raise_error(HandBrake::FileExistsError) end it 'throws an exception if the target filename exists after output' do runner.behavior = lambda { FileUtils.touch filename } - lambda { cli.output(filename, :atomic => true, :overwrite => false) }. + lambda { cli.output(filename, :atomic => atomic_option_value, :overwrite => false) }. should raise_error(HandBrake::FileExistsError) end end describe ':ignore' do it 'does nothing if the target filename exists initially' do FileUtils.touch filename - cli.output(filename, :atomic => true, :overwrite => :ignore) + cli.output(filename, :atomic => atomic_option_value, :overwrite => :ignore) it_should_not_have_run end it 'does not copy the output if the target filename exists after encoding' do runner.behavior = lambda { File.open(filename, 'w') { |f| f.write 'Other process result' } } - cli.output(filename, :atomic => true, :overwrite => :ignore) + cli.output(filename, :atomic => atomic_option_value, :overwrite => :ignore) File.read(filename).should == 'Other process result' end it 'does not remove the temporary output if the target filename exists after encoding' do runner.behavior = lambda { File.open(filename, 'w') { |f| f.write 'Other process result' } } - cli.output(filename, :atomic => true, :overwrite => :ignore) + cli.output(filename, :atomic => atomic_option_value, :overwrite => :ignore) File.exist?(expected_temporary_file).should be_true end end end end + + context 'true' do + let(:atomic_option_value) { true } + let(:expected_temporary_file) { File.join(tmpdir, "foo.handbraking.m4v") } + let(:expected_no_extension_temporary_filename) { + File.join(tmpdir('a.b.c'), 'foo.handbraking') + } + + include_examples 'atomic enabled' + end + + context 'an alternate path' do + let(:atomic_option_value) { tmpdir('somewhere/else') } + let(:expected_temporary_file) { File.join(atomic_option_value, "foo.handbraking.m4v") } + let(:expected_no_extension_temporary_filename) { + File.join(atomic_option_value, 'foo.handbraking') + } + + include_examples 'atomic enabled' + end end end describe '#scan' do let(:sample_scan) { File.read(File.expand_path('../sample-titles-scan.err', __FILE__)) } + let(:single_scan) { File.read(File.expand_path('../single-title-scan.err', __FILE__)) } before do runner.output = sample_scan end @@ -251,21 +270,27 @@ cli.scan runner.actual_arguments.should == %w(--title 0 --scan) end it 'only scans the specified title if one is specified' do - cli.title(3).scan - runner.actual_arguments.should == %w(--title 3 --scan) + cli.title(2).scan + runner.actual_arguments.should == %w(--title 2 --scan) end it 'does not permanently modify the argument list when using the default title setting' do cli.scan cli.arguments.should_not include('--title') end - it 'returns titles from the output' do - # The details for this are tested in titles_spec - cli.scan.size.should == 5 + it 'return a Disc when scanning all titles' do + # The details for this are tested in disc_spec + cli.scan.should be_a HandBrake::Disc + end + + it 'returns a Title when scanning one title' do + # The details for this are tested in disc_spec + runner.output = single_scan + cli.title(2).scan.should be_a HandBrake::Title end end describe '#update' do it 'uses the --update argument' do