public
Created

api_steps

  • Download Gist
api_steps.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.