Class: Canon::RSpecMatchers::SerializationMatcher
- Inherits:
-
Object
- Object
- Canon::RSpecMatchers::SerializationMatcher
- Defined in:
- lib/canon/rspec_matchers.rb
Overview
Base matcher class for serialization equivalence This is a THIN WRAPPER around Canon::Comparison API
Instance Method Summary collapse
- #actual ⇒ Object
-
#diffable ⇒ Object
rubocop:disable Naming/PredicateMethod.
-
#does_not_match?(target) ⇒ Boolean
Skip the rebaseliner path for
.not_to. - #expected ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected, format = nil, match_profile: nil, match: nil, preprocessing: nil, diff_algorithm: nil, show_diffs: nil) ⇒ SerializationMatcher
constructor
A new instance of SerializationMatcher.
- #matches?(target) ⇒ Boolean
-
#show_diffs(value) ⇒ SerializationMatcher
Chain method for controlling diff display.
-
#with_match(**match_opts) ⇒ SerializationMatcher
Chain method for setting match options.
-
#with_options(**options) ⇒ SerializationMatcher
Chain method for setting match options (alias for with_match).
-
#with_profile(profile_name) ⇒ SerializationMatcher
Chain method for setting match profile.
Constructor Details
#initialize(expected, format = nil, match_profile: nil, match: nil, preprocessing: nil, diff_algorithm: nil, show_diffs: nil) ⇒ SerializationMatcher
Returns a new instance of SerializationMatcher.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/canon/rspec_matchers.rb', line 49 def initialize(expected, format = nil, match_profile: nil, match: nil, preprocessing: nil, diff_algorithm: nil, show_diffs: nil) @expected = expected @format = format&.to_sym @match_profile = match_profile @match = match @preprocessing = preprocessing @diff_algorithm = diff_algorithm @show_diffs = show_diffs end |
Instance Method Details
#actual ⇒ Object
121 122 123 |
# File 'lib/canon/rspec_matchers.rb', line 121 def actual @target end |
#diffable ⇒ Object
rubocop:disable Naming/PredicateMethod
125 126 127 |
# File 'lib/canon/rspec_matchers.rb', line 125 def diffable # rubocop:disable Naming/PredicateMethod false end |
#does_not_match?(target) ⇒ Boolean
Skip the rebaseliner path for .not_to. RSpec invokes
does_not_match? if defined, instead of negating matches?.
105 106 107 |
# File 'lib/canon/rspec_matchers.rb', line 105 def does_not_match?(target) !compute_equivalent(target) end |
#expected ⇒ Object
117 118 119 |
# File 'lib/canon/rspec_matchers.rb', line 117 def expected @expected end |
#failure_message ⇒ Object
109 110 111 |
# File 'lib/canon/rspec_matchers.rb', line 109 def "expected #{format_name} to be equivalent\n\n#{diff_output}" end |
#failure_message_when_negated ⇒ Object
113 114 115 |
# File 'lib/canon/rspec_matchers.rb', line 113 def "expected #{format_name} not to be equivalent" end |
#matches?(target) ⇒ Boolean
93 94 95 96 97 98 99 100 101 |
# File 'lib/canon/rspec_matchers.rb', line 93 def matches?(target) # Capture caller_locations only when rebaseliner is enabled so that # passing assertions don't pay for stack walking. @rebaseliner_caller = caller_locations(1, 12) if Canon::Rebaseliner.enabled? equivalent = compute_equivalent(target) return true if equivalent attempt_rebaseline end |
#show_diffs(value) ⇒ SerializationMatcher
Chain method for controlling diff display
64 65 66 67 |
# File 'lib/canon/rspec_matchers.rb', line 64 def show_diffs(value) @show_diffs = value.to_sym self end |
#with_match(**match_opts) ⇒ SerializationMatcher
Chain method for setting match options
72 73 74 75 76 |
# File 'lib/canon/rspec_matchers.rb', line 72 def with_match(**match_opts) @match ||= {} @match = @match.merge(match_opts) self end |
#with_options(**options) ⇒ SerializationMatcher
Chain method for setting match options (alias for with_match)
89 90 91 |
# File 'lib/canon/rspec_matchers.rb', line 89 def (**) with_match(**) end |
#with_profile(profile_name) ⇒ SerializationMatcher
Chain method for setting match profile
81 82 83 84 |
# File 'lib/canon/rspec_matchers.rb', line 81 def with_profile(profile_name) @match_profile = profile_name self end |