Created
April 22, 2011 09:50
-
-
Save everzet/936365 to your computer and use it in GitHub Desktop.
REST API feature example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | [email protected] | | |
| dima | [email protected] | | |
When I request /users.json | |
Then I should get a response: | |
""" | |
[ | |
{ name: "ivan", email: "[email protected]" }, | |
{ name: "dima", email: "[email protected]" } | |
] | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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