Class: RSpec::JsonApi::Matchers::MatchJsonSchema
- Inherits:
-
Object
- Object
- RSpec::JsonApi::Matchers::MatchJsonSchema
- Defined in:
- lib/rspec/json_api/matchers/match_json_schema.rb
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected) ⇒ MatchJsonSchema
constructor
A new instance of MatchJsonSchema.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(expected) ⇒ MatchJsonSchema
Returns a new instance of MatchJsonSchema.
9 10 11 |
# File 'lib/rspec/json_api/matchers/match_json_schema.rb', line 9 def initialize(expected) @expected = expected end |
Instance Attribute Details
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
7 8 9 |
# File 'lib/rspec/json_api/matchers/match_json_schema.rb', line 7 def expected @expected end |
Instance Method Details
#failure_message ⇒ Object
29 30 31 |
# File 'lib/rspec/json_api/matchers/match_json_schema.rb', line 29 def self end |
#failure_message_when_negated ⇒ Object
33 34 35 |
# File 'lib/rspec/json_api/matchers/match_json_schema.rb', line 33 def self end |
#matches?(actual) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rspec/json_api/matchers/match_json_schema.rb', line 13 def matches?(actual) actual = JSON.parse(actual, symbolize_names: true) # Compare types return false unless actual.instance_of?(expected.class) if expected.instance_of?(Array) RSpec::JsonApi::CompareArray.compare(actual, expected) else # Compare actual and expected schema return false unless actual.deep_keys == expected.deep_keys RSpec::JsonApi::CompareHash.compare(actual, expected) end end |