spec/arachni/browser_cluster/job_spec.rb in arachni-1.2.1 vs spec/arachni/browser_cluster/job_spec.rb in arachni-1.3

- old
+ new

@@ -13,23 +13,25 @@ @master ||= MockBrowserCluster.new end end class JobTest < Arachni::BrowserCluster::Job + include RSpec::Matchers + def ran? !!@ran end def run - browser.class.should == MockWorker + expect(browser.class).to eq MockWorker @ran = true end end class JobConfigureAndRunTest < JobTest def run - browser.class.should == MockWorker + expect(browser.class).to eq MockWorker super end end class JobSaveResultTest < JobTest @@ -40,26 +42,26 @@ def run val = 'stuff' save_result my_data: val result = browser.master.result - result.job.id.should == self.id - result.my_data.should == val + expect(result.job.id).to eq self.id + expect(result.my_data).to eq val super end end class JobCleanCopyTest < JobTest def run - browser.class.should == MockWorker + expect(browser.class).to eq MockWorker copy = self.clean_copy - copy.browser.should == nil - copy.id.should == self.id + expect(copy.browser).to eq nil + expect(copy.id).to eq self.id - browser.class.should == MockWorker + expect(browser.class).to eq MockWorker super end end @@ -87,11 +89,11 @@ id = nil 10.times do |i| id = described_class.new.id next if i == 0 - described_class.new.id.should == id + 1 + expect(described_class.new.id).to eq(id + 1) end end end describe '#never_ending?' do @@ -99,24 +101,24 @@ context 'when #never_ending is' do context true do it 'returns true' do subject.never_ending = true - subject.never_ending?.should be_true + expect(subject.never_ending?).to be_truthy end end context false do it 'returns false' do subject.never_ending = false - subject.never_ending?.should be_false + expect(subject.never_ending?).to be_falsey end end context nil do it 'returns false' do - subject.never_ending?.should be_false + expect(subject.never_ending?).to be_falsey end end end end @@ -126,138 +128,156 @@ it 'sets #browser' do subject.configure_and_run( worker ) end it 'calls #run' do - subject.ran?.should be_false + expect(subject.ran?).to be_falsey subject.configure_and_run( worker ) - subject.ran?.should be_true + expect(subject.ran?).to be_truthy end it 'removes #browser' do - subject.ran?.should be_false + expect(subject.ran?).to be_falsey subject.configure_and_run( worker ) - subject.browser.should be_nil - subject.ran?.should be_true + expect(subject.browser).to be_nil + expect(subject.ran?).to be_truthy end end describe '#save_result' do subject { JobSaveResultTest.new } it 'forwards the result to the BrowserCluster' do - subject.ran?.should be_false + expect(subject.ran?).to be_falsey subject.configure_and_run( worker ) - subject.ran?.should be_true + expect(subject.ran?).to be_truthy end end describe '#clean_copy' do subject { JobCleanCopyTest.new } it 'copies the Job without the resources set by #configure_and_run' do - subject.ran?.should be_false + expect(subject.ran?).to be_falsey subject.configure_and_run( worker ) - subject.ran?.should be_true + expect(subject.ran?).to be_truthy end end describe '#dup' do subject { JobDupTest.new( never_ending: true, my_data: 'stuff' ) } it 'copies the Job' do - subject.my_data.should == 'stuff' + expect(subject.my_data).to eq('stuff') dup = subject.dup - dup.my_data.should == 'stuff' - dup.never_ending?.should == true + expect(dup.my_data).to eq('stuff') + expect(dup.never_ending?).to eq(true) end + + it 'preserves #time' do + subject.time = 10 + expect(subject.time).to eq 10 + + dup = subject.dup + expect(dup.time).to eq 10 + end + + it 'preserves #timed_out' do + subject.timed_out! 10 + expect(subject.time).to eq 10 + expect(subject).to be_timed_out + + dup = subject.dup + expect(dup.time).to eq 10 + expect(subject).to be_timed_out + end end describe '#forward' do subject { JobForwardTest.new( my_data: 'stuff' ) } it 'sets the original Job as the #forwarder' do id = subject.id - subject.forward.forwarder.should == subject + expect(subject.forward.forwarder).to eq(subject) end it 'creates a new Job with the same #id' do id = subject.id - subject.forward.id.should == id + expect(subject.forward.id).to eq(id) end it 'creates a new Job with the same #never_ending' do - subject.forward.never_ending?.should be_false + expect(subject.forward.never_ending?).to be_falsey job = JobForwardTest.new( never_ending: true, my_data: 'stuff' ) - job.never_ending?.should be_true - job.forward.never_ending?.should be_true + expect(job.never_ending?).to be_truthy + expect(job.forward.never_ending?).to be_truthy job = JobForwardTest.new( never_ending: false, my_data: 'stuff' ) - job.never_ending?.should be_false - job.forward.never_ending?.should be_false + expect(job.never_ending?).to be_falsey + expect(job.forward.never_ending?).to be_falsey end it 'does not preserve any existing data' do - subject.forward.my_data.should be_nil + expect(subject.forward.my_data).to be_nil end context 'when options are given' do it 'sets initialization options' do - subject.forward( my_data: 'stuff2' ).my_data.should == 'stuff2' + expect(subject.forward( my_data: 'stuff2' ).my_data).to eq('stuff2') end end end describe '#forward_as' do subject { JobForwardTest.new( my_data: 'stuff' ) } it 'sets the original Job as the #forwarder' do id = subject.id - subject.forward_as( JobForwardAsTest ).forwarder.should == subject + expect(subject.forward_as( JobForwardAsTest ).forwarder).to eq(subject) end it 'creates a new Job type with the same #id' do - subject.should_not be_kind_of JobForwardAsTest + expect(subject).not_to be_kind_of JobForwardAsTest id = subject.id forwarded = subject.forward_as( JobForwardAsTest ) - forwarded.id.should == id - forwarded.should be_kind_of JobForwardAsTest + expect(forwarded.id).to eq(id) + expect(forwarded).to be_kind_of JobForwardAsTest end it 'creates a new Job with the same #never_ending' do - subject.forward_as( JobForwardAsTest ).never_ending?.should be_false + expect(subject.forward_as( JobForwardAsTest ).never_ending?).to be_falsey job = JobForwardTest.new( never_ending: true, my_data: 'stuff' ) - job.never_ending?.should be_true - job.forward_as( JobForwardAsTest ).never_ending?.should be_true + expect(job.never_ending?).to be_truthy + expect(job.forward_as( JobForwardAsTest ).never_ending?).to be_truthy job = JobForwardTest.new( never_ending: false, my_data: 'stuff' ) - job.never_ending?.should be_false - job.forward_as( JobForwardAsTest ).never_ending?.should be_false + expect(job.never_ending?).to be_falsey + expect(job.forward_as( JobForwardAsTest ).never_ending?).to be_falsey end it 'does not preserve any existing data' do - subject.should_not be_kind_of JobForwardAsTest + expect(subject).not_to be_kind_of JobForwardAsTest forwarded = subject.forward_as( JobForwardAsTest ) - forwarded.my_data.should be_nil - forwarded.should be_kind_of JobForwardAsTest + expect(forwarded.my_data).to be_nil + expect(forwarded).to be_kind_of JobForwardAsTest end context 'when options are given' do it 'sets initialization options' do - subject.should_not be_kind_of JobForwardAsTest + expect(subject).not_to be_kind_of JobForwardAsTest forwarded = subject.forward_as( JobForwardAsTest, my_data: 'stuff2' ) - forwarded.my_data.should == 'stuff2' - forwarded.should be_kind_of JobForwardAsTest + expect(forwarded.my_data).to eq('stuff2') + expect(forwarded).to be_kind_of JobForwardAsTest end end end end