Class: Canon::RSpecMatchers::SerializationMatcher
- Inherits:
-
Object
- Object
- Canon::RSpecMatchers::SerializationMatcher
- Defined in:
- lib/canon/rspec_matchers.rb
Overview
Base matcher class for serialization equivalence
Instance Method Summary collapse
-
#initialize(expected, format = :xml) ⇒ SerializationMatcher
constructor
A new instance of SerializationMatcher.
- #match_json ⇒ Object
- #match_xml ⇒ Object
-
#match_yaml ⇒ Object
Canonicalize and check string equivalence for YAML/JSON.
- #matches?(target) ⇒ Boolean
Constructor Details
#initialize(expected, format = :xml) ⇒ SerializationMatcher
Returns a new instance of SerializationMatcher.
16 17 18 19 20 |
# File 'lib/canon/rspec_matchers.rb', line 16 def initialize(expected, format = :xml) @expected = expected @format = format.to_sym @result = nil end |
Instance Method Details
#match_json ⇒ Object
49 50 51 |
# File 'lib/canon/rspec_matchers.rb', line 49 def match_json canonicalize_and_compare(:json) end |
#match_xml ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/canon/rspec_matchers.rb', line 30 def match_xml @result = CompareXML.equivalent?( Nokogiri::XML(@target), Nokogiri::XML(@expected), { collapse_whitespace: true, ignore_attr_order: true, verbose: true, }, ) @result.empty? end |
#match_yaml ⇒ Object
Canonicalize and check string equivalence for YAML/JSON
45 46 47 |
# File 'lib/canon/rspec_matchers.rb', line 45 def match_yaml canonicalize_and_compare(:yaml) end |