Class: RSpec::XSD::Matcher
- Inherits:
-
Object
- Object
- RSpec::XSD::Matcher
- Defined in:
- lib/rspec/xsd/matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(schema, schema_name) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(xml) ⇒ Boolean
Constructor Details
#initialize(schema, schema_name) ⇒ Matcher
Returns a new instance of Matcher.
7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#description ⇒ Object
47 48 49 |
# File 'lib/rspec/xsd/matcher.rb', line 47 def description "validate against #{@schema_name}" end |
#failure_message ⇒ Object
39 40 41 |
# File 'lib/rspec/xsd/matcher.rb', line 39 def "expected that XML would validate against #{@schema_name}\r\n\r\n#{@errors.join("\r\n")}" end |
#failure_message_when_negated ⇒ Object
43 44 45 |
# File 'lib/rspec/xsd/matcher.rb', line 43 def "expected that XML would not validate against #{@schema_name}" end |
#matches?(xml) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |