There are a few libraries now for server side REST testing with cucumber in Ruby. Here's a couple:
The library I've been using for server side REST testing with cucumber is Cucumber-API-Steps.
Here's how I'd write your test using 'cucumber-api-steps' (Recommended):
@success
Scenario: Successfully add to cart
Given I am logged in
When I send a POST request to “/cart/add” with the following:
| item | body |
Then the response status should be “200”
And the JSON response should have "success" with the text "true"
When I send a GET request to “/cart”
Then the response status should be “200”
And the JSON response should be "{'items': ['tv']}"
And here's what my tests look like using 'cucumber-api-steps':
@success
Scenario: Successfully log in
Given I am logged out
When I send a POST request to “/login” with:
| username | katie@gmail.com |
| password | mypassword |
Then the response status should be “200”
And the JSON response should have "firstName" with the text "Katie"
Here's how I'd write your test using 'cucumber-api':
@success
Scenario: Successfully add to cart
Given I am logged in
When I send a POST request to “/cart/add”
And I set JSON request body to '{item: body}'
Then the response status should be “200”
And the response should have key “success” with value “true”
When I send a GET request to “/cart”
Then the response status should be “200”
And the response should follow "{'items': ['tv']}"
And here's what my tests look like using 'cucumber-api':
@success
Scenario: Successfully log in
Given I am logged out
When I send a POST request to “/login” with:
| username | katie@gmail.com |
| password | mypassword |
Then the response status should be “200”
And the response should have key “firstName”
- Note about Cucumber-API: There is no way currently to do
should have key “firstName” with value “Katie”
. The "with value" part has not been done yet.
- Also "Follow" expects a JSON file
Another resource is here, but it is old (2011).