Class: JsonMatchers::Assertion

Inherits:
Object
  • Object
show all
Defined in:
lib/json_matchers/assertion.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_name) ⇒ Assertion

Returns a new instance of Assertion.



8
9
10
11
12
# File 'lib/json_matchers/assertion.rb', line 8

def initialize(schema_name)
  @schema_name = schema_name.to_s
  @schema_path = JsonMatchers.path_to_schema(schema_name)
  @matcher = Matcher.new(schema_path)
end

Instance Method Details

#invalid_failure_messageObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/json_matchers/assertion.rb', line 36

def invalid_failure_message
  <<-FAIL
#{last_error_message}

---

expected

#{format_json(payload)}

not to match schema "#{schema_name}":

#{format_json(schema_body)}
  FAIL
end

#valid?(json) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/json_matchers/assertion.rb', line 14

def valid?(json)
  @payload = Payload.new(json)

  matcher.matches?(payload)
end

#valid_failure_messageObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/json_matchers/assertion.rb', line 20

def valid_failure_message
  <<-FAIL
#{last_error_message}

---

expected

#{format_json(payload)}

to match schema "#{schema_name}":

#{format_json(schema_body)}
  FAIL
end