Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flaky result type to be used for flaky scenarios. #141

Merged
merged 1 commit into from
Jul 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/cucumber/core/report/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Summary
attr_reader :test_cases, :test_steps

def initialize(event_bus)
@previous_test_case = nil
@test_cases = Test::Result::Summary.new
@test_steps = Test::Result::Summary.new
subscribe_to(event_bus)
Expand All @@ -19,7 +20,13 @@ def ok?(be_strict = false)

def subscribe_to(event_bus)
event_bus.on(:test_case_finished) do |event|
event.result.describe_to test_cases
if event.test_case != @previous_test_case
@previous_test_case = event.test_case
event.result.describe_to test_cases
elsif event.result.passed?
test_cases.flaky
test_cases.decrement_failed
end
end
event_bus.on(:test_step_finished) do |event|
event.result.describe_to test_steps if is_step?(event.test_step)
Expand Down
15 changes: 14 additions & 1 deletion lib/cucumber/core/test/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Cucumber
module Core
module Test
module Result
TYPES = [:failed, :skipped, :undefined, :pending, :passed, :unknown].freeze
TYPES = [:failed, :flaky, :skipped, :undefined, :pending, :passed, :unknown].freeze

def self.ok?(type, be_strict = false)
private
Expand Down Expand Up @@ -124,6 +124,15 @@ def with_filtered_backtrace(filter)
end
end

# Flaky is not used directly as an execution result, but is used as a
# reporting result type for test cases that fails and the passes on
# retry, therefore only the class method self.ok? is needed.
class Flaky
def self.ok?(be_strict = false)
!be_strict
end
end

# Base class for exceptions that can be raised in a step definition causing
# the step to have that result.
class Raisable < StandardError
Expand Down Expand Up @@ -268,6 +277,10 @@ def total(for_status = nil)
end
end

def decrement_failed
@totals[:failed] -= 1
end

private

def get_total(method_name)
Expand Down
10 changes: 10 additions & 0 deletions spec/cucumber/core/report/summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ module Cucumber::Core::Report
expect( @summary.test_cases.total(:undefined) ).to eq(1)
expect( @summary.test_cases.total ).to eq(1)
end

it "handles flaky test cases" do
allow(test_case).to receive(:==).and_return(false, true)
event_bus.send(:test_case_finished, test_case, failed_result)
event_bus.send(:test_case_finished, test_case, passed_result)

expect( @summary.test_cases.total(:failed) ).to eq(0)
expect( @summary.test_cases.total(:flaky) ).to eq(1)
expect( @summary.test_cases.total ).to eq(1)
end
end

context "test step summary" do
Expand Down
17 changes: 17 additions & 0 deletions spec/cucumber/core/test/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Cucumber::Core::Test
specify { expect( result ).not_to be_undefined }
specify { expect( result ).not_to be_unknown }
specify { expect( result ).not_to be_skipped }
specify { expect( result ).not_to be_flaky }

specify { expect( result ).to be_ok }
specify { expect( result.ok?(false) ).to be_truthy }
Expand Down Expand Up @@ -105,6 +106,7 @@ module Cucumber::Core::Test
specify { expect( result ).not_to be_undefined }
specify { expect( result ).not_to be_unknown }
specify { expect( result ).not_to be_skipped }
specify { expect( result ).not_to be_flaky }

specify { expect( result ).to_not be_ok }
specify { expect( result.ok?(false) ).to be_falsey }
Expand All @@ -130,6 +132,7 @@ module Cucumber::Core::Test
specify { expect( result ).not_to be_undefined }
specify { expect( result ).to be_unknown }
specify { expect( result ).not_to be_skipped }
specify { expect( result ).not_to be_flaky }
end

describe Result::Raisable do
Expand Down Expand Up @@ -196,6 +199,7 @@ module Cucumber::Core::Test
specify { expect( result ).to be_undefined }
specify { expect( result ).not_to be_unknown }
specify { expect( result ).not_to be_skipped }
specify { expect( result ).not_to be_flaky }

specify { expect( result ).to be_ok }
specify { expect( result.ok?(false) ).to be_truthy }
Expand All @@ -218,6 +222,7 @@ module Cucumber::Core::Test
specify { expect( result ).not_to be_undefined }
specify { expect( result ).not_to be_unknown }
specify { expect( result ).to be_skipped }
specify { expect( result ).not_to be_flaky }

specify { expect( result ).to be_ok }
specify { expect( result.ok?(false) ).to be_truthy }
Expand All @@ -240,13 +245,19 @@ module Cucumber::Core::Test
specify { expect( result ).not_to be_undefined }
specify { expect( result ).not_to be_unknown }
specify { expect( result ).not_to be_skipped }
specify { expect( result ).not_to be_flaky }
specify { expect( result ).to be_pending }

specify { expect( result ).to be_ok }
specify { expect( result.ok?(false) ).to be_truthy }
specify { expect( result.ok?(true) ).to be_falsey }
end

describe Result::Flaky do
specify { expect( Result::Flaky.ok?(false) ).to be_truthy }
specify { expect( Result::Flaky.ok?(true) ).to be_falsey }
end

describe Result::Summary do
let(:summary) { Result::Summary.new }
let(:failed) { Result::Failed.new(Result::Duration.new(10), exception) }
Expand Down Expand Up @@ -357,6 +368,12 @@ def describe_to(visitor, *args)
expect( summary.ok? ).to be true
expect( summary.ok?(true) ).to be false
end

it "flaky result is ok if not strict" do
summary.flaky
expect( summary.ok? ).to be true
expect( summary.ok?(true) ).to be false
end
end
end

Expand Down