Skip to content

Commit

Permalink
Delay step output until after step has been called. Fixed #804.
Browse files Browse the repository at this point in the history
Delay sending the step output to the gherkin formatter in the
JSONFormatter, until step has been called on the gherkin formatter.
  • Loading branch information
brasmusson committed Feb 14, 2015
1 parent c310824 commit 4cbd35b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
4 changes: 2 additions & 2 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## [In Git](https://github.com/cucumber/cucumber/compare/v1.3.19...v1.3.x-bugfix)

* Your change here?
* Handle step output correctly for Scenario Outlines with the --expand option ([804](https://github.com/cucumber/cucumber/issues/804) @brasmusson)

## [In Git](https://github.com/cucumber/cucumber/compare/v1.3.18...v1.3.19)
## [v1.3.19](https://github.com/cucumber/cucumber/compare/v1.3.18...v1.3.19)

* Update multi_test dependency to prevent crashes on ruby 2.2 when no minitest
or rspec available (@tooky)
Expand Down
70 changes: 67 additions & 3 deletions features/json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ Feature: JSON output formatter
"""
Feature: An embed data directly feature
Scenario Outline:
Given I embed data directly
Examples:
| dummy |
| 1 |
| 2 |
Scenario:
Given I embed data directly
Expand Down Expand Up @@ -437,7 +445,7 @@ Feature: JSON output formatter
"""
Scenario: embedding data directly
When I run `cucumber -b --format json features/embed_data_directly.feature`
When I run `cucumber -b --format json -x features/embed_data_directly.feature`
Then it should pass with JSON:
"""
[
Expand All @@ -449,18 +457,74 @@ Feature: JSON output formatter
"line": 1,
"description": "",
"elements": [
{
"keyword": "Scenario Outline",
"name": "",
"line": 8,
"description": "",
"id": "an-embed-data-directly-feature;;;2",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I embed data directly",
"line": 4,
"embeddings": [
{
"mime_type": "mime-type",
"data": "YWJj"
}
],
"match": {
"location": "features/step_definitions/steps.rb:38"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
},
{
"keyword": "Scenario Outline",
"name": "",
"line": 9,
"description": "",
"id": "an-embed-data-directly-feature;;;3",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I embed data directly",
"line": 4,
"embeddings": [
{
"mime_type": "mime-type",
"data": "YWJj"
}
],
"match": {
"location": "features/step_definitions/steps.rb:38"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
},
{
"id": "an-embed-data-directly-feature;",
"keyword": "Scenario",
"name": "",
"line": 3,
"line": 11,
"description": "",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I embed data directly",
"line": 4,
"line": 12,
"embeddings": [
{
"mime_type": "mime-type",
Expand Down
29 changes: 27 additions & 2 deletions lib/cucumber/formatter/gherkin_formatter_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def initialize(gherkin_formatter, print_empty_match, options)
@gf = gherkin_formatter
@print_empty_match = print_empty_match
@options = options
@delayed_messages = []
@delayed_embeddings = []
end

def before_feature(feature)
Expand All @@ -19,10 +21,12 @@ def before_feature(feature)

def before_background(background)
@outline = false
@delay_output = true
@gf.background(background.gherkin_statement)
end

def before_feature_element(feature_element)
@delay_output = true
case(feature_element)
when Ast::Scenario
@outline = false
Expand Down Expand Up @@ -58,16 +62,20 @@ def scenario_name(keyword, name, file_colon_line, source_indent)
@current_scenario_hash['description'],
example_row_hash['line'],
example_row_hash['id'])
@delay_output = true
@gf.scenario(scenario)
end
end

def before_step(step)
unless @outline and @options[:expand]
@gf.step(step.gherkin_statement)
pass_delayed_output
@delay_output = false
else
if @in_instantiated_scenario
@current_step_hash = to_hash(step.gherkin_statement)
@delay_output = true
end
end
if @print_empty_match
Expand Down Expand Up @@ -114,6 +122,8 @@ def step_name(keyword, step_match, status, source_indent, background, file_colon
@current_step_hash['line'],
@current_step_hash['rows'],
@current_step_hash['doc_string']))
pass_delayed_output
@delay_output = false
@gf.match(@current_match)
@gf.result(@current_result)
end
Expand Down Expand Up @@ -159,11 +169,19 @@ def embed(file, mime_type, label)
if defined?(JRUBY_VERSION)
data = data.to_java_bytes
end
@gf.embedding(mime_type, data)
unless @delay_output
@gf.embedding(mime_type, data)
else
@delayed_embeddings.push [mime_type, data]
end
end

def puts(message)
@gf.write(message)
unless @delay_output
@gf.write(message)
else
@delayed_messages.push message
end
end

private
Expand All @@ -175,6 +193,13 @@ def to_hash(gherkin_statement)
gherkin_statement.to_hash
end
end

def pass_delayed_output
@delayed_messages.each { |message| @gf.write(message) }
@delayed_embeddings.each { |embed_data| @gf.embedding(embed_data[0], embed_data[1]) }
@delayed_messages = []
@delayed_embeddings = []
end
end
end
end

0 comments on commit 4cbd35b

Please sign in to comment.