Skip to content

Commit

Permalink
Migrate JSON features over to aruba_features
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Nov 12, 2010
1 parent 7263571 commit d693314
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 511 deletions.
11 changes: 11 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
== In Git

=== Changed Features
* New "schema" for JSON output. See New Features. (Aslak Hellesøy)

=== New Features
* JSON output now contains optional "match", "result" and "embeddings" elements underneath each step. (Aslak Hellesøy)

=== Removed Features
* Removed json_pretty formatter. If you really need the pretty, indented output - prettify it yourself. (Aslak Hellesøy)

== 0.9.3 (2010-10-24)

=== Bugfixes
Expand Down
10 changes: 0 additions & 10 deletions aruba_features/background.feature
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ Feature: backgrounds
2 steps (2 passed)
0m0.012s
"""

Scenario: run a feature with a background that passes
Expand All @@ -225,7 +224,6 @@ Feature: backgrounds
4 steps (4 passed)
0m0.012s
"""

Scenario: run a feature with scenario outlines that has a background that passes
Expand Down Expand Up @@ -255,7 +253,6 @@ Feature: backgrounds
4 steps (4 passed)
0m0.012s
"""

Scenario: run a feature with scenario outlines that has a background that passes
Expand All @@ -279,7 +276,6 @@ Feature: backgrounds
2 steps (2 passed)
0m0.012s
"""

Scenario: run a feature with a background that fails
Expand Down Expand Up @@ -309,7 +305,6 @@ Feature: backgrounds
6 steps (1 failed, 5 skipped)
0m0.012s
"""

Scenario: run a feature with scenario outlines that has a background that fails
Expand Down Expand Up @@ -346,7 +341,6 @@ Feature: backgrounds
4 steps (1 failed, 3 skipped)
0m0.012s
"""

Scenario: run a feature with a background that is pending
Expand All @@ -368,7 +362,6 @@ Feature: backgrounds
4 steps (2 skipped, 2 undefined)
0m0.012s
"""

Scenario: background passes with first scenario but fails with second
Expand Down Expand Up @@ -399,7 +392,6 @@ Feature: backgrounds
6 steps (1 failed, 1 skipped, 4 passed)
0m0.012s
"""

Scenario: background with multline args
Expand Down Expand Up @@ -460,7 +452,6 @@ Feature: backgrounds
8 steps (8 passed)
0m0.012s
"""

Scenario: https://rspec.lighthouseapp.com/projects/16211/tickets/329
Expand Down Expand Up @@ -504,5 +495,4 @@ Feature: backgrounds
1 step (1 passed)
0m0.012s
"""
1 change: 0 additions & 1 deletion aruba_features/custom_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ Feature: Custom Formatter
I'LL USE MY OWN
JUST PRINT ME
"""
241 changes: 241 additions & 0 deletions aruba_features/json_formatter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
Feature: JSON output formatter
In order to simplify processing of Cucumber features and results
Developers should be able to consume features as JSON

Background:
Given a file named "features/one_passing_one_failing.feature" with:
"""
@a
Feature: One passing scenario, one failing scenario
@b
Scenario: Passing
Given a passing step
@c
Scenario: Failing
Given a failing step
"""
And a file named "features/step_definitions/steps.rb" with:
"""
Given /a passing step/ do
#does nothing
end
Given /a failing step/ do
fail
end
Given /a pending step/ do
pending
end
Given /^I add (\d+) and (\d+)$/ do |a,b|
@result = a.to_i + b.to_i
end
Then /^I the result should be (\d+)$/ do |c|
@result.should == c.to_i
end
Then /^I should see/ do |string|
end
Given /^I pass a table argument/ do |table|
end
Given /^I embed a screenshot/ do
File.open("screenshot.png", "w") { |file| file << "foo" }
embed "screenshot.png", "image/png"
end
"""
And a file named "features/embed.feature" with:
"""
Feature: A screenshot feature
Scenario:
Given I embed a screenshot
"""

Scenario: one feature, one passing scenario, one failing scenario
When I run cucumber "--format json features/one_passing_one_failing.feature"
Then the output should match /^\{"features":\[/

Scenario: one feature, one passing scenario, one failing scenario
When I run cucumber "--format json features/one_passing_one_failing.feature"
Then it should fail with JSON:
"""
{
"features": [
{
"keyword": "Feature",
"name": "One passing scenario, one failing scenario",
"line": 2,
"description": "",
"tags": [
{
"name": "@a",
"line": 1
}
],
"elements": [
{
"keyword": "Scenario",
"name": "Passing",
"line": 5,
"description": "",
"tags": [
{
"name": "@b",
"line": 4
}
],
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a passing step",
"line": 6,
"match": {
"location": "features/step_definitions/steps.rb:1"
},
"result": {
"status": "passed"
}
}
]
},
{
"keyword": "Scenario",
"name": "Failing",
"line": 9,
"description": "",
"tags": [
{
"name": "@c",
"line": 8
}
],
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a failing step",
"line": 10,
"match": {
"location": "features/step_definitions/steps.rb:5"
},
"result": {
"status": "failed",
"error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/one_passing_one_failing.feature:10:in `Given a failing step'"
}
}
]
}
]
}
]
}
"""

Scenario: pystring
Given a file named "features/pystring.feature" with:
"""
Feature: A py string feature
Scenario:
Then I should see
\"\"\"
a string
\"\"\"
"""
When I run cucumber "--format json features/pystring.feature"
Then it should pass with JSON:
"""
{
"features": [
{
"keyword": "Feature",
"name": "A py string feature",
"line": 1,
"description": "",
"elements": [
{
"keyword": "Scenario",
"name": "",
"line": 3,
"description": "",
"type": "scenario",
"steps": [
{
"keyword": "Then ",
"name": "I should see",
"line": 4,
"multiline_arg": {
"value": "a string",
"line": 5,
"type": "py_string"
},
"match": {
"location": "features/step_definitions/steps.rb:21"
},
"result": {
"status": "passed"
}
}
]
}
]
}
]
}
"""

Scenario: embedding screenshot
When I run cucumber "-b --format json features/embed.feature"
Then it should pass with JSON:
"""
{
"features": [
{
"keyword": "Feature",
"name": "A screenshot feature",
"line": 1,
"description": "",
"elements": [
{
"keyword": "Scenario",
"name": "",
"line": 3,
"description": "",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I embed a screenshot",
"line": 4,
"embeddings": [
{
"mime_type": "image/png",
"data": "Zm9v"
}
],
"match": {
"location": "features/step_definitions/steps.rb:29"
},
"result": {
"status": "passed"
}
}
]
}
]
}
]
}
"""
2 changes: 0 additions & 2 deletions aruba_features/stats_formatters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Feature: Usage formatter
7 steps (7 skipped)
0m0.012s
"""

Scenario: Run with --format stepdefs
Expand All @@ -68,5 +67,4 @@ Feature: Usage formatter
7 steps (7 skipped)
0m0.012s
"""
7 changes: 6 additions & 1 deletion aruba_features/step_definitions/cucumber_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def serialize_feature(cmd)
World(FeatureSerializer)

When /^I run cucumber "([^"]*)"$/ do |cmd|
serialize_feature(cmd)
#serialize_feature(cmd)
run(unescape("cucumber #{cmd}"), false)
end

Then /^it should (pass|fail) with JSON:$/ do |pass_fail, json|
JSON.pretty_generate(JSON.parse(@last_stdout)).should == JSON.pretty_generate(JSON.parse(json))
assert_exiting_with(pass_fail == 'pass')
end
3 changes: 1 addition & 2 deletions aruba_features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
end

AfterStep do
@last_stderr.gsub!(/#{Dir.pwd}\/tmp\/aruba/, '.') if @last_stderr
if @last_stdout
# Remove absolute paths
@last_stdout.gsub!(/#{Dir.pwd}\/tmp\/aruba/, '.')
# Make duration predictable
@last_stdout.gsub!(/^\d+m\d+\.\d+s$/, '0m0.012s') if @last_stdout
# Remove SimpleCov message
@last_stdout.gsub!(/^Coverage report generated for Cucumber Features to #{Dir.pwd}\/coverage$/, '')
@last_stdout.gsub!(/Coverage report generated for Cucumber Features to #{Dir.pwd}\/coverage\n$/, '')
end
end
2 changes: 1 addition & 1 deletion cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for important information about this release. Happy cuking!
}

s.add_dependency 'gherkin', '~> 2.2.9'
s.add_dependency 'gherkin', '~> 2.3.0'
s.add_dependency 'term-ansicolor', '~> 1.0.5'
s.add_dependency 'builder', '~> 2.1.2'
s.add_dependency 'diff-lcs', '~> 1.1.2'
Expand Down
Loading

0 comments on commit d693314

Please sign in to comment.