Skip to content

Commit

Permalink
Merge e5b4a21 into 5d41017
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-psarga committed Jan 15, 2020
2 parents 5d41017 + e5b4a21 commit 10999d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/cucumber/core/events.rb
Expand Up @@ -5,6 +5,10 @@ module Cucumber
module Core
module Events

class Envelope < Event.new(:envelope)
attr_reader :envelope
end

# Signals that a gherkin source has been parsed
class GherkinSourceParsed < Event.new(:gherkin_document)
# @return [GherkinDocument] the GherkinDocument Ast Node
Expand Down Expand Up @@ -55,6 +59,7 @@ class TestCaseFinished < Event.new(:test_case, :result)
# that will be used by the {EventBus} by default.
def self.registry
build_registry(
Envelope,
GherkinSourceParsed,
TestCaseStarted,
TestStepStarted,
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/core/gherkin/parser.rb
Expand Up @@ -19,6 +19,7 @@ def initialize(receiver, event_bus, gherkin_query)
def document(document)
messages = ::Gherkin.from_source(document.uri, document.body, gherkin_options(document))
messages.each do |message|
event_bus.envelope(message)
gherkin_query.update(message)
if !message.gherkin_document.nil?
event_bus.gherkin_source_parsed(message.gherkin_document)
Expand Down
14 changes: 14 additions & 0 deletions spec/cucumber/core/gherkin/parser_spec.rb
Expand Up @@ -15,6 +15,7 @@ module Gherkin

before do
allow( event_bus ).to receive(:gherkin_source_parsed)
allow( event_bus).to receive(:envelope)
allow( gherkin_query ).to receive(:update)
end

Expand Down Expand Up @@ -42,6 +43,12 @@ def parse
expect( event_bus ).to receive(:gherkin_source_parsed)
parse
end

it "emits an 'envelope' event for every message produced by Gherkin" do
# Only one message emited, there's no pickles generated
expect( event_bus ).to receive(:envelope).once
parse
end
end

context "for empty files" do
Expand Down Expand Up @@ -89,6 +96,13 @@ def self.source(&block)
expect( receiver ).to receive(:pickle)
parse
end

it "emits an 'envelope' event containing the pickle" do
allow( receiver ).to receive(:pickle)
# Once for the gherkin document, once with the pickle
expect( event_bus ).to receive(:envelope).twice
parse
end
end

context "when scenario is inside a rule" do
Expand Down

0 comments on commit 10999d5

Please sign in to comment.