Class: Rspec::Xsd::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/xsd/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_path) ⇒ Matcher

Returns a new instance of Matcher.



7
8
9
10
11
# File 'lib/rspec/xsd/matcher.rb', line 7

def initialize(schema_path)
  @schema_path = schema_path
  @schema      = File.basename(schema_path)
  @errors      = []
end

Instance Method Details

#descriptionObject



32
33
34
# File 'lib/rspec/xsd/matcher.rb', line 32

def description
  "validate against #{@schema}"
end

#failure_messageObject



24
25
26
# File 'lib/rspec/xsd/matcher.rb', line 24

def failure_message
  "expected that XML would validate against #{@schema}\r\n\r\n#{@errors.join("\r\n")}"
end

#failure_message_when_negatedObject



28
29
30
# File 'lib/rspec/xsd/matcher.rb', line 28

def failure_message_when_negated
  "expected that XML would not validate against #{@schema}"
end

#matches?(xml) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/rspec/xsd/matcher.rb', line 13

def matches?(xml)
  File.open(@schema_path) do |f|
    xsd     = Nokogiri::XML::Schema(f)
    @errors = xsd.validate(Nokogiri::XML(xml))
  end

  @errors.map! { |e| e }

  @errors.empty?
end