Created
October 23, 2015 15:33
-
-
Save lcguida/3c4a2ce6730011a25bd1 to your computer and use it in GitHub Desktop.
Custom matcher to verify content type of a request
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
RSpec::Matchers.define :have_content_type do |content_type| | |
MIME_TYPES = { json: 'application/json' } | |
match do |response| | |
response_content_type = response.header['Content-Type'] | |
response_content_type.split(";").include?(MIME_TYPES[content_type]) | |
end | |
description do | |
"has #{action} as content type" | |
end | |
failure_message do |response| | |
"response does not have #{content_type} as Content-Type" | |
end | |
failure_message_when_negated do |response| | |
"response has #{content_type} as Content-Type" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment