Skip to content

Commit cf4277d

Browse files
Fix dry run with messages (#1540)
* Add support for message formatters with dry runs I've just applied the suggest from @cbochs in #1496 Co-authored-by: Matt Wynne <matt@cucumber.io>
1 parent 3b03852 commit cf4277d

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

CHANGELOG.md

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

1717
### Fixed
1818

19+
- '--dry-run' now supports 'message' based-formatters
20+
([1540](https://github.com/cucumber/cucumber-ruby/pull/1540)
21+
[1496](https://github.com/cucumber/cucumber-ruby/issues/1496)
22+
[1488](https://github.com/cucumber/cucumber-ruby/issues/1488)
23+
[aurelien-reeves](https://github.com/aurelien-reeves))
1924
- Step definitions now uses object instances created in the ParameterType
2025
([1538](https://github.com/cucumber/cucumber-ruby/pull/1538)
2126
[1532](https://github.com/cucumber/cucumber-ruby/issues/1532)
2227
[aurelien-reeves](https://github.com/aurelien-reeves))
23-
- '--dry-run' now supports 'message' based-formatters
24-
([1537](https://github.com/cucumber/cucumber-ruby/pull/1537)
25-
[1496](https://github.com/cucumber/cucumber-ruby/issues/1496)
26-
[1488](https://github.com/cucumber/cucumber-ruby/issues/1488)
27-
[aurelien-reeves](https://github.com/aurelien-reeves))
2828
- `attach` can now handle null bytes in the data.
2929
([1536](https://github.com/cucumber/cucumber-ruby/pull/1536)
3030
[1529](https://github.com/cucumber/cucumber-ruby/issues/1529)

features/docs/cli/dry_run.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ Feature: Dry Run
2626
2727
"""
2828

29+
Scenario: With message formatter
30+
Given a file named "features/test.feature" with:
31+
"""
32+
Feature: test
33+
Scenario:
34+
Given this step passes
35+
"""
36+
And the standard step definitions
37+
When I run `cucumber --dry-run --publish-quiet --format message`
38+
Then it should pass
39+
And output should be valid NDJSON
40+
And the output should contain NDJSON with key "status" and value "SKIPPED"
41+
2942
Scenario: In strict mode
3043
Given a file named "features/test.feature" with:
3144
"""

lib/cucumber/runtime.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,17 @@ def filters # rubocop:disable Metrics/AbcSize
235235
step_match_search = StepMatchSearch.new(@support_code.registry.method(:step_matches), @configuration)
236236
filters << Filters::ActivateSteps.new(step_match_search, @configuration)
237237
@configuration.filters.each { |filter| filters << filter }
238+
238239
unless configuration.dry_run?
239240
filters << Filters::ApplyAfterStepHooks.new(@support_code)
240241
filters << Filters::ApplyBeforeHooks.new(@support_code)
241242
filters << Filters::ApplyAfterHooks.new(@support_code)
242243
filters << Filters::ApplyAroundHooks.new(@support_code)
243-
filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)
244+
end
245+
246+
filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)
247+
248+
unless configuration.dry_run?
244249
filters << Filters::BroadcastTestRunStartedEvent.new(@configuration)
245250
filters << Filters::Quit.new
246251
filters << Filters::Retry.new(@configuration)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'cucumber/formatter/spec_helper'
5+
require 'cucumber/formatter/message'
6+
require 'cucumber/cli/options'
7+
8+
module Cucumber
9+
module Formatter
10+
describe Message do
11+
extend SpecHelperDsl
12+
include SpecHelper
13+
14+
before(:each) do
15+
Cucumber::Term::ANSIColor.coloring = false
16+
@out = StringIO.new
17+
@formatter = Message.new(actual_runtime.configuration.with_options(out_stream: @out))
18+
end
19+
20+
describe 'given a single feature' do
21+
before(:each) do
22+
run_defined_feature
23+
end
24+
25+
describe 'with a scenario' do
26+
define_feature <<-FEATURE
27+
Feature: Banana party
28+
29+
Scenario: Monkey eats banana
30+
Given there are bananas
31+
FEATURE
32+
33+
it 'outputs the undefined step' do
34+
expect(@out.string).to include '"status":"UNDEFINED"'
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end

spec/cucumber/formatter/spec_helper.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ module SpecHelper
2222
def run_defined_feature
2323
define_steps
2424
actual_runtime.visitor = Fanout.new([@formatter])
25-
2625
receiver = Test::Runner.new(event_bus)
27-
filters = [
26+
27+
event_bus.gherkin_source_read(gherkin_doc.uri, gherkin_doc.body)
28+
29+
compile [gherkin_doc], receiver, filters, event_bus
30+
31+
event_bus.test_run_finished
32+
end
33+
34+
def filters
35+
# TODO: Remove duplication with runtime.rb#filters
36+
[
2837
Filters::ActivateSteps.new(
2938
StepMatchSearch.new(actual_runtime.support_code.registry.method(:step_matches), actual_runtime.configuration),
3039
actual_runtime.configuration
@@ -33,11 +42,10 @@ def run_defined_feature
3342
Filters::ApplyBeforeHooks.new(actual_runtime.support_code),
3443
Filters::ApplyAfterHooks.new(actual_runtime.support_code),
3544
Filters::ApplyAroundHooks.new(actual_runtime.support_code),
45+
Filters::BroadcastTestCaseReadyEvent.new(actual_runtime.configuration),
46+
Filters::BroadcastTestRunStartedEvent.new(actual_runtime.configuration),
3647
Filters::PrepareWorld.new(actual_runtime)
3748
]
38-
event_bus.gherkin_source_read(gherkin_doc.uri, gherkin_doc.body)
39-
compile [gherkin_doc], receiver, filters, event_bus
40-
event_bus.test_run_finished
4149
end
4250

4351
require 'cucumber/core/gherkin/document'

0 commit comments

Comments
 (0)