Skip to content

Commit

Permalink
Merge #695: Support embedding data directly in gherkin formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson committed Aug 25, 2014
2 parents 4b2b948 + ffc692b commit 50668e4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
59 changes: 59 additions & 0 deletions features/json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Feature: JSON output formatter
Given /^I print from step definition/ do
puts "from step definition"
end
Given /^I embed data directly/ do
data = "YWJj"
embed data, "mime-type;base64"
end
"""
And a file named "features/embed.feature" with:
"""
Expand Down Expand Up @@ -89,6 +94,14 @@ Feature: JSON output formatter
| passing |
"""
And a file named "features/embed_data_directly.feature" with:
"""
Feature: An embed data directly feature
Scenario:
Given I embed data directly
"""

# Need to investigate why this won't pass in-process. error_message doesn't get det?
@spawn
Expand Down Expand Up @@ -422,6 +435,52 @@ Feature: JSON output formatter
}
]
"""
Scenario: embedding data directly
When I run `cucumber -b --format json features/embed_data_directly.feature`
Then it should pass with JSON:
"""
[
{
"uri": "features/embed_data_directly.feature",
"id": "an-embed-data-directly-feature",
"keyword": "Feature",
"name": "An embed data directly feature",
"line": 1,
"description": "",
"elements": [
{
"id": "an-embed-data-directly-feature;",
"keyword": "Scenario",
"name": "",
"line": 3,
"description": "",
"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
}
}
]
}
]
}
]
"""
@spawn
Scenario: scenario outline
Expand Down
11 changes: 10 additions & 1 deletion lib/cucumber/formatter/gherkin_formatter_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ def after_features(features)
end

def embed(file, mime_type, label)
data = File.open(file, 'rb') { |f| f.read }
if File.file?(file)
data = File.open(file, 'rb') { |f| f.read }
else
if mime_type =~ /;base64$/
mime_type = mime_type[0..-8]
data = Base64.decode64(file)
else
data = file
end
end
if defined?(JRUBY_VERSION)
data = data.to_java_bytes
end
Expand Down

0 comments on commit 50668e4

Please sign in to comment.