Class: JsonRspecMatchMaker::Base
- Inherits:
-
Object
- Object
- JsonRspecMatchMaker::Base
- Defined in:
- lib/json_rspec_match_maker/base.rb
Overview
Base class that abstracts away all of the work of using the @match_definition
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
private
The object being expected against.
-
#match_definition ⇒ Hash
readonly
private
Data structure that specifies how instance values relate to JSON values.
-
#target ⇒ Hash
readonly
private
The json being tested.
Instance Method Summary collapse
-
#failure_message ⇒ String
Error reporting method called by RSpec.
-
#initialize(expected, match_definition, prefix: '') ⇒ Base
constructor
Create a new JSON matcher.
-
#matches?(target) ⇒ Bool
Match method called by RSpec.
Constructor Details
#initialize(expected, match_definition, prefix: '') ⇒ Base
Create a new JSON matcher
27 28 29 30 31 32 |
# File 'lib/json_rspec_match_maker/base.rb', line 27 def initialize(expected, match_definition, prefix: '') @expected = expected @match_definition = (match_definition) @errors = {} @prefix = prefix end |
Instance Attribute Details
#expected ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The object being expected against
9 10 11 |
# File 'lib/json_rspec_match_maker/base.rb', line 9 def expected @expected end |
#match_definition ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Data structure that specifies how instance values relate to JSON values
19 20 21 |
# File 'lib/json_rspec_match_maker/base.rb', line 19 def match_definition @match_definition end |
#target ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The json being tested
14 15 16 |
# File 'lib/json_rspec_match_maker/base.rb', line 14 def target @target end |
Instance Method Details
#failure_message ⇒ String
Error reporting method called by RSpec
51 52 53 |
# File 'lib/json_rspec_match_maker/base.rb', line 51 def @errors.values.join('\n') end |
#matches?(target) ⇒ Bool
Match method called by RSpec
40 41 42 43 44 |
# File 'lib/json_rspec_match_maker/base.rb', line 40 def matches?(target) @target = target check_target_against_expected @errors.empty? end |