Skip to content

Instantly share code, notes, and snippets.

@lcguida
Created October 23, 2015 15:33
Show Gist options
  • Save lcguida/3c4a2ce6730011a25bd1 to your computer and use it in GitHub Desktop.
Save lcguida/3c4a2ce6730011a25bd1 to your computer and use it in GitHub Desktop.
Custom matcher to verify content type of a request
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