Class: APIMatchers::Headers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/api_matchers/headers/base.rb

Direct Known Subclasses

BeJSON, BeXML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setup) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/api_matchers/headers/base.rb', line 6

def initialize(setup)
  @setup = setup
end

Instance Attribute Details

#setupObject (readonly)

Returns the value of attribute setup.



4
5
6
# File 'lib/api_matchers/headers/base.rb', line 4

def setup
  @setup
end

Instance Method Details

#content_type_responseObject



16
17
18
19
20
21
22
23
# File 'lib/api_matchers/headers/base.rb', line 16

def content_type_response
  if @setup.header_method.present? and @setup.header_content_type_key.present?
    headers = @actual.send(@setup.header_method)
    headers[@setup.header_content_type_key] || headers if headers.present?
  else
    @actual
  end
end

#expected_content_typeObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/api_matchers/headers/base.rb', line 25

def expected_content_type
  raise NotImplementedError, "not implemented on #{self}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/api_matchers/headers/base.rb', line 10

def matches?(actual)
  @actual = actual

  content_type_response.eql?(expected_content_type)
end