Class: InfinumJsonApiSetup::RSpec::Matchers::JsonBodyMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/infinum_json_api_setup/rspec/matchers/json_body_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ JsonBodyMatcher

Returns a new instance of JsonBodyMatcher.



5
6
7
# File 'lib/infinum_json_api_setup/rspec/matchers/json_body_matcher.rb', line 5

def initialize(parser)
  @parser = parser
end

Instance Method Details

#failure_messageString

Returns:

  • (String)


25
26
27
# File 'lib/infinum_json_api_setup/rspec/matchers/json_body_matcher.rb', line 25

def failure_message
  @error_message || match_failure_message
end

#matches?(response) ⇒ Boolean

Parameters:

  • response (ActionDispatch::TestResponse)

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/infinum_json_api_setup/rspec/matchers/json_body_matcher.rb', line 11

def matches?(response)
  @response = response
  success, result = parser.process(response)

  if success
    process_parsing_result(result)
    body_matches?
  else
    @error_message = result
    false
  end
end