Skip to content

Instantly share code, notes, and snippets.

@everzet
Created April 22, 2011 09:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everzet/936365 to your computer and use it in GitHub Desktop.
Save everzet/936365 to your computer and use it in GitHub Desktop.
REST API feature example
Feature: REST API
In order to be able to build my own tool for web application
As a developer
I need to have clean REST API for application
Scenario: List all users
Given application has users:
| name | email |
| ivan | ivan@ex.com |
| dima | dima@ex.com |
When I request /users.json
Then I should get a response:
"""
[
{ name: "ivan", email: "ivan@ex.com" },
{ name: "dima", email: "dima@ex.com" }
]
"""
<?php
$steps->Given('/^application has users\:$/', function($world, $users) {
// write users to the DB
});
$steps->When('/^I request (.*)\.(json|xml)$/', function($world, $page, $type) {
$world->response = /* make request to $page.$type */;
$world->responseType = $type;
});
$steps->Then('/^I should get a response\:$/', function ($world, $response) {
switch ($world->responseType) {
case 'json': assertEquals(json_decode($response), json_decode($world->response)); break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment