Class: APIMatchers::HTTPStatusCode::Base

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

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/http_status_code/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/http_status_code/base.rb', line 4

def setup
  @setup
end

Instance Method Details

#expected_status_codeObject

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/api_matchers/http_status_code/base.rb', line 17

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

#find_http_status_code(actual) ⇒ Object

If have some configuration about the method to call on actual that method will be called.



23
24
25
26
27
28
29
# File 'lib/api_matchers/http_status_code/base.rb', line 23

def find_http_status_code(actual)
  if @setup.http_status_method.present?
    actual.send(@setup.http_status_method)
  else
    actual
  end
end

#matches?(actual) ⇒ Boolean

Matches the actual with the expected http status code

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/api_matchers/http_status_code/base.rb', line 12

def matches?(actual)
  @http_status_code = find_http_status_code(actual)
  @http_status_code.equal?(expected_status_code)
end