Skip to content

Instantly share code, notes, and snippets.

@aeden
Created November 2, 2010 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aeden/660331 to your computer and use it in GitHub Desktop.
Save aeden/660331 to your computer and use it in GitHub Desktop.
World(Rack::Test::Methods)
Given /^I am a valid API user$/ do
@user = Factory(:user)
authorize(@user.email, @user.password)
end
Given /^I send and accept XML$/ do
header 'Accept', 'text/xml'
header 'Content-Type', 'text/xml'
end
Given /^I send and accept JSON$/ do
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
end
When /^I send a GET request for "([^\"]*)"$/ do |path|
get path
end
When /^I send a POST request to "([^\"]*)" with the following:$/ do |path, body|
post path, body
end
When /^I send a PUT request to "([^\"]*)" with the following:$/ do |path, body|
put path, body
end
When /^I send a DELETE request to "([^\"]*)"$/ do |path|
delete path
end
Then /^the response should be "([^\"]*)"$/ do |status|
last_response.status.should == status.to_i
end
Then /^the XML response should be a "([^\"]*)" array with (\d+) "([^\"]*)" elements$/ do |tag, number_of_children, child_tag|
page = Nokogiri::XML(last_response.body)
page.xpath("//#{tag}/#{child_tag}").length.should == number_of_children.to_i
end
Then /^the JSON response should be an array with (\d+) "([^\"]*)" elements$/ do |number_of_children, name|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == number_of_children.to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment