class EqSchemaOf

Public Class Methods

new(schema_file) click to toggle source
# File lib/itesttool/custom_matchers.rb, line 10
def initialize(schema_file)
  @schema_file = schema_file
end

Public Instance Methods

failure_message_for_should() click to toggle source
# File lib/itesttool/custom_matchers.rb, line 25
  def failure_message_for_should
<<"MSG"

Invalid response body on "#{@schema_file}".
#{@msg}

Body is
====================
#{@body}

#{@schema_file} is
====================
#{File.open(@schema_file).read}

MSG
  end
failure_message_for_should_not() click to toggle source
# File lib/itesttool/custom_matchers.rb, line 42
def failure_message_for_should_not
  "\nValid response body on \"#{@schema_file}\".\n\n"
end
matches?(body) click to toggle source
# File lib/itesttool/custom_matchers.rb, line 13
def matches? (body)
  @body = body
  @msg = ""
  begin
    JSON::Validator.validate!(@schema_file, body)
    true
  rescue JSON::Schema::ValidationError
    @msg = $!.message
    false
  end
end