Skip to content

Commit

Permalink
Delay step output until after step has been called. Fixed #806.
Browse files Browse the repository at this point in the history
Delay sending the step output to the gherkin formatter in the
JSONFormatter, also for Scenario Outlines in expanded mode, until step
has been called on the gherkin formatter.
  • Loading branch information
brasmusson committed Feb 14, 2015
1 parent 9f349da commit ef215e6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
66 changes: 65 additions & 1 deletion features/docs/formatters/json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ Feature: JSON output formatter
Scenario:
Given I embed data directly
Scenario Outline:
Given I embed data directly
Examples:
| dummy |
| 1 |
| 2 |
"""
And a file named "features/out_scenario_out_scenario_outline.feature" with:
"""
Expand Down Expand Up @@ -613,7 +621,7 @@ Feature: JSON output formatter

@spawn
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 Down Expand Up @@ -652,6 +660,62 @@ Feature: JSON output formatter
}
}
]
},
{
"keyword": "Scenario Outline",
"name": "",
"line": 11,
"description": "",
"id": "an-embed-data-directly-feature;;;2",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I embed data directly",
"line": 11,
"embeddings": [
{
"mime_type": "mime-type",
"data": "YWJj"
}
],
"match": {
"location": "features/step_definitions/json_steps.rb:10"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
},
{
"keyword": "Scenario Outline",
"name": "",
"line": 12,
"description": "",
"id": "an-embed-data-directly-feature;;;3",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I embed data directly",
"line": 12,
"embeddings": [
{
"mime_type": "mime-type",
"data": "YWJj"
}
],
"match": {
"location": "features/step_definitions/json_steps.rb:10"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
}
]
}
Expand Down
15 changes: 9 additions & 6 deletions lib/cucumber/formatter/gherkin_formatter_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def before_feature(feature)

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

def before_feature_element(feature_element)
@before_steps = true
case(feature_element)
when Core::Ast::Scenario
@outline = false
Expand All @@ -44,6 +42,10 @@ def before_feature_element(feature_element)
end
end

def before_test_case(test_case)
@delay_output = true
end

def scenario_name(keyword, name, file_colon_line, source_indent)
if @outline and @options[:expand]
return if not @in_instantiated_scenario
Expand All @@ -70,10 +72,11 @@ def before_step(step)
unless @outline and @options[:expand]
@gf.step(step.gherkin_statement)
pass_delayed_output
@before_steps = false
@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 @@ -120,7 +123,7 @@ def step_name(keyword, step_match, status, source_indent, background, file_colon
@current_step_hash['rows'],
@current_step_hash['doc_string']))
pass_delayed_output
@before_steps = false
@delay_output = false
@gf.match(@current_match)
@gf.result(@current_result)
end
Expand Down Expand Up @@ -165,15 +168,15 @@ def embed(file, mime_type, label)
if defined?(JRUBY_VERSION)
data = data.to_java_bytes
end
unless @before_steps
unless @delay_output
@gf.embedding(mime_type, data)
else
@delayed_embeddings.push [mime_type, data]
end
end

def puts(message)
unless @before_steps
unless @delay_output
@gf.write(message)
else
@delayed_messages.push message
Expand Down

0 comments on commit ef215e6

Please sign in to comment.