Last active
August 29, 2015 14:03
-
-
Save carlzulauf/1892e6c2b822ef75df97 to your computer and use it in GitHub Desktop.
Custom RSpec matcher for HTTP status codes
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
# 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