Class: EqSchemaOf

Inherits:
Object
  • Object
show all
Defined in:
lib/itesttool/custom_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_file) ⇒ EqSchemaOf

Returns a new instance of EqSchemaOf.



10
11
12
# File 'lib/itesttool/custom_matchers.rb', line 10

def initialize(schema_file)
  @schema_file = schema_file
end

Instance Method Details

#failure_message_for_shouldObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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_notObject



42
43
44
# 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) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# 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