Skip to content

Instantly share code, notes, and snippets.

@jccarbonfive
Created February 28, 2012 17:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jccarbonfive/1933849 to your computer and use it in GitHub Desktop.
Save jccarbonfive/1933849 to your computer and use it in GitHub Desktop.
Scenario Outline: Make an API request from a different domain
When I ask if a <http-method> request to <api-path> from a different domain is supported
Then I should receive a successful response
And the <http-method> request should be allowed
Scenarios: Available APIs
| http-method | api-path |
| GET | /api/v1/samples |
| GET | /api/v1/samples/1 |
| PUT | /api/v1/samples/1 |
When /^I ask if a (.+) request to (.+) from a different domain is supported$/ do |http_method, api_path|
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
header 'Origin', 'http://example.com'
header 'Access-Control-Request-Method', http_method
header 'Access-Control-Request-Headers', 'Origin, Content-Type, Accept'
options api_path
end
Then /^I should receive a successful response$/ do
last_response.status.should == 200
end
Then /^the (.+) request should be allowed$/ do |http_method|
last_response.headers['Access-Control-Allow-Origin'].should == '*'
last_response.headers['Access-Control-Allow-Methods'].should include(http_method)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment