class JsonMatchers::Assertion

Attributes

matcher[R]
payload[R]
schema_name[R]
schema_path[R]

Public Class Methods

new(schema_name) click to toggle source
# 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

Public Instance Methods

invalid_failure_message() click to toggle source
# 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) click to toggle source
# File lib/json_matchers/assertion.rb, line 14
def valid?(json)
  @payload = Payload.new(json)

  matcher.matches?(payload)
end
valid_failure_message() click to toggle source
# 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

Private Instance Methods

format_json(json) click to toggle source
# File lib/json_matchers/assertion.rb, line 64
def format_json(json)
  JSON.pretty_generate(JSON.parse(json.to_s))
end
last_error_message() click to toggle source
# File lib/json_matchers/assertion.rb, line 56
def last_error_message
  matcher.validation_failure_message
end
schema_body() click to toggle source
# File lib/json_matchers/assertion.rb, line 60
def schema_body
  schema_path.read
end