Skip to content

Commit

Permalink
Fix dry run with messages (#1540)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aurelien-reeves and mattwynne committed May 18, 2021
1 parent 3b03852 commit cf4277d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Fixed

- '--dry-run' now supports 'message' based-formatters
([1540](https://github.com/cucumber/cucumber-ruby/pull/1540)
[1496](https://github.com/cucumber/cucumber-ruby/issues/1496)
[1488](https://github.com/cucumber/cucumber-ruby/issues/1488)
[aurelien-reeves](https://github.com/aurelien-reeves))
- Step definitions now uses object instances created in the ParameterType
([1538](https://github.com/cucumber/cucumber-ruby/pull/1538)
[1532](https://github.com/cucumber/cucumber-ruby/issues/1532)
[aurelien-reeves](https://github.com/aurelien-reeves))
- '--dry-run' now supports 'message' based-formatters
([1537](https://github.com/cucumber/cucumber-ruby/pull/1537)
[1496](https://github.com/cucumber/cucumber-ruby/issues/1496)
[1488](https://github.com/cucumber/cucumber-ruby/issues/1488)
[aurelien-reeves](https://github.com/aurelien-reeves))
- `attach` can now handle null bytes in the data.
([1536](https://github.com/cucumber/cucumber-ruby/pull/1536)
[1529](https://github.com/cucumber/cucumber-ruby/issues/1529)
Expand Down
13 changes: 13 additions & 0 deletions features/docs/cli/dry_run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ Feature: Dry Run
"""

Scenario: With message formatter
Given a file named "features/test.feature" with:
"""
Feature: test
Scenario:
Given this step passes
"""
And the standard step definitions
When I run `cucumber --dry-run --publish-quiet --format message`
Then it should pass
And output should be valid NDJSON
And the output should contain NDJSON with key "status" and value "SKIPPED"

Scenario: In strict mode
Given a file named "features/test.feature" with:
"""
Expand Down
7 changes: 6 additions & 1 deletion lib/cucumber/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,17 @@ def filters # rubocop:disable Metrics/AbcSize
step_match_search = StepMatchSearch.new(@support_code.registry.method(:step_matches), @configuration)
filters << Filters::ActivateSteps.new(step_match_search, @configuration)
@configuration.filters.each { |filter| filters << filter }

unless configuration.dry_run?
filters << Filters::ApplyAfterStepHooks.new(@support_code)
filters << Filters::ApplyBeforeHooks.new(@support_code)
filters << Filters::ApplyAfterHooks.new(@support_code)
filters << Filters::ApplyAroundHooks.new(@support_code)
filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)
end

filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)

unless configuration.dry_run?
filters << Filters::BroadcastTestRunStartedEvent.new(@configuration)
filters << Filters::Quit.new
filters << Filters::Retry.new(@configuration)
Expand Down
40 changes: 40 additions & 0 deletions spec/cucumber/formatter/message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'spec_helper'
require 'cucumber/formatter/spec_helper'
require 'cucumber/formatter/message'
require 'cucumber/cli/options'

module Cucumber
module Formatter
describe Message do
extend SpecHelperDsl
include SpecHelper

before(:each) do
Cucumber::Term::ANSIColor.coloring = false
@out = StringIO.new
@formatter = Message.new(actual_runtime.configuration.with_options(out_stream: @out))
end

describe 'given a single feature' do
before(:each) do
run_defined_feature
end

describe 'with a scenario' do
define_feature <<-FEATURE
Feature: Banana party
Scenario: Monkey eats banana
Given there are bananas
FEATURE

it 'outputs the undefined step' do
expect(@out.string).to include '"status":"UNDEFINED"'
end
end
end
end
end
end
18 changes: 13 additions & 5 deletions spec/cucumber/formatter/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ module SpecHelper
def run_defined_feature
define_steps
actual_runtime.visitor = Fanout.new([@formatter])

receiver = Test::Runner.new(event_bus)
filters = [

event_bus.gherkin_source_read(gherkin_doc.uri, gherkin_doc.body)

compile [gherkin_doc], receiver, filters, event_bus

event_bus.test_run_finished
end

def filters
# TODO: Remove duplication with runtime.rb#filters
[
Filters::ActivateSteps.new(
StepMatchSearch.new(actual_runtime.support_code.registry.method(:step_matches), actual_runtime.configuration),
actual_runtime.configuration
Expand All @@ -33,11 +42,10 @@ def run_defined_feature
Filters::ApplyBeforeHooks.new(actual_runtime.support_code),
Filters::ApplyAfterHooks.new(actual_runtime.support_code),
Filters::ApplyAroundHooks.new(actual_runtime.support_code),
Filters::BroadcastTestCaseReadyEvent.new(actual_runtime.configuration),
Filters::BroadcastTestRunStartedEvent.new(actual_runtime.configuration),
Filters::PrepareWorld.new(actual_runtime)
]
event_bus.gherkin_source_read(gherkin_doc.uri, gherkin_doc.body)
compile [gherkin_doc], receiver, filters, event_bus
event_bus.test_run_finished
end

require 'cucumber/core/gherkin/document'
Expand Down

0 comments on commit cf4277d

Please sign in to comment.