class SchemaMatcher::RspecMatchers::JsonSchemaMatcher
Attributes
assertion[R]
options[R]
payload[R]
schema_name[R]
Public Class Methods
new(schema_name, options = {})
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 9 def initialize(schema_name, options = {}) @schema_name = schema_name @options = options end
Public Instance Methods
error_message()
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 20 def error_message @assertion.errors[0] end
failure_message()
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 24 def failure_message <<~FAIL #{error_message} --- expected #{format_json(payload)} to match schema "#{schema_name}": FAIL end
failure_message_for_should()
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 54 def failure_message_for_should failure_message end
failure_message_for_should_not()
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 58 def failure_message_for_should_not failure_message_when_negated end
failure_message_when_negated()
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 39 def failure_message_when_negated <<~FAIL #{error_message} --- expected #{format_json(payload)} not to match schema "#{schema_name}": FAIL end
format_json(_json)
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 62 def format_json(_json) JSON.pretty_generate(payload) end
matches?(payload)
click to toggle source
# File lib/schema_matcher/rspec_matchers.rb, line 14 def matches?(payload) @payload = payload @assertion = SchemaMatcher::Assertion.new(schema_name, payload, options) @assertion.valid? end