Skip to content

Commit

Permalink
Initial specs for retry filter - they test if it works at all, basically
Browse files Browse the repository at this point in the history
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
danascheider committed Oct 19, 2015
1 parent 4a66b5b commit 22855a7
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/cucumber/filters/retry.rb
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
73 changes: 73 additions & 0 deletions spec/cucumber/filters/retry_spec.rb
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

0 comments on commit 22855a7

Please sign in to comment.