Skip to content

Commit

Permalink
Let the JSON formatter include data tables. Fixes cucumber#948.
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson committed Feb 18, 2016
1 parent 9d1115c commit b781bbf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -4,6 +4,7 @@

### Bugfixes

* Let the JSON formatter include data tables in the JSON file ([#948](https://github.com/cucumber/cucumber-ruby/issues/948) @brasmusson)
* Stringifying location in the JSON formatter for more consistent json parsing ([949](https://github.com/cucumber/cucumber-ruby/pull/949), [945](https://github.com/cucumber/cucumber-ruby/issues/945) @larryprice)

### Refactoring
Expand Down
7 changes: 7 additions & 0 deletions lib/cucumber/formatter/json.rb
Expand Up @@ -153,6 +153,7 @@ def create_step_hash(step_source)
}
step_hash[:comments] = Formatter.create_comments_array(step_source.comments) unless step_source.comments.empty?
step_hash[:doc_string] = create_doc_string_hash(step_source.multiline_arg) if step_source.multiline_arg.doc_string?
step_hash[:rows] = create_data_table_value(step_source.multiline_arg) if step_source.multiline_arg.data_table?
step_hash
end

Expand All @@ -165,6 +166,12 @@ def create_doc_string_hash(doc_string)
}
end

def create_data_table_value(data_table)
data_table.raw.map do |row|
{ cells: row }
end
end

def add_match_and_result(test_step, result)
@step_or_hook_hash[:match] = create_match_hash(test_step, result)
@step_or_hook_hash[:result] = create_result_hash(result)
Expand Down
42 changes: 42 additions & 0 deletions spec/cucumber/formatter/json_spec.rb
Expand Up @@ -757,6 +757,48 @@ module Formatter
"duration": 1}}]}]}]})
end
end

describe "with a scenario with a step with a data table" do
define_feature <<-FEATURE
Feature: Banana party
Scenario: Monkey eats bananas
Given there are bananas
| aa | bb |
| cc | dd |
FEATURE

define_steps do
Given(/^there are bananas$/) { |s| s }
end

it "includes the doc string in the json data" do
expect(load_normalised_json(@out)).to eq MultiJson.load(%{
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"rows":
[{"cells": ["aa", "bb"]},
{"cells": ["cc", "dd"]}],
"match": {"location": "spec/cucumber/formatter/json_spec.rb:772"},
"result": {"status": "passed",
"duration": 1}}]}]}]})
end
end
end

def load_normalised_json(out)
Expand Down

0 comments on commit b781bbf

Please sign in to comment.