From ebdb95b7543ac90cd439985c7e0cef6a499348c0 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 15 Sep 2015 09:34:31 -0400 Subject: [PATCH] Adding test coverage to make sure we're testing validation of invalid files. Related to #1351. --- test/xml/test_schema.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/xml/test_schema.rb b/test/xml/test_schema.rb index bd7b54ca2d..0ad03aa3eb 100644 --- a/test/xml/test_schema.rb +++ b/test/xml/test_schema.rb @@ -94,9 +94,22 @@ def test_validate_file end def test_validate_invalid_document - read_doc = File.read(PO_XML_FILE).gsub(/[^<]*<\/city>/, '') + doc = Nokogiri::XML File.read(PO_XML_FILE) + doc.css("city").unlink - assert errors = @xsd.validate(Nokogiri::XML(read_doc)) + assert errors = @xsd.validate(doc) + assert_equal 2, errors.length + end + + def test_validate_invalid_file + tempfile = Tempfile.new("xml") + + doc = Nokogiri::XML File.read(PO_XML_FILE) + doc.css("city").unlink + tempfile.write doc.to_xml + tempfile.close + + assert errors = @xsd.validate(tempfile.path) assert_equal 2, errors.length end