Skip to content

Commit

Permalink
Merge #141 'Add a flaky result type to be used for flaky scenarios'
Browse files Browse the repository at this point in the history
Also update History.md.
  • Loading branch information
brasmusson committed Jul 16, 2017
2 parents f23f5b6 + 1a37222 commit ce60172
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### New Features

* Add a flaky result type to be used for flaky scenarios ([#141](https://github.com/cucumber/cucumber-ruby-core/pull/141), [cucumber/cucumber-ruby#1044](https://github.com/cucumber/cucumber-ruby/issues/1044) @brasmusson)
* Make the Summary report able to say if the total result is ok ([#140](https://github.com/cucumber/cucumber-ruby-core/pull/140) @brasmusson)
* Replay previous events to new subscribers ([#136](https://github.com/cucumber/cucumber-ruby-core/pull/136) @mattwynne)
* Ruby 2.4.0 compatability ([#120](https://github.com/cucumber/cucumber-ruby-core/pull/120) @junaruga)
Expand Down
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

0 comments on commit ce60172

Please sign in to comment.