-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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| | ||
This comment has been minimized.
Sorry, something went wrong. |
||
test_case.describe_to(receiver) if event.result.failed? | ||
next unless event.test_case == test_case | ||
This comment has been minimized.
Sorry, something went wrong.
mattwynne
Member
|
||
next unless event.result.failed? | ||
next if test_case_counts[test_case] >= configuration.retry_attempts | ||
This comment has been minimized.
Sorry, something went wrong.
mattwynne
Member
|
||
|
||
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 | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,31 +43,33 @@ | |
|
||
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| | ||
This comment has been minimized.
Sorry, something went wrong.
mattwynne
Member
|
||
configuration.notify(fail) | ||
This comment has been minimized.
Sorry, something went wrong.
mattwynne
Member
|
||
}.exactly(3).times | ||
This comment has been minimized.
Sorry, something went wrong.
mattwynne
Member
|
||
filter.test_case(test_case) | ||
configuration.notify(fail) | ||
end | ||
end | ||
|
||
context "flaky test cases" do | ||
|
||
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 | ||
This comment has been minimized.
Sorry, something went wrong.
mattwynne
Member
|
||
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 | ||
end |
We moved the whole event hook registration to happen before the test case is run, so that it's able to hear about the first failure - if it's registered after the call to
super
it will miss the firstafter_test_case
event which will have already fired by the time the hook is registered.