Skip to content

Commit

Permalink
Use Events for fail-fast
Browse files Browse the repository at this point in the history
ref #906
  • Loading branch information
mattwynne committed Sep 11, 2015
1 parent 895d6e3 commit a296821
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 35 deletions.
3 changes: 3 additions & 0 deletions lib/cucumber/formatter/event_bus_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def after_test_step(test_step, result)
def after_test_case(test_case, result)
@config.notify Events::AfterTestCase.new(test_case, result)
end

def done
end
end

end
Expand Down
15 changes: 6 additions & 9 deletions lib/cucumber/formatter/fail_fast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@

module Cucumber
module Formatter

class FailFast
def initialize(configuration)
@configuration = configuration
end

def after_test_case(test_case, result)
Cucumber.wants_to_quit = true unless result.ok?
def initialize(configuration)
configuration.on_event :after_test_case do |event|
Cucumber.wants_to_quit = true unless event.result.ok?
end
end

def done; end
def before_test_case *args; end
def before_test_step *args; end
def after_test_step *args; end
end

end
end
30 changes: 4 additions & 26 deletions spec/cucumber/formatter/fail_fast_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def test_case(test_case)
end
end

let(:report) { FailFast.new(double.as_null_object) }
let(:configuration) { Cucumber::Configuration.new }
before { FailFast.new(configuration) }
let(:report) { EventBusReport.new(configuration) }

context 'failing scenario' do
before(:each) do
Expand Down Expand Up @@ -72,29 +74,5 @@ def test_case(test_case)
end
end

describe 'after_test_case method' do
context 'failing scenario' do
it 'sets Cucumber.wants_to_quit' do
result = Cucumber::Core::Test::Result::Failed.new(double('duration'), double('exception'))

test_case = double('test_case')
allow(test_case).to receive(:location) { Cucumber::Core::Ast::Location.new('foo.feature')}
report.after_test_case(test_case, result)
expect(Cucumber.wants_to_quit).to be true
end
end

context 'passing scenario' do
let(:result) { Cucumber::Core::Test::Result::Passed.new(double) }

it 'doesn\'t raise an error' do
expect{ report.after_test_case(double, result) }.not_to raise_error
end

it 'returns nil' do
expect(report.after_test_case(double, result)).to eql nil
end
end
end
end
end
end

0 comments on commit a296821

Please sign in to comment.