Skip to content

Commit

Permalink
Rewrite the Json formatter to use the new formatter api
Browse files Browse the repository at this point in the history
Now the Json formatter will produce usable data for Scenario Outlines
also when not using the --expand option. All executed step will be
reported (that is background steps will be included each time they are
executed). Also hook executions will be reported. Remove the usage of
the Gherkin2 library.
  • Loading branch information
brasmusson committed May 26, 2015
1 parent 73344a5 commit b24c2b4
Show file tree
Hide file tree
Showing 5 changed files with 991 additions and 74 deletions.
119 changes: 57 additions & 62 deletions features/docs/formatters/json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Feature: JSON output formatter
"""

@spawn @wip-jruby
@spawn
Scenario: DocString
Given a file named "features/doc_string.feature" with:
"""
Expand All @@ -285,7 +285,7 @@ Feature: JSON output formatter
And a file named "features/step_definitions/steps.rb" with:
"""
Then /I should fail with/ do |s|
raise s
raise RuntimeError, s
end
"""
When I run `cucumber --format json features/doc_string.feature`
Expand Down Expand Up @@ -333,7 +333,7 @@ Feature: JSON output formatter
]
"""

@spawn
@spawn
Scenario: embedding screenshot
When I run `cucumber -b --format json features/embed.feature`
Then it should pass with JSON:
Expand Down Expand Up @@ -381,6 +381,7 @@ Feature: JSON output formatter
"""

@spawn
Scenario: scenario outline
When I run `cucumber --format json features/outline.feature`
Then it should fail with JSON:
Expand All @@ -395,75 +396,69 @@ Feature: JSON output formatter
"description": "",
"elements": [
{
"id": "an-outline-feature;outline",
"id": "an-outline-feature;outline;examples1;2",
"keyword": "Scenario Outline",
"name": "outline",
"line": 3,
"description": "",
"type": "scenario_outline",
"line": 8,
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "this step <status>",
"line": 4,
"name": "this step passes",
"line": 8,
"match": {
"location": "features/outline.feature:4"
"location": "features/step_definitions/steps.rb:1"
},
"result": {
"status": "passed",
"duration": 1
}
}
],
"examples": [
]
},
{
"id": "an-outline-feature;outline;examples1;3",
"keyword": "Scenario Outline",
"name": "outline",
"description": "",
"line": 9,
"type": "scenario",
"steps": [
{
"keyword": "Examples",
"name": "examples1",
"line": 6,
"description": "",
"id": "an-outline-feature;outline;examples1",
"rows": [
{
"cells": [
"status"
],
"line": 7,
"id": "an-outline-feature;outline;examples1;1"
},
{
"cells": [
"passes"
],
"line": 8,
"id": "an-outline-feature;outline;examples1;2"
},
{
"cells": [
"fails"
],
"line": 9,
"id": "an-outline-feature;outline;examples1;3"
}
]
},
"keyword": "Given ",
"name": "this step fails",
"line": 9,
"match": {
"location": "features/step_definitions/steps.rb:4"
},
"result": {
"status": "failed",
"error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/outline.feature:9:in `Given this step fails'\nfeatures/outline.feature:4:in `Given this step <status>'",
"duration": 1
}
}
]
},
{
"id": "an-outline-feature;outline;examples2;2",
"keyword": "Scenario Outline",
"name": "outline",
"description": "",
"line": 13,
"type": "scenario",
"steps": [
{
"keyword": "Examples",
"name": "examples2",
"line": 11,
"description": "",
"id": "an-outline-feature;outline;examples2",
"rows": [
{
"cells": [
"status"
],
"line": 12,
"id": "an-outline-feature;outline;examples2;1"
},
{
"cells": [
"passes"
],
"line": 13,
"id": "an-outline-feature;outline;examples2;2"
}
]
"keyword": "Given ",
"name": "this step passes",
"line": 13,
"match": {
"location": "features/step_definitions/steps.rb:1"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
}
Expand Down Expand Up @@ -735,7 +730,7 @@ Feature: JSON output formatter
puts "Before hook 2"
embed "src", "mime_type", "label"
end
AfterStep do
puts "AfterStep hook 1"
embed "src", "mime_type", "label"
Expand Down
25 changes: 21 additions & 4 deletions features/lib/support/normalise_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,32 @@ def normalise_json(json)
elements = feature.fetch('elements') { [] }
elements.each do |scenario|
scenario['steps'].each do |step|
if step['result']
expect(step['result']['duration']).to be >= 0
step['result']['duration'] = 1
['steps', 'before', 'after'].each do |type|
if scenario[type]
scenario[type].each do |step_or_hook|
normalise_json_step_or_hook(step_or_hook)
if step_or_hook['after']
step_or_hook['after'].each do |hook|
normalise_json_step_or_hook(hook)
end
end
end
end
end
end
end
end
end

def normalise_json_step_or_hook(step_or_hook)
if step_or_hook['result']
if step_or_hook['result']['duration']
expect(step_or_hook['result']['duration']).to be >= 0
step_or_hook['result']['duration'] = 1
end
end
end

end

World(NormaliseArubaOutput)

Loading

0 comments on commit b24c2b4

Please sign in to comment.