-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial specs for retry filter - they test if it works at all, basically
Change Retry filter to have attribute :configuration and first pass at setting up a listener Reorganize spec file Finish adding tests for re-running flaky test cases - all but one pass Fix spec that said to test what happens when a test case passes but actually didn't make sure it did pass
- Loading branch information
1 parent
4a66b5b
commit 22855a7
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'cucumber/core/filter' | ||
require 'cucumber/running_test_case' | ||
require 'cucumber/events/bus' | ||
require 'cucumber/events/after_test_case' | ||
|
||
module Cucumber | ||
module Filters | ||
class Retry < Core::Filter.new(:configuration) | ||
|
||
def test_case(test_case) | ||
super | ||
|
||
configuration.on_event(:after_test_case) do |event| | ||
test_case.describe_to(receiver) if event.result.failed? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'cucumber' | ||
require 'cucumber/filters/retry' | ||
require 'cucumber/core/gherkin/writer' | ||
require 'cucumber/configuration' | ||
require 'cucumber/core/test/case' | ||
require 'cucumber/core' | ||
require 'cucumber/events' | ||
|
||
describe Cucumber::Filters::Retry do | ||
include Cucumber::Core::Gherkin::Writer | ||
include Cucumber::Core | ||
include Cucumber::Events | ||
|
||
let(:configuration) { Cucumber::Configuration.new(:retry => 2) } | ||
let(:test_case) { Cucumber::Core::Test::Case.new([double('test steps')], double('source').as_null_object) } | ||
let(:receiver) { double('receiver').as_null_object } | ||
let(:filter) { Cucumber::Filters::Retry.new(configuration, receiver) } | ||
let(:fail) { Cucumber::Events::AfterTestCase.new(test_case, double('result', :failed? => true, :ok? => false)) } | ||
let(:pass) { Cucumber::Events::AfterTestCase.new(test_case, double('result', :failed? => false, :ok? => true)) } | ||
|
||
it { is_expected.to respond_to(:test_case) } | ||
it { is_expected.to respond_to(:with_receiver) } | ||
it { is_expected.to respond_to(:done) } | ||
|
||
context "general" do | ||
before(:each) do | ||
filter.with_receiver(receiver) | ||
end | ||
|
||
it "registers the :after_test_case event" do | ||
expect(configuration).to receive(:on_event).with(:after_test_case) | ||
filter.test_case(test_case) | ||
end | ||
end | ||
|
||
context "passing test case" do | ||
it "describes the test case once" do | ||
expect(test_case).to receive(:describe_to).with(receiver) | ||
filter.test_case(test_case) | ||
configuration.notify(pass) | ||
end | ||
end | ||
|
||
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 | ||
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 | ||
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 | ||
filter.test_case(test_case) | ||
configuration.notify(fail) | ||
configuration.notify(fail) | ||
configuration.notify(pass) | ||
end | ||
end | ||
end | ||
end |