spec/rdiff_simple_spec.rb in rdiff-simple-0.0.3 vs spec/rdiff_simple_spec.rb in rdiff-simple-0.0.4

- old
+ new

@@ -1,7 +1,56 @@ require 'spec_helper' describe RdiffSimple do - it "should be defined" do - defined?(RdiffSimple).should == 'constant' + describe '#execute' do + context 'when no arguments are given' do + it 'should return false' do + subject.execute.should be_false + end + end + + context 'when arguments are given' do + it 'should return true' do + subject.execute('--version').should be_true + end + end + + context 'when rdiff-backup is not installed' do + before(:each) do + mock_rdiff_installed(false) + end + + it 'should be false' do + expect { subject.execute('--version') }.should raise_error(RdiffSimple::NotInstalledError) + end + end + end + + describe '#installed?' do + context 'when rdiff-backup is installed' do + before(:each) do + mock_rdiff_installed(true) + end + + it 'should be true' do + subject.installed?.should be_true + end + end + + context 'when rdiff-backup is not installed' do + before(:each) do + mock_rdiff_installed(false) + end + + it 'should be false' do + subject.installed?.should be_false + end + end + end + + def mock_rdiff_installed(value) + subject + .should_receive(:system) + .with('which rdiff-backup') + .and_return(value) end end