Skip to content

Commit bda1990

Browse files
Fix TestRunFinished.success message to return true when the run has passed (#1606)
* Add a reproducible example for #1595 * Make sure module is valid before extending the world with it * Update CHANGELOG.md * Simplify world.feature * Extend the world only if modules.any? * Add reproducible example * Add status of the run when emitting TestRunFinished * Fix TestRunFinished.success message in the message builder * Update CHANGELOG.md * Update example to remove failing step actually not failing * Add newline at the end of the feature file * Make Runtime#failure? a real public method
1 parent 6e6f1a3 commit bda1990

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
1616

1717
### Fixed
1818

19+
- Fix TestRunFinished success property in html formatter and all formatters
20+
based on the messages: it now returns true if the run has passed
21+
([PR#1606](https://github.com/cucumber/cucumber-ruby/pull/1606)
22+
[Issue#1604](https://github.com/cucumber/cucumber-ruby/issues/1604))
23+
1924
- Fix usage of namespaced modules across multiple scenarios
2025
([PR#1603](https://github.com/cucumber/cucumber-ruby/pull/1603)
2126
[Issue#1595](https://github.com/cucumber/cucumber-ruby/issues/1595))

features/docs/formatters/message.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,34 @@ Feature: Message output formatter
4343
testRunFinished
4444
"""
4545

46+
Scenario: it sets "testRunFinished"."success" to false if something failed
47+
Given a file named "features/steps.rb" with:
48+
"""
49+
Given('a passed step') {}
50+
Given('a failed step') { fail }
51+
"""
52+
When I run `cucumber features/my_feature.feature --format message`
53+
Then output should be valid NDJSON
54+
And the output should contain:
55+
"""
56+
{"testRunFinished":{"success":false
57+
"""
58+
59+
Scenario: it sets "testRunFinished"."success" to true if nothing failed
60+
Given a file named "features/my_feature.feature" with:
61+
"""
62+
Feature: Some feature
63+
64+
Scenario Outline: a scenario
65+
Given a passed step
66+
"""
67+
And a file named "features/steps.rb" with:
68+
"""
69+
Given('a passed step') {}
70+
"""
71+
When I run `cucumber features/my_feature.feature --format message`
72+
Then output should be valid NDJSON
73+
And the output should contain:
74+
"""
75+
{"testRunFinished":{"success":true
76+
"""

lib/cucumber/events/test_run_finished.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
module Cucumber
66
module Events
77
# Event fired after all test cases have finished executing
8-
class TestRunFinished < Core::Event.new
8+
class TestRunFinished < Core::Event.new(:success)
9+
attr_reader :success
910
end
1011
end
1112
end

lib/cucumber/formatter/message_builder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ def on_test_case_finished(event)
226226
output_envelope(message)
227227
end
228228

229-
def on_test_run_finished(*)
229+
def on_test_run_finished(event)
230230
message = Cucumber::Messages::Envelope.new(
231231
test_run_finished: Cucumber::Messages::TestRunFinished.new(
232-
timestamp: time_to_timestamp(Time.now)
232+
timestamp: time_to_timestamp(Time.now),
233+
success: event.success
233234
)
234235
)
235236

lib/cucumber/runtime.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def run!
7979

8080
receiver = Test::Runner.new(@configuration.event_bus)
8181
compile features, receiver, filters, @configuration.event_bus
82-
@configuration.notify :test_run_finished
82+
@configuration.notify :test_run_finished, !failure?
8383

8484
fire_after_all_hook unless dry_run?
8585
end
@@ -110,6 +110,14 @@ def doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0
110110
Core::Test::DocString.new(string_without_triple_quotes, content_type)
111111
end
112112

113+
def failure?
114+
if @configuration.wip?
115+
summary_report.test_cases.total_passed > 0
116+
else
117+
!summary_report.ok?(@configuration.strict)
118+
end
119+
end
120+
113121
private
114122

115123
def fire_install_plugin_hook # :nodoc:
@@ -226,15 +234,6 @@ def accept_options?(factory)
226234
factory.instance_method(:initialize).arity > 1
227235
end
228236

229-
def failure?
230-
if @configuration.wip?
231-
summary_report.test_cases.total_passed > 0
232-
else
233-
!summary_report.ok?(@configuration.strict)
234-
end
235-
end
236-
public :failure?
237-
238237
require 'cucumber/core/test/filters'
239238
def filters # rubocop:disable Metrics/AbcSize
240239
tag_expressions = @configuration.tag_expressions

0 commit comments

Comments
 (0)