From a2968211bfe13e29e771ac15d4ac454dcbbe5a61 Mon Sep 17 00:00:00 2001 From: Matt Wynne Date: Fri, 11 Sep 2015 13:51:29 +0100 Subject: [PATCH] Use Events for fail-fast ref #906 --- lib/cucumber/formatter/event_bus_report.rb | 3 +++ lib/cucumber/formatter/fail_fast.rb | 15 +++++------ spec/cucumber/formatter/fail_fast_spec.rb | 30 +++------------------- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/cucumber/formatter/event_bus_report.rb b/lib/cucumber/formatter/event_bus_report.rb index dd7690c74d..94eace8079 100644 --- a/lib/cucumber/formatter/event_bus_report.rb +++ b/lib/cucumber/formatter/event_bus_report.rb @@ -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 diff --git a/lib/cucumber/formatter/fail_fast.rb b/lib/cucumber/formatter/fail_fast.rb index be591e33d4..d1b060ac5d 100644 --- a/lib/cucumber/formatter/fail_fast.rb +++ b/lib/cucumber/formatter/fail_fast.rb @@ -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 diff --git a/spec/cucumber/formatter/fail_fast_spec.rb b/spec/cucumber/formatter/fail_fast_spec.rb index 467d9576d1..2d4f4943b2 100644 --- a/spec/cucumber/formatter/fail_fast_spec.rb +++ b/spec/cucumber/formatter/fail_fast_spec.rb @@ -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 @@ -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 \ No newline at end of file +end