Module: RSpecApi::Matchers::ContentType

Included in:
RSpecApi::Matchers
Defined in:
lib/rspec-api/matchers/content_type/matcher.rb,
lib/rspec-api/matchers/content_type/have_content_type.rb

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Instance Method Details

#have_content_type(type = nil) ⇒ Object

Passes if the response headers specify the provided content type

For more examples check have_content_type_spec.rb.

Examples:


# Passes if the headers matches the provided JSON content type
headers ={'Content-Type' => 'application/json; charset=utf-8'}
expect(OpenStruct.new headers: headers).to have_content_type(:json)


15
16
17
18
19
20
21
# File 'lib/rspec-api/matchers/content_type/have_content_type.rb', line 15

def have_content_type(type = nil)
  content_type = case type
    when :json then 'application/json; charset=utf-8'
    when :any then %r{}
  end
  RSpecApi::Matchers::ContentType::Matcher.new content_type
end