module Seatbelt::AssertContentType

Constants

SUPPORTED_MIME_TYPES

Public Instance Methods

assert_content_type(content_type, header=nil) click to toggle source
# File lib/seatbelt/assert_content_type.rb, line 24
def assert_content_type(content_type, header=nil)
  header = @response.headers["Content-Type"] if header.nil? && @response
  if header
    # assert_match /application\/vnd.ms-excel/, @response.header["Content-Type"]
    assert_match matcher_for(content_type), header
  else
    assert false, "nothing to match against!"
  end
end

Private Instance Methods

matcher_for(content_type) click to toggle source
# File lib/seatbelt/assert_content_type.rb, line 36
def matcher_for(content_type)
  case content_type
  when Regexp
    content_type
  when String
    Regexp.new((SUPPORTED_MIME_TYPES[content_type] || content_type).gsub('+', '\\\+'))
  else
    raise "type unknown: #{content_type}"
  end
end