4xx test response option for have_http_status

26 views
Skip to first unread message

Joseph Haig

unread,
Feb 26, 2020, 10:36:24 AM2/26/20
to rspec
I am looking at the documentation for the have_http_status matcher here - https://www.rubydoc.info/gems/rspec-rails/RSpec%2FRails%2FMatchers:have_http_status - and I see that there are options to match for 2xx (:success), 3xx (:redirect) and 5xx (:error) but if I use :missing then it matches exactly on a 404 status. Is there any particular reason why there isn't an option for matching a status in the range 400-499? Thanks.

Regards,

Joe

Jon Rowe

unread,
Feb 26, 2020, 11:05:03 AM2/26/20
to rs...@googlegroups.com
Hi Joseph

TL;DR because rails does.

Partly because we take the lead from rails here and provide only some fuzzing around the versions to provide consistency… Rails takes this strict approach because only 404 is missing, most of the other 4xx status codes are other kinds of client errors. I suppose you could argue that 410 (Gone) is missing, but then we get into semantic errors. I can assure you that 401 / 403 is not missing, nor 405 and most definitely not 418. Even if I do sometimes misplace the teapot.

Cheers
Jon Rowe
---------------------------

Joseph Haig

unread,
Feb 26, 2020, 12:02:50 PM2/26/20
to rs...@googlegroups.com
Thanks, Jon. That makes a lot of sense.

I wasn't specifically looking for "missing" but "generic error that isn't a server error". This has made me think a bit more about the exact status code I want and that is probably good practice anyway.

With the Internet of Things it is not too hard to imagine a legitimate use for a 418 status. :-)

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-217-e06f5c2a-aae8-45d0-b63d-12c064648ed3%40jonrowe.co.uk.
Reply all
Reply to author
Forward
0 new messages