I am new to rails and rspec. I am trying to write specs for a web
service
written in rails and found that firefox 3.6 makes an OPTIONS call to the
server before making a POST.
I want to write a spec for this behavior but am unable to find any
resource
on how to write a spec for an OPTIONS call. Could someone please help? I
would really appreciate it.
I am working on rails 3 with ruby 1.9.2 and rspec 2.5.2
I am working on rails 3 with ruby 1.9.2 and rspec 2.5.2
thank you
Do you really need to do this? From my cursory look of the w3 spec HTTP/1.1: Method Definitions, the options
command
is all about establishing comms with your server - not your service. So
there is nothing to specify in your service is there! Your not writing
specs for apache, nginx or whatever you have serving your application.
I’m not sure that’s necessarily true - I’ve read of several RESTful
APIs using OPTIONS to discover more about a resource at a URI. Rails
clearly recognizes the OPTIONS HTTP verb because I get
Started OPTIONS “/” for 127.0.0.1 at Tue May 24 23:38:38 +0530 2011
when I query a standard Rails index action from an interactive console:
Ruby 1.9.2, 2011-02-18, x86_64-darwin10.6.0
Loading Wrest 1.4.4
ruby-1.9.2-p180 :001 > response = ‘http://localhost:3000’.to_uri.options
← (OPTIONS -2038453369797053398 -4029552566690348382) http://localhost:3000/
→ (OPTIONS -2038453369797053398 -4029552566690348382) 200 OK (0 bytes
0.09s)
=> #<Wrest::Native::Response:0x00000100d89ea0
@http_response=#<Net::HTTPOK 200 OK readbody=true>>
ruby-1.9.2-p180 :002 > response.body
=> nil
Interestingly, that same uri does actually have a body when invoked with
a get.
A cursory examination of http://apidock.com/rails/ActionController/TestCase seems to indicate
that there may be no way to write tests for options calls using
standard Rails tests.
‘First, one uses the get, post, put, delete or head method to simulate
an HTTP request.’
I’m not sure that’s necessarily true - I’ve read of several RESTful
APIs using OPTIONS to discover more about a resource at a URI. Rails
clearly recognizes the OPTIONS HTTP verb because I get
Ah do you have any links about this you would recommend? Always
something
new to learn
It was simple enough to add to Rails - I’ve submitted a pull request:
If the pull request isn’t accepted, then it should be easy enough for
me to add it to rspec-rails if David and the rest of the rspec team
thinks that’s an acceptable alternative.