Sha256: ed13f51f2f73c32fc8fbf8ad851c3f814ef46bf1674ba8f6859e0f394af10c5f

Contents?: true

Size: 948 Bytes

Versions: 5

Compression:

Stored size: 948 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

5 entries across 5 versions & 4 rubygems

Version Path
libxml-jruby-modified-1.0.2-jruby test/tc_schema.rb
libxml-jruby-modified-1.0.1-jruby test/tc_schema.rb
libxml-fixed-jruby-1.0.0-jruby test/tc_schema.rb
libxml-jruby-fixed-1.0.0-jruby test/tc_schema.rb
libxml-jruby-1.0.0 test/tc_schema.rb