diff --git a/lib/cucumber/filters/retry.rb b/lib/cucumber/filters/retry.rb index 128fd44a8c..bf26b3f69a 100644 --- a/lib/cucumber/filters/retry.rb +++ b/lib/cucumber/filters/retry.rb @@ -7,13 +7,23 @@ module Cucumber module Filters class Retry < Core::Filter.new(:configuration) - def test_case(test_case) - super - + def test_case(test_case) configuration.on_event(:after_test_case) do |event| - test_case.describe_to(receiver) if event.result.failed? + next unless event.test_case == test_case + next unless event.result.failed? + next if test_case_counts[test_case] >= configuration.retry_attempts + + test_case_counts[test_case] += 1 + event.test_case.describe_to(receiver) end + + super + end + + def test_case_counts + @test_case_counts ||= Hash.new { |h,k| h[k] = 0 } end + end end -end \ No newline at end of file +end diff --git a/spec/cucumber/filters/retry_spec.rb b/spec/cucumber/filters/retry_spec.rb index d001ef7583..526ba57d0f 100644 --- a/spec/cucumber/filters/retry_spec.rb +++ b/spec/cucumber/filters/retry_spec.rb @@ -43,9 +43,10 @@ context "failing test case" do it "describes the test case the specified number of times" do - expect(test_case).to receive(:describe_to).with(receiver).exactly(3).times + expect(receiver).to receive(:test_case) { |test_case| + configuration.notify(fail) + }.exactly(3).times filter.test_case(test_case) - configuration.notify(fail) end end @@ -53,21 +54,22 @@ context "a little flaky" do it "describes the test case twice" do - expect(test_case).to receive(:describe_to).with(receiver).exactly(2).times + results = [fail, pass] + expect(receiver).to receive(:test_case) { |test_case| + configuration.notify(results.shift) + }.exactly(2).times filter.test_case(test_case) - configuration.notify(fail) - configuration.notify(pass) end end context "really flaky" do it "describes the test case 3 times" do - expect(test_case).to receive(:describe_to).with(receiver).exactly(3).times + results = [fail, fail, pass] + expect(receiver).to receive(:test_case) { |test_case| + configuration.notify(results.shift) + }.exactly(3).times filter.test_case(test_case) - configuration.notify(fail) - configuration.notify(fail) - configuration.notify(pass) end end end -end \ No newline at end of file +end