Created
February 27, 2013 16:53
-
-
Save jherdman/5049474 to your computer and use it in GitHub Desktop.
An RSpec matcher for checking HTTP response codes from a Rails Controller
This file contains hidden or 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
RSpec::Matchers.define :have_status_code do |expected| | |
match do |response| | |
response.status == expected | |
end | |
description do | |
"be #{expected} (#{lookup_human_code(expected)})" | |
end | |
failure_message_for_should do |actual| | |
"expected response code to be #{expected} (#{lookup_human_code(expected)}) but was #{response.status} (#{lookup_human_code(response.status)})" | |
end | |
def lookup_human_code(code) | |
Rack::Utils::HTTP_STATUS_CODES[code] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment