Class: JsonResponseMatchers::Content

Inherits:
Base
  • Object
show all
Defined in:
lib/json_response_matchers/content.rb

Instance Attribute Summary

Attributes inherited from Base

#actual, #expected

Instance Method Summary collapse

Methods inherited from Base

#at_key, #diffable?

Constructor Details

#initialize(expected) ⇒ Content

Returns a new instance of Content.



5
6
7
8
9
10
11
12
# File 'lib/json_response_matchers/content.rb', line 5

def initialize expected
  super
  @exact = true
  if Hash === @expected
    @expected.deep_stringify_keys!
    @exact = false
  end
end

Instance Method Details

#failure_messageObject



14
15
16
# File 'lib/json_response_matchers/content.rb', line 14

def failure_message
  "expected\n    #{@actual}\nto #{@exact ? 'equal' : 'include'}\n    #{@expected}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/json_response_matchers/content.rb', line 19

def matches? actual
  @actual = fetch_from extract_parsed_json_from actual
  @exact ? @actual == @expected : hash_include?
end

#with_full_matchObject



24
25
26
27
# File 'lib/json_response_matchers/content.rb', line 24

def with_full_match
  @exact = true
  self
end