class RSpec::XSD::Matcher
Public Class Methods
new(schema, schema_name)
click to toggle source
# File lib/rspec/xsd/matcher.rb, line 7 def initialize(schema, schema_name) @schema_name = schema_name case schema when Nokogiri::XML::Schema @xsd = schema @schema_name = "In Memory Schema" if @schema_name.nil? else @schema_path = schema @schema_name = File.basename(@schema_path) if @schema_name.nil? end @errors = [] end
Public Instance Methods
description()
click to toggle source
# File lib/rspec/xsd/matcher.rb, line 47 def description "validate against #{@schema_name}" end
failure_message()
click to toggle source
# File lib/rspec/xsd/matcher.rb, line 39 def failure_message "expected that XML would validate against #{@schema_name}\r\n\r\n#{@errors.join("\r\n")}" end
failure_message_when_negated()
click to toggle source
# File lib/rspec/xsd/matcher.rb, line 43 def failure_message_when_negated "expected that XML would not validate against #{@schema_name}" end
matches?(xml)
click to toggle source
# File lib/rspec/xsd/matcher.rb, line 20 def matches?(xml) if @xsd.nil? File.open(@schema_path) do |f| @xsd = Nokogiri::XML::Schema(f) end end case xml when Nokogiri::XML::Document @errors = @xsd.validate(xml) else @errors = @xsd.validate(Nokogiri::XML(xml)) end @errors.map! { |e| e } @errors.empty? end