Skip to content

Instantly share code, notes, and snippets.

@otzy007
Created September 7, 2013 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otzy007/6473493 to your computer and use it in GitHub Desktop.
Save otzy007/6473493 to your computer and use it in GitHub Desktop.
api_steps
Given /^I send and accept JSON$/ do
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
end
Given /the following API Keys exist/ do | keys |
keys.hashes.each do | k |
ApiKey.create! k
end
end
When /^I send a POST request to "([^\"]*)" with the following:$/ do |path, body|
post path, body
end
When /^I send a GET request to "([^\"]*)" with the following:$/ do |path, body|
get path, body
end
When /^I send a DELETE request to "([^\"]*)" with the following:$/ do |path, body|
delete path, body
end
Then /^the response status should be "([^\"]*)"$/ do |status|
last_response.status.should eq(status.to_i)
end
Then /^the response body should be a token$/ do
last_response.body.should include('authentication_token')
last_response.body.should_not include('errors')
end
Then /^the session should be destroyed$/ do
last_response.body.should include("Session destroyed.")
end
Then /^the response body should be an email exists error$/ do
last_response.body.should include("Email already exists")
end
Then /^the response body should be an username exists error$/ do
last_response.body.should include("User name taken. Please choose another one")
end
Then /^the response body should contain an error with the message "([^\"]*)"$/ do |message|
hash = JSON.parse last_response.body
hash['errors'].should include(message)
end
Then /^the response body should contain the message "([^\"]*)"$/ do |message|
JSON.parse(last_response.body)['message'].should eq(message)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment