-
-
Notifications
You must be signed in to change notification settings - Fork 50
Change to use worst Test Step result as the Test Case result #317
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'cucumber/core/test/timer' | ||
| require 'cucumber/messages/helpers/test_step_result_comparator' | ||
|
|
||
| module Cucumber | ||
| module Core | ||
|
|
@@ -45,6 +46,8 @@ def done | |
| end | ||
|
|
||
| class RunningTestCase | ||
| include Cucumber::Messages::Helpers::TestStepResultComparator | ||
|
|
||
| def initialize | ||
| @timer = Timer.new.start | ||
| @status = Status::Unknown.new(Result::Unknown.new) | ||
|
|
@@ -59,27 +62,27 @@ def result | |
| end | ||
|
|
||
| def failed(step_result) | ||
| @status = Status::Failing.new(step_result) | ||
| not_passing(step_result) | ||
| self | ||
| end | ||
|
|
||
| def ambiguous(step_result) | ||
| @status = Status::Ambiguous.new(step_result) | ||
| failed(step_result) | ||
| self | ||
| end | ||
|
|
||
| def passed(step_result) | ||
| @status = Status::Passing.new(step_result) | ||
| @status = Status::Passing.new(step_result) if test_step_result_rankings[step_result.to_message.status] > test_step_result_rankings[status.step_result_message.status] | ||
| self | ||
| end | ||
|
|
||
| def pending(_message, step_result) | ||
| @status = Status::Pending.new(step_result) | ||
| failed(step_result) | ||
| self | ||
| end | ||
|
|
||
| def skipped(step_result) | ||
| @status = Status::Skipping.new(step_result) | ||
| failed(step_result) | ||
| self | ||
| end | ||
|
|
||
|
|
@@ -96,6 +99,13 @@ def duration(_step_duration, _step_result) | |
| self | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def not_passing(step_result) | ||
| @status = Status::NotPassing.new(step_result) if test_step_result_rankings[step_result.to_message.status] > test_step_result_rankings[status.step_result_message.status] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see we have status defined as an iVar and I assume it's defined somewhere in here, but I can't see it. |
||
| self | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this self call is needed here, as the not_passing invocation returns self afterwards |
||
| end | ||
|
|
||
| attr_reader :status | ||
| private :status | ||
|
|
||
|
|
@@ -118,6 +128,10 @@ def execute(test_step, monitor, &) | |
| def result | ||
| raise NoMethodError, 'Override me' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot see where |
||
| end | ||
|
|
||
| def step_result_message | ||
| step_result.to_message | ||
| end | ||
| end | ||
|
|
||
| class Unknown < Base | ||
|
|
@@ -132,26 +146,14 @@ def result(duration) | |
| end | ||
| end | ||
|
|
||
| class Failing < Base | ||
| class NotPassing < Base | ||
| def execute(test_step, monitor) | ||
| result = test_step.skip(monitor.result) | ||
| if result.undefined? | ||
| result = result.with_message(%(Undefined step: "#{test_step.text}")) | ||
| result = result.with_appended_backtrace(test_step) | ||
| end | ||
| result | ||
| end | ||
|
|
||
| def result(duration) | ||
| step_result.with_duration(duration) | ||
| result = result.with_message(%(Undefined step: "#{test_step.text}")) if result.undefined? | ||
|
luke-hill marked this conversation as resolved.
|
||
| result = result.with_appended_backtrace(test_step) unless test_step.hook? | ||
| result.describe_to(monitor, result) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the bit that does the magic stuff? I know these methods are a bit obscure for me
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The important here is that the only difference between After calling
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this "repeated" rewriting / over assignment is possible because a lot of the describe and other methods are returning |
||
| end | ||
| end | ||
|
|
||
| Pending = Class.new(Failing) | ||
|
|
||
| Ambiguous = Class.new(Failing) | ||
|
|
||
| class Skipping < Failing | ||
| def result(duration) | ||
| step_result.with_duration(duration) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,6 +250,105 @@ | |
| test_case.describe_to(runner) | ||
| end | ||
| end | ||
|
|
||
| context 'with an initial undefined step' do | ||
| let(:test_steps) { [undefined_step, passing_step] } | ||
|
|
||
| it 'emits a test_step_finished event with an undefined result' do | ||
| expect(event_bus).to receive(:test_step_finished).with(undefined_step, anything) do |_reported_test_case, result| | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is Or are we simply saying here it's irrelevant what it receives. Wouldn't it be a passing step due to line 255? |
||
| expect(result).to be_undefined | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'emits a test_step_finished event with a skipped result' do | ||
| expect(event_bus).to receive(:test_step_finished).with(passing_step, anything) do |_reported_test_case, result| | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't all these shadowing wrapper methods be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I think this actually should be an ordered set of results. Maybe like here? https://github.com/site-prism/site_prism/blob/v2.15.1/spec/sections_spec.rb#L50-L55 |
||
| expect(result).to be_skipped | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'emits a test_case_finished event with an undefined result' do | ||
| allow(event_bus).to receive(:test_case_finished) do |_reported_test_case, result| | ||
| expect(result).to be_undefined | ||
| expect(result.exception).to be_a StandardError | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'skips, rather than executing the second step' do | ||
| expect(passing_step).not_to receive(:execute) | ||
|
|
||
| allow(passing_step).to receive(:skip).and_return(Cucumber::Core::Test::Result::Skipped.new) | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| context 'with a following ambiguous step' do | ||
| let(:test_steps) { [undefined_step, ambiguous_step] } | ||
|
|
||
| it 'emits a test_step_finished event with an undefined result' do | ||
| expect(event_bus).to receive(:test_step_finished).with(undefined_step, anything) do |_reported_test_case, result| | ||
| expect(result).to be_undefined | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'emits a test_step_finished event with a ambiguous result' do | ||
| expect(event_bus).to receive(:test_step_finished).with(ambiguous_step, anything) do |_reported_test_case, result| | ||
| expect(result).to be_ambiguous | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'emits a test_case_finished event with an ambiguous result' do | ||
| allow(event_bus).to receive(:test_case_finished) do |_reported_test_case, result| | ||
| expect(result).to be_ambiguous | ||
| expect(result.exception).to be_a StandardError | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'skips, rather than executing the second step' do | ||
| expect(ambiguous_step).not_to receive(:execute) | ||
|
|
||
| allow(ambiguous_step).to receive(:skip).and_return(Cucumber::Core::Test::Result::Ambiguous.new) | ||
| test_case.describe_to(runner) | ||
| end | ||
| end | ||
|
|
||
| context 'with a failing after hook' do | ||
| let(:test_steps) { [undefined_step, failing_hook] } | ||
|
|
||
| it 'emits a test_step_finished event with an undefined result' do | ||
| expect(event_bus).to receive(:test_step_finished).with(undefined_step, anything) do |_reported_test_case, result| | ||
| expect(result).to be_undefined | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'emits a test_step_finished event with a failing result' do | ||
| expect(event_bus).to receive(:test_step_finished).with(failing_hook, anything) do |_reported_test_case, result| | ||
| expect(result).to be_failed | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'emits a test_case_finished event with an failing result' do | ||
| allow(event_bus).to receive(:test_case_finished) do |_reported_test_case, result| | ||
| expect(result).to be_failed | ||
| expect(result.exception).to be_a StandardError | ||
| end | ||
| test_case.describe_to(runner) | ||
| end | ||
|
|
||
| it 'call skip, rather than execute on test step of the hook' do | ||
| expect(failing_hook).not_to receive(:execute) | ||
|
|
||
| allow(failing_hook).to receive(:skip).and_return(Cucumber::Core::Test::Result::Failed.new(Cucumber::Core::Test::Result::UnknownDuration.new, instance_double(StandardError, backtrace: []))) | ||
| test_case.describe_to(runner) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'with multiple test cases' do | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.