Sha256: b5d834946a1294c511571cee68bc4709a62bbf9c4eb0bb25aae548ca43bdc528

Contents?: true

Size: 987 Bytes

Versions: 4

Compression:

Stored size: 987 Bytes

Contents

require "xml"
require 'test/unit'

class TestSchema < Test::Unit::TestCase
  def setup
    xp = XML::Parser.new
    @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xml'))
  end
  
  def teardown
    @doc = nil
  end
  
  def schema
    document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
    schema = XML::Schema.document(document)
  end

  def test_from_doc
    assert_instance_of(XML::Schema, schema)
  end
  
  def test_valid
    assert(@doc.validate_schema(schema))
  end
  
  def test_invalid
    new_node = XML::Node.new('invalid', 'this will mess up validation')
    @doc.root.child_add(new_node)
    
    messages = Hash.new
    assert(!@doc.validate_schema(schema) do |message, error|
      messages[message] = error
    end)

    expected = {"Element 'invalid': This element is not expected. Expected is ( item ).\n" => true}
    assert_equal(expected, messages)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
libxml-ruby-0.8.2 test/tc_schema.rb
libxml-ruby-0.8.2-x86-mswin32-60 test/tc_schema.rb
libxml-ruby-0.8.3 test/tc_schema.rb
libxml-ruby-0.8.3-x86-mswin32-60 test/tc_schema.rb