Skip to content

Instantly share code, notes, and snippets.

@fdiasr
Last active June 20, 2016 16:52
Show Gist options
  • Select an option

  • Save fdiasr/242c43608c4612dc4bf8995229252d9e to your computer and use it in GitHub Desktop.

Select an option

Save fdiasr/242c43608c4612dc4bf8995229252d9e to your computer and use it in GitHub Desktop.
Bdd Scenarios Examples
# http://knpuniversity.com/screencast/rest/testing#play
# api/features/programmer.feature
# ...
Scenario: Create a programmer
Given I have the payload:
"""
{
"nickname": "ObjectOrienter",
"avatarNumber" : "2",
"tagLine": "I'm from a test!"
}
"""
When I request "POST /api/programmers"
Then the response status code should be 201
And the "Location" header should be "/api/programmers/ObjectOrienter"
And the "nickname" property should equal "ObjectOrienter"
# ...
Background:
Given the user "weaverryan" exists
# ...
Scenario: GET one programmer
Given the following programmers exist:
| nickname | avatarNumber |
| UnitTester | 3 |
When I request "GET /api/programmers/UnitTester"
Then the response status code should be 200
And the following properties should exist:
"""
nickname
avatarNumber
powerLevel
tagLine
"""
And the "nickname" property should equal "UnitTester"
Scenario: GET a collection of programmers
Given the following programmers exist:
| nickname | avatarNumber |
| UnitTester | 3 |
| CowboyCoder | 5 |
When I request "GET /api/programmers"
Then the response status code should be 200
And the "programmers" property should be an array
And the "programmers" property should contain 2 items
Scenario: Validation errors
Given I have the payload:
"""
{
"avatarNumber" : "2",
"tagLine": "I'm from a test!"
}
"""
When I request "POST /api/programmers"
Then the response status code should be 400
And the following properties should exist:
"""
type
title
errors
"""
And the "errors.nickname" property should exist
But the "errors.avatarNumber" property should not exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment