Class: EqSchemaOf
- Inherits:
-
Object
- Object
- EqSchemaOf
- Defined in:
- lib/itesttool/custom_matchers.rb
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(schema_file) ⇒ EqSchemaOf
constructor
A new instance of EqSchemaOf.
- #matches?(body) ⇒ Boolean
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_should ⇒ Object
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 <<"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 ⇒ Object
42 43 44 |
# File 'lib/itesttool/custom_matchers.rb', line 42 def "\nValid response body on \"#{@schema_file}\".\n\n" end |
#matches?(body) ⇒ 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 = $!. false end end |