Skip to content

Commit

Permalink
Update Schema to reject invalid steps
Browse files Browse the repository at this point in the history
  • Loading branch information
TimotheeVille committed Apr 2, 2021
1 parent f431168 commit e56e003
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 20 deletions.
45 changes: 25 additions & 20 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
}
},
"optional": true
},
"step": {
"type": "object",
"properties": {
"keyword": {
"type": "string"
},
"name": {
"type": "string"
},
"result": {
"type": "object",
"properties": {
"status": {
"type": "string"
},
"duration": {
"type": "number"
}
},
"required": ["status"]
}
},
"required": ["keyword"]
}
},
"type": "array",
Expand Down Expand Up @@ -46,26 +70,7 @@
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"keyword": {
"type": "string"
},
"name": {
"type": "string"
},
"result": {
"type": "object",
"properties": {
"status": {
"type": "string"
},
"duration": {
"type": "number"
}
}
}
}
"$ref": "#/definitions/step"
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions spec/schema_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@
end
end
end

describe 'step' do
it 'rejects when there is no status' do
step_without_status_result = JSON.parse(File.read('testdata/invalid/step_without_status.json'))

expect(schemer.valid?(step_without_status_result)).to be_falsy
end

it 'rejects when there is no keyword' do
step_without_keyword_result = JSON.parse(File.read('testdata/invalid/step_without_keyword.json'))

expect(schemer.valid?(step_without_keyword_result)).to be_falsy
end
end
end
34 changes: 34 additions & 0 deletions testdata/invalid/step_without_keyword.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"description": " Here is a description",
"elements": [
{
"description": "",
"id": ";",
"keyword": "Scenario",
"line": 7,
"name": "",
"steps": [
{
"line": 8,
"match": {
"location": "Steps.java:17"
},
"name": "this step passes",
"result": {
"duration": 110881,
"status": "passed"
}
}
],
"type": "scenario"
}
],
"id": "",
"keyword": "Feature",
"line": 1,
"name": "",
"tags": [],
"uri": "features/step_without_keyword.feature"
}
]
34 changes: 34 additions & 0 deletions testdata/invalid/step_without_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"description": " Here is a description",
"elements": [
{
"description": "",
"id": ";",
"keyword": "Scenario",
"line": 7,
"name": "",
"steps": [
{
"keyword": "Given ",
"line": 8,
"match": {
"location": "Steps.java:17"
},
"name": "this step passes",
"result": {
"duration": 110881
}
}
],
"type": "scenario"
}
],
"id": "",
"keyword": "Feature",
"line": 1,
"name": "",
"tags": [],
"uri": "features/step_without_status.feature"
}
]

0 comments on commit e56e003

Please sign in to comment.