[rspec-users] specifying an HTTP status code

Craig Demyanovich cdemyanovich at gmail.com
Sun Dec 2 08:12:14 EST 2007


On Dec 1, 2007 5:19 PM, Scott Taylor <mailing_lists at railsnewbie.com> wrote:

>
> On Dec 1, 2007, at 5:10 PM, Jarkko Laine wrote:
>
> > On 1.12.2007, at 23.27, Scott Taylor wrote:
> >>  it "should return an HTTP status code of 404" do
> >>    get :view
> >>    response.headers["Status"].should == "404 Not Found"
> >
> > or
> >
> > response.response_code.should == 404
> >
>
> Nice.  I find out something new every day from this list.


You might also look at status_codes.rb. For example, if you have rails in
vendor/rails, it's path is

vendor/rails/actionpack/lib/action_controller/status_codes.rb

For any status in that file, you should be able to do this in your examples:

assert_response :not_found

Yes, that's a Test::Unit assertion. Here's why I use it:

* I'm not sure if there is a way to do it in RSpec (haven't yet
investigated)
* I can use Test::Unit assertions in RSpec (really cool)
* I like the way it reads compared to using the codes, such as 404

Regards,
Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071202/bd0a0834/attachment.html 


More information about the rspec-users mailing list