spec/models/calculator_spec.rb in sw2at-ui-0.0.10 vs spec/models/calculator_spec.rb in sw2at-ui-0.0.11

- old
+ new

@@ -2,16 +2,55 @@ describe FullRevision do context 'Calculations' do - context 'Statuses' do + before :each do + Fire.reset_tree!(FIREBASE_DATA) + end + context 'Terminated Status' do before :each do - Fire.reset_tree!(FIREBASE_DATA) + allow_any_instance_of(RevisionStatusCalulator).to receive(:old_build?).and_return(true) end + it 'should calculate basic status (in_progress_failed)' do + rev = Revision::Root.all.first + + t1 = rev.nested_threads.first + t1.failed_examples = 5 + t1.save + + t2 = rev.nested_threads.last + t2.failed_examples = nil + t2.save + + rev = Revision::Root.all.first + + ts = RevisionStatusCalulator.new(rev).set_thread_statuses + expect(ts).to eq( + [{:name=>"completed_failed", + :label=>"Failed", + :completed=>true, + :failed=>true}, + {:name=>"in_progress_success", + :label=>"In Progress", + :completed=>false, + :failed=>false}] + ) + status = RevisionStatusCalulator.new(rev).set_status + expect(status).to include({name: "terminated", label: "Terminated", completed: true, failed: true}) + end + + end + + context 'Statuses(without terminated)' do + + before :each do + allow_any_instance_of(RevisionStatusCalulator).to receive(:old_build?).and_return(false) + end + it 'should set basic statuses' do rev = Revision::Root.all.first status = rev.nested_status expect(status.value).to be_nil @@ -23,11 +62,11 @@ end it 'should calculate basic status (completed_passed)' do rev = Revision::Root.all.first - ts = RevisionStatusCalulator.new.set_thread_statuses(rev) + ts = RevisionStatusCalulator.new(rev).set_thread_statuses expect(ts).to eq( [{:name=>"completed_passed", :label=>"Passed", :completed=>true, :failed=>false}, @@ -35,11 +74,11 @@ :label=>"Passed", :completed=>true, :failed=>false}] ) - status = RevisionStatusCalulator.new.set_status(rev) + status = RevisionStatusCalulator.new(rev).set_status expect(status).to include({name: "completed_passed", label: "Passed", completed: true, failed: false}) end it 'should calculate basic status (completed_failed)' do rev = Revision::Root.all.first @@ -48,11 +87,11 @@ t.failed_examples = 5 t.save rev = Revision::Root.all.first - ts = RevisionStatusCalulator.new.set_thread_statuses(rev) + ts = RevisionStatusCalulator.new(rev).set_thread_statuses expect(ts).to eq( [{:name=>"completed_failed", :label=>"Failed", :completed=>true, :failed=>true}, @@ -60,11 +99,11 @@ :label=>"Passed", :completed=>true, :failed=>false}] ) - status = RevisionStatusCalulator.new.set_status(rev) + status = RevisionStatusCalulator.new(rev).set_status expect(status).to include({name: "completed_failed", label: "Failed", completed: true, failed: true}) end it 'should calculate basic status (in_progress_failed)' do rev = Revision::Root.all.first @@ -77,22 +116,22 @@ t2.failed_examples = nil t2.save rev = Revision::Root.all.first - ts = RevisionStatusCalulator.new.set_thread_statuses(rev) + ts = RevisionStatusCalulator.new(rev).set_thread_statuses expect(ts).to eq( [{:name=>"completed_failed", :label=>"Failed", :completed=>true, :failed=>true}, {:name=>"in_progress_success", :label=>"In Progress", :completed=>false, :failed=>false}] ) - status = RevisionStatusCalulator.new.set_status(rev) + status = RevisionStatusCalulator.new(rev).set_status expect(status).to include({name: "in_progress_failed", label: "In Progress", completed: false, failed: true}) end it 'should calculate basic status (in_progress_success)' do @@ -101,11 +140,11 @@ main.threads_count = 3 main.save rev = Revision::Root.all.first - ts = RevisionStatusCalulator.new.set_thread_statuses(rev) + ts = RevisionStatusCalulator.new(rev).set_thread_statuses expect(ts).to eq( [{:name=>"completed_passed", :label=>"Passed", :completed=>true, :failed=>false}, @@ -117,10 +156,10 @@ :label=>"In Progress", :completed=>false, :failed=>false} ] ) - status = RevisionStatusCalulator.new.set_status(rev) + status = RevisionStatusCalulator.new(rev).set_status expect(status).to include({name: "in_progress_success", label: "In Progress", completed: false, failed: false}) end end