Skip to content

Commit

Permalink
Handle more than one Examples table in a Scenario Outline
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson authored and mattwynne committed Aug 6, 2014
1 parent 2bc685f commit 3bc8d70
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 28 deletions.
65 changes: 57 additions & 8 deletions features/docs/formatters/json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ Feature: JSON output formatter
Scenario Outline: outline
Given a <type> step
Examples: examples
Examples: examples1
| type |
| passing |
| failing |
Examples: examples2
| type |
| passing |
"""

# Need to investigate why this won't pass in-process. error_message doesn't get det?
Expand Down Expand Up @@ -604,31 +608,54 @@ Feature: JSON output formatter
"examples": [
{
"keyword": "Examples",
"name": "examples",
"name": "examples1",
"line": 6,
"description": "",
"id": "an-outline-feature;outline;examples",
"id": "an-outline-feature;outline;examples1",
"rows": [
{
"cells": [
"type"
],
"line": 7,
"id": "an-outline-feature;outline;examples;1"
"id": "an-outline-feature;outline;examples1;1"
},
{
"cells": [
"passing"
],
"line": 8,
"id": "an-outline-feature;outline;examples;2"
"id": "an-outline-feature;outline;examples1;2"
},
{
"cells": [
"failing"
],
"line": 9,
"id": "an-outline-feature;outline;examples;3"
"id": "an-outline-feature;outline;examples1;3"
}
]
},
{
"keyword": "Examples",
"name": "examples2",
"line": 11,
"description": "",
"id": "an-outline-feature;outline;examples2",
"rows": [
{
"cells": [
"type"
],
"line": 12,
"id": "an-outline-feature;outline;examples2;1"
},
{
"cells": [
"passing"
],
"line": 13,
"id": "an-outline-feature;outline;examples2;2"
}
]
}
Expand All @@ -654,7 +681,7 @@ Feature: JSON output formatter
"description": "",
"elements": [
{
"id": "an-outline-feature;outline;examples;2",
"id": "an-outline-feature;outline;examples1;2",
"keyword": "Scenario Outline",
"name": "outline",
"line": 8,
Expand All @@ -676,7 +703,7 @@ Feature: JSON output formatter
]
},
{
"id": "an-outline-feature;outline;examples;3",
"id": "an-outline-feature;outline;examples1;3",
"keyword": "Scenario Outline",
"name": "outline",
"line": 9,
Expand All @@ -697,6 +724,28 @@ Feature: JSON output formatter
}
}
]
},
{
"id": "an-outline-feature;outline;examples2;2",
"keyword": "Scenario Outline",
"name": "outline",
"line": 13,
"description": "",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a passing step",
"line": 4,
"match": {
"location": "features/step_definitions/steps.rb:1"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
}
]
}
Expand Down
43 changes: 23 additions & 20 deletions lib/cucumber/formatter/gherkin_formatter_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def before_feature_element(feature_element)
when Core::Ast::ScenarioOutline
@outline = true
if @options[:expand]
@in_instantiated_scenario = false
@current_scenario_hash = to_hash(feature_element.gherkin_statement)
else
@gf.scenario_outline(feature_element.gherkin_statement)
Expand All @@ -41,27 +42,31 @@ def before_feature_element(feature_element)

def scenario_name(keyword, name, file_colon_line, source_indent)
if @outline and @options[:expand]
@example_row = @example_row ? @example_row + 1 : 0
if in_instantiated_scenario?
example_row_hash = @current_example_rows[@example_row].to_hash
scenario = Gherkin::Formatter::Model::Scenario.new(
@current_scenario_hash['comments'],
@current_scenario_hash['tags'],
@current_scenario_hash['keyword'],
@current_scenario_hash['name'],
@current_scenario_hash['description'],
example_row_hash['line'],
example_row_hash['id'])
@gf.scenario(scenario)
return if not @in_instantiated_scenario
if @new_example_table
@example_row = 1
@new_example_table = false
else
@example_row += 1
end
example_row_hash = @current_example_rows[@example_row].to_hash
scenario = Gherkin::Formatter::Model::Scenario.new(
@current_scenario_hash['comments'],
@current_scenario_hash['tags'],
@current_scenario_hash['keyword'],
@current_scenario_hash['name'],
@current_scenario_hash['description'],
example_row_hash['line'],
example_row_hash['id'])
@gf.scenario(scenario)
end
end

def before_step(step)
unless @outline and @options[:expand]
@gf.step(step.gherkin_statement)
else
if in_instantiated_scenario?
if @in_instantiated_scenario
@current_step_hash = to_hash(step.gherkin_statement)
end
end
Expand Down Expand Up @@ -93,15 +98,15 @@ def before_step_result(keyword, step_match, multiline_arg, status, exception, so
unless @outline
@gf.result(Gherkin::Formatter::Model::Result.new(status, nil, error_message))
else
if @options[:expand] and in_instantiated_scenario?
if @options[:expand] and @in_instantiated_scenario
@current_match = match
@current_result = Gherkin::Formatter::Model::Result.new(status, nil, error_message)
end
end
end

def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
if @outline and @options[:expand] and in_instantiated_scenario?
if @outline and @options[:expand] and @in_instantiated_scenario
@gf.step(Gherkin::Formatter::Model::Step.new(
@current_step_hash['comments'],
@current_step_hash['keyword'],
Expand All @@ -118,14 +123,16 @@ def before_examples(examples)
unless @options[:expand]
@gf.examples(examples.gherkin_statement)
else
@in_instantiated_scenario = true
@new_example_table = true
@current_example_rows = to_hash(examples.gherkin_statement)['rows']
end
end

#used for capturing duration
def after_step(step)
step_finish = (Time.now - @step_time)
unless @outline and @options[:expand] and not in_instantiated_scenario?
unless @outline and @options[:expand] and not @in_instantiated_scenario
@gf.append_duration(step_finish)
end
end
Expand Down Expand Up @@ -156,10 +163,6 @@ def puts(message)

private

def in_instantiated_scenario?
@example_row > 0
end

def to_hash(gherkin_statement)
if defined?(JRUBY_VERSION)
gherkin_statement.toMap()
Expand Down

0 comments on commit 3bc8d70

Please sign in to comment.