class RSpec::XmlHelpers::XmlMatcher
@api private
Constants
- BAD_ACTUAL
- BAD_EXPECTED
Public Class Methods
new(expected, colorize: true)
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 28 def initialize(expected, colorize: true) @expected = XmlHelpers.normalize_xml(expected) @diff_format = colorize ? :color : :text rescue NawsXml::ParseError => error raise ArgumentError, format(BAD_EXPECTED, error: error.message, got: got(expected)) end
Public Instance Methods
diff()
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 61 def diff diff = Diffy::Diff.new(@expected, @actual).to_s(@diff_format) diff.lines[0..-2].join end
diff_json_error_message()
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 53 def diff_json_error_message message = StringIO.new message << "Expected:\n\n#{@expected}\n" message << "Got:\n\n#{@actual}\n" message << "Diff:\n\n#{diff}" message.string end
failure_message()
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 45 def failure_message @error_message || diff_json_error_message end
failure_message_when_negated()
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 49 def failure_message_when_negated 'Expected XML value not to match.' end
got(value)
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 66 def got(value) value = value.inspect unless value.is_a?(String) value = xml.inspect if value == '' value end
matches?(actual)
click to toggle source
# File lib/rspec/xml_helpers/xml_matcher.rb, line 36 def matches?(actual) @actual = XmlHelpers.normalize_xml(actual) @expected == @actual rescue NawsXml::ParseError => error @error_message = format(BAD_ACTUAL, error: error.message, got: got(actual)) false end