Created
February 6, 2014 23:53
-
-
Save melcher/8854953 to your computer and use it in GitHub Desktop.
Adds support for OPTIONS verb testing in rspec-rails Request (integration) tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RequestHelper | |
#... | |
# Add support for testing `options` requests in rspec. | |
# See: https://github.com/rspec/rspec-rails/issues/925 | |
def options(*args) | |
reset! unless integration_session | |
integration_session.__send__(:process, :options, *args).tap do | |
copy_session_variables! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Graham. Thanks for this gist. I'm trying to test CORS as well with RSpec. I'm using the rack-cors gem which requires the
Origin
HTTP header to be passed in the request. My specs are failing and I'm pretty sure it's because I'm not passing in the Origin header correctly. I get the correct HTTP status in the response, so I know it's actually hitting the correct:options
route, but it's not returning anyAccess-Control-Allow
headers, which means that theOrigin
wasn't passed. I've tested it via curl, so I know everything is actually working, so the tests should be passing.Here's how I include the Origin header in a regular
POST
request in an integration spec:When I try the same thing with your
options
method, the Origin header doesn't seem to be recognized:I also tried removing the middle hash, but that didn't work either:
What am I doing wrong?
Thanks!