Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use awesome_print for comparing JSON. Make sure there is always a des…

…cription.
  • Loading branch information...
commit 5343c03cc3e8e60049345cad2902d091cd022e9f 1 parent fd78734
Aslak Hellesøy aslakhellesoy authored
5 Rakefile
View
@@ -19,8 +19,9 @@ begin
gem.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Hellesøy"]
gem.executables = ["gherkin"]
gem.add_dependency "trollop", "~> 1.16.2"
- gem.add_development_dependency 'rspec', '~> 2.0.0.beta.15'
- gem.add_development_dependency "cucumber", "~> 0.8.4"
+ gem.add_development_dependency 'awesome_print', '~> 0.2.1'
+ gem.add_development_dependency 'rspec', '~> 2.0.0.beta.17'
+ gem.add_development_dependency "cucumber", "~> 0.8.5"
gem.add_development_dependency "rake-compiler", "~> 0.7.0" unless defined?(JRUBY_VERSION)
gem.files -= FileList['ikvm/**/*']
29 features/json_formatter.feature
View
@@ -20,6 +20,7 @@ Feature: JSON formatter
"comments": ["# language: no", "# Another comment"],
"keyword": "Egenskap",
"name": "Kjapp",
+ "description": "",
"line": 3,
"uri": "test.feature"
}
@@ -73,16 +74,18 @@ Feature: JSON formatter
"""
{
"type": "feature",
+ "tags": ["@one"],
"keyword": "Feature",
"name": "OH HAI",
- "tags": ["@one"],
+ "description": "",
"line": 2,
"uri": "test.feature",
"elements":[
{
+ "type": "scenario",
"keyword": "Scenario",
"name": "Fujin",
- "type": "scenario",
+ "description": "",
"line": 4,
"steps": [
{
@@ -98,10 +101,11 @@ Feature: JSON formatter
]
},
{
+ "type": "scenario",
"tags": ["@two"],
"keyword": "Scenario",
"name": "_why",
- "type": "scenario",
+ "description": "",
"line": 9,
"steps": [
{
@@ -117,10 +121,11 @@ Feature: JSON formatter
]
},
{
+ "type": "scenario_outline",
"tags": ["@three", "@four"],
"keyword": "Scenario Outline",
"name": "Life",
- "type": "scenario_outline",
+ "description": "",
"line": 14,
"steps": [
{
@@ -135,6 +140,7 @@ Feature: JSON formatter
"tags": ["@five"],
"keyword": "Examples",
"name": "Real life",
+ "description": "",
"line": 18,
"table": [
{
@@ -154,9 +160,10 @@ Feature: JSON formatter
]
},
{
+ "type": "scenario",
"keyword": "Scenario",
"name": "who stole my mojo?",
- "type": "scenario",
+ "description": "",
"line": 23,
"steps": [
{
@@ -179,11 +186,12 @@ Feature: JSON formatter
]
},
{
+ "type": "scenario_outline",
"comments": ["# The"],
"keyword": "Scenario Outline",
- "type": "scenario_outline",
- "line": 32,
"name": "with",
+ "description": "",
+ "line": 32,
"steps": [
{
"comments": ["# all"],
@@ -198,6 +206,7 @@ Feature: JSON formatter
"comments": ["# comments", "# everywhere"],
"keyword": "Examples",
"name": "An example",
+ "description": "",
"line": 38,
"table": [
{
@@ -231,6 +240,7 @@ Feature: JSON formatter
"type": "feature",
"keyword": "Feature",
"name": "Kjapp",
+ "description": "",
"line": 1,
"uri": "test.feature",
"elements": [
@@ -239,6 +249,7 @@ Feature: JSON formatter
"keyword": "Background",
"line": 3,
"name": "No idea what Kjapp means",
+ "description": "",
"steps": [
{
"keyword": "Given ",
@@ -248,9 +259,11 @@ Feature: JSON formatter
]
},
{
+ "type": "scenario",
"comments": ["# Writing JSON by hand sucks"],
"keyword": "Scenario",
- "type": "scenario",
+ "name": "",
+ "description": "",
"line": 7,
"steps": [
{
15 features/step_definitions/json_formatter_steps.rb
View
@@ -1,3 +1,4 @@
+require 'ap' # awesome_print gem
require 'stringio'
require 'gherkin/formatter/json_formatter'
require 'gherkin/listener/formatter_listener'
@@ -17,16 +18,10 @@ def keys
Then /^the outputted JSON should be:$/ do |expected_json|
require 'json'
- expected = JSON.pretty_generate(JSON.parse(expected_json))
- actual = JSON.pretty_generate(JSON.parse(@io.string))
- announce actual
- begin
- actual.should == expected
- rescue # Haven't figured out how to order Hash on JRuby (JSON pure). Retry with possibly worse error message.
- expected = JSON.parse(expected_json)
- actual = JSON.parse(@io.string)
- actual.should == expected
- end
+ announce JSON.pretty_generate(JSON.parse(@io.string))
+ expected = JSON.parse(expected_json).ai
+ actual = JSON.parse(@io.string).ai
+ actual.should == expected
end
18 lib/gherkin/formatter/json_formatter.rb
View
@@ -47,15 +47,15 @@ def eof
def statement_hash(type, statement)
element = {
- 'comments' => statement.comments.map{|comment| comment.value},
- 'tags' => statement.tags.map{|tag| tag.name},
'keyword' => statement.keyword,
'name' => statement.name,
- 'description' => statement.description,
'line' => statement.line,
- 'type' => type
}
- compact(element)
+ element['type'] = type if type
+ element['comments'] = statement.comments.map{|comment| comment.value} if statement.comments && statement.comments.any?
+ element['tags'] = statement.tags.map{|tag| tag.name} if statement.tags && statement.tags.any?
+ element['description'] = statement.description if statement.description
+ element
end
def add_element(type, statement)
@@ -83,7 +83,9 @@ def last_element
def to_hash_array(rows)
rows.map do |row|
- compact({"cells" => row.cells.to_a, "comments" => row.comments.map{|comment| comment.value}, "line" => row.line})
+ e = {"cells" => row.cells.to_a, "line" => row.line}
+ e["comments"] = row.comments.map{|comment| comment.value} if row.comments && row.comments.any?
+ e
end
end
@@ -92,10 +94,6 @@ def step_arg_to_hash(multiline_arg)
multiline_arg = rubify(multiline_arg)
Array === multiline_arg ? {"table" => to_hash_array(multiline_arg) } : { "py_string" => multiline_arg.value }
end
-
- def compact(hash)
- hash.reject{|k,v| [[], "", nil].index(v)}
- end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.