Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rspec can validate with schemas now

  • Loading branch information...
commit 563e7a0c444d9cecd87ef84a7b8023435b444632 1 parent 153d6c8
@tenderlove authored
Showing with 34 additions and 0 deletions.
  1. +17 −0 lib/markup_validity/rspec.rb
  2. +17 −0 spec/matcher_spec.rb
View
17 lib/markup_validity/rspec.rb
@@ -31,5 +31,22 @@ def be_xhtml_strict
end
end
end
+
+ def be_valid_with_schema schema
+ Matcher.new :be_xhtml_strict, schema do |_schema_|
+ validator = nil
+ match do |xhtml|
+ validator = MarkupValidity::Validator.new(
+ xhtml,
+ Nokogiri::XML::Schema(_schema_)
+ )
+ validator.valid?
+ end
+
+ failure_message_for_should do |actual|
+ validator.inspect
+ end
+ end
+ end
end
end
View
17 spec/matcher_spec.rb
@@ -25,6 +25,23 @@ module Matchers
it "is not strict xhtml" do
Matchers.invalid_document.should_not be_xhtml_strict
end
+
+ XSD = File.read(
+ File.expand_path(
+ File.join(File.dirname(__FILE__),'..','test','assets','shipment.xsd')
+ )
+ )
+ XML = File.read(
+ File.join(File.dirname(__FILE__), '..','test', 'assets', 'order.xml')
+ )
+
+ it "is valid given spec" do
+ XML.should be_valid_with_schema XSD
+ end
+
+ it "is not valid given spec" do
+ XML.gsub(/<name>[^<]*<\/name>/, '').should_not be_valid_with_schema XSD
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.