Class: APIMatchers::ResponseBody::HaveJson

Inherits:
Object
  • Object
show all
Includes:
Core::Parser
Defined in:
lib/api_matchers/response_body/have_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Parser

#json

Constructor Details

#initialize(expected_json) ⇒ HaveJson

Returns a new instance of HaveJson.



7
8
9
# File 'lib/api_matchers/response_body/have_json.rb', line 7

def initialize(expected_json)
  @expected_json = expected_json
end

Instance Attribute Details

#expected_jsonObject (readonly)

Returns the value of attribute expected_json.



5
6
7
# File 'lib/api_matchers/response_body/have_json.rb', line 5

def expected_json
  @expected_json
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



5
6
7
# File 'lib/api_matchers/response_body/have_json.rb', line 5

def response_body
  @response_body
end

Instance Method Details

#failure_messageObject Also known as: failure_message_for_should



17
18
19
# File 'lib/api_matchers/response_body/have_json.rb', line 17

def failure_message
  "expect to have json: '#{expected_json}'. Got: '#{json}'."
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



21
22
23
# File 'lib/api_matchers/response_body/have_json.rb', line 21

def failure_message_when_negated
  "expect to NOT have json: '#{response_body}'."
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/api_matchers/response_body/have_json.rb', line 11

def matches?(actual)
  @response_body = actual

  @expected_json == json
end