Class: SchemaMatcher::RspecMatchers::JsonSchemaMatcher
- Inherits:
-
Object
- Object
- SchemaMatcher::RspecMatchers::JsonSchemaMatcher
- Defined in:
- lib/schema_matcher/rspec_matchers.rb
Instance Attribute Summary collapse
-
#assertion ⇒ Object
readonly
Returns the value of attribute assertion.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#schema_name ⇒ Object
readonly
Returns the value of attribute schema_name.
Instance Method Summary collapse
- #error_message ⇒ Object
- #failure_message ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
- #failure_message_when_negated ⇒ Object
- #format_json(_json) ⇒ Object
-
#initialize(schema_name, options = {}) ⇒ JsonSchemaMatcher
constructor
A new instance of JsonSchemaMatcher.
- #matches?(payload) ⇒ Boolean
Constructor Details
#initialize(schema_name, options = {}) ⇒ JsonSchemaMatcher
Returns a new instance of JsonSchemaMatcher.
9 10 11 12 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 9 def initialize(schema_name, = {}) @schema_name = schema_name @options = end |
Instance Attribute Details
#assertion ⇒ Object (readonly)
Returns the value of attribute assertion.
7 8 9 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 7 def assertion @assertion end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 7 def @options end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 7 def payload @payload end |
#schema_name ⇒ Object (readonly)
Returns the value of attribute schema_name.
7 8 9 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 7 def schema_name @schema_name end |
Instance Method Details
#error_message ⇒ Object
20 21 22 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 20 def @assertion.errors[0] end |
#failure_message ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 24 def <<~FAIL #{} --- expected #{format_json(payload)} to match schema "#{schema_name}": FAIL end |
#failure_message_for_should ⇒ Object
54 55 56 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 54 def end |
#failure_message_for_should_not ⇒ Object
58 59 60 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 58 def end |
#failure_message_when_negated ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 39 def <<~FAIL #{} --- expected #{format_json(payload)} not to match schema "#{schema_name}": FAIL end |
#format_json(_json) ⇒ Object
62 63 64 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 62 def format_json(_json) JSON.pretty_generate(payload) end |
#matches?(payload) ⇒ Boolean
14 15 16 17 18 |
# File 'lib/schema_matcher/rspec_matchers.rb', line 14 def matches?(payload) @payload = payload @assertion = SchemaMatcher::Assertion.new(schema_name, payload, ) @assertion.valid? end |