Ensure SAX after_element receives meaningful args

This changes the behaviour of after_element when parsing documents using the SAX
parsing API. Previously it would always receive a nil argument, which is kinda
pointless. This commit changes that by making sure it receives a namespace name
(if any) and the element name.

This fixes #54.
This commit is contained in:
Yorick Peterse committed 2014-11-16 23:32:32 +01:00
1 parent 8c8ecce447
commit 57adabc068
3 files changed
+73 -2

No files matched your search

+16 -1
View File
@@ -3,11 +3,16 @@ require 'spec_helper'
describe Oga::XML::SaxParser do
before do
@handler = Class.new do
attr_reader :name
attr_reader :name, :after_namespace, :after_name
def on_element(namespace, name, attrs = {})
@name = name
end
def after_element(namespace, name)
@after_namespace = namespace
@after_name = name
end
end
end
@@ -26,6 +31,16 @@ describe Oga::XML::SaxParser do
handler.name.should == 'foo'
end
example 'always pass element names to after_element' do
handler = @handler.new
parser = described_class.new(handler, '<namespace:foo />')
parser.parse
handler.after_name.should == 'foo'
handler.after_namespace.should == 'namespace'
end
example 'ignore callbacks that are not defined in the handler' do
parser = described_class.new(@handler.new, '<!--foo-->')