1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#encoding: utf-8
require 'spec_helper'
require 'gherkin/json_parser'
require 'gherkin/formatter/json_formatter'
module Gherkin
describe JSONParser do
def check_json(json)
io = StringIO.new
f = Formatter::JSONFormatter.new(io)
p = JSONParser.new(f, f)
p.parse(json, 'unknown.json', 0)
expected = JSON.parse(json)
actual = JSON.parse(io.string)
actual.should == expected
end
it "should parse a barely empty feature" do
check_json(%{{
"keyword": "Feature",
"name": "One",
"description": "",
"line" : 3
}})
end
it "should parse feature with tags and one scenario" do
check_json(%{{
"tags": [
{
"name": "@foo",
"line": 22
}
],
"keyword": "Feature",
"name": "One",
"description": "",
"line": 3,
"elements": [
{
"type": "scenario",
"steps": [
{
"name": "Hello",
"multiline_arg": {
"type": "table",
"value": [
{
"cells": ["foo", "bar"]
}
]
}
}
]
}
]
}})
end
it "should parse feature with match, result and embedding" do
check_json(%{{
"tags": [
{
"name": "@foo",
"line": 22
}
],
"keyword": "Feature",
"name": "One",
"description": "",
"line": 3,
"elements": [
{
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a passing step",
"line": 6,
"match": {
"arguments": [
{
"offset": 22,
"val": "cukes"
}
],
"location": "features/step_definitions/steps.rb:1"
},
"result": {
"status": "failed",
"error_message": "You suck",
"duration": -1
},
"embeddings": [
{
"mime_type": "text/plain",
"data": "Tm8sIEknbSBub3QgaW50ZXJlc3RlZCBpbiBkZXZlbG9waW5nIGEgcG93ZXJmdWwgYnJhaW4uIEFsbCBJJ20gYWZ0ZXIgaXMganVzdCBhIG1lZGlvY3JlIGJyYWluLCBzb21ldGhpbmcgbGlrZSB0aGUgUHJlc2lkZW50IG9mIHRoZSBBbWVyaWNhbiBUZWxlcGhvbmUgYW5kIFRlbGVncmFwaCBDb21wYW55Lg=="
}
]
}
]
}
]
}})
end
it "shoud parse a complex feature" do
check_json(fixture("complex.json"))
end
end
end
|