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
- #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.
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
121 122 123 |
# File 'lib/canon/rspec_matchers.rb', line 121 def actual @target end |
#diffable ⇒ Object
125 126 127 |
# File 'lib/canon/rspec_matchers.rb', line 125 def diffable false 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/canon/rspec_matchers.rb', line 75 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 |