Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlzulauf/1892e6c2b822ef75df97 to your computer and use it in GitHub Desktop.
Save carlzulauf/1892e6c2b822ef75df97 to your computer and use it in GitHub Desktop.
Custom RSpec matcher for HTTP status codes
# Usage: expect(response).to have_status(:unauthorized)
RSpec::Matchers.define(:have_status) do |expected|
status_code = case expected
when Symbol
Rack::Utils.status_code(expected)
else
expected
end
match do |actual|
actual.status == status_code
end
failure_message_for_should do |actual|
"expected response status of #{status_code} but got #{actual.status}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment