Skip to content

Instantly share code, notes, and snippets.

@jordelver
Created May 3, 2012 23:50
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 jordelver/2590504 to your computer and use it in GitHub Desktop.
Save jordelver/2590504 to your computer and use it in GitHub Desktop.
Custom must_be_json minitest assertion / expectation for use with rack-test
module MiniTest::Assertions
def assert_content_type_is_json(response)
content_type = response.headers['Content-Type']
assert_equal 'application/json;charset=utf-8', content_type
end
end
module MiniTest::Expectations
infect_an_assertion :assert_content_type_is_json, :must_be_json, :unary
end
# Assertion
assert_content_type_is_json expected, last_response
# Expectation
last_response.must_be_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment