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.
- #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.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/canon/rspec_matchers.rb', line 46 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
136 137 138 |
# File 'lib/canon/rspec_matchers.rb', line 136 def actual @target end |
#diffable ⇒ Object
rubocop:disable Naming/PredicateMethod
140 141 142 |
# File 'lib/canon/rspec_matchers.rb', line 140 def diffable # rubocop:disable Naming/PredicateMethod false end |
#expected ⇒ Object
132 133 134 |
# File 'lib/canon/rspec_matchers.rb', line 132 def expected @expected end |
#failure_message ⇒ Object
124 125 126 |
# File 'lib/canon/rspec_matchers.rb', line 124 def "expected #{format_name} to be equivalent\n\n#{diff_output}" end |
#failure_message_when_negated ⇒ Object
128 129 130 |
# File 'lib/canon/rspec_matchers.rb', line 128 def "expected #{format_name} not to be equivalent" end |
#matches?(target) ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/canon/rspec_matchers.rb', line 90 def matches?(target) @target = target # Build comparison options from config and matcher params opts = # Add format hint if explicitly provided opts[:format] = @format if @format # Delegate to Canon::Comparison.equivalent? - the SINGLE source of truth # Comparison handles format detection, HTML parsing, and all business logic @comparison_result = Canon::Comparison.equivalent?( @expected, @target, opts, ) # When verbose: true, result is a ComparisonResult object # Use the equivalent? method to check for normative differences case @comparison_result when Canon::Comparison::ComparisonResult @comparison_result.equivalent? when Hash # Legacy format - Hash with :differences array and :preprocessed strings @comparison_result[:differences].empty? when Array # Legacy format - XML/JSON/YAML returns [] @comparison_result.empty? else # Boolean result @comparison_result end end |
#show_diffs(value) ⇒ SerializationMatcher
Chain method for controlling diff display
61 62 63 64 |
# File 'lib/canon/rspec_matchers.rb', line 61 def show_diffs(value) @show_diffs = value.to_sym self end |
#with_match(**match_opts) ⇒ SerializationMatcher
Chain method for setting match options
69 70 71 72 73 |
# File 'lib/canon/rspec_matchers.rb', line 69 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)
86 87 88 |
# File 'lib/canon/rspec_matchers.rb', line 86 def (**) with_match(**) end |
#with_profile(profile_name) ⇒ SerializationMatcher
Chain method for setting match profile
78 79 80 81 |
# File 'lib/canon/rspec_matchers.rb', line 78 def with_profile(profile_name) @match_profile = profile_name self end |