Added XML::Attribute#==
Overwriting this method makes it easier to check if a given namespace equals the default XML (and soon HTML) namespace.
This commit is contained in:
parent
f2d69af33b
commit
4ad502958d
|
@ -37,6 +37,14 @@ module Oga
|
|||
def inspect
|
||||
return "Namespace(name: #{name.inspect} uri: #{uri.inspect})"
|
||||
end
|
||||
|
||||
##
|
||||
# @param [Oga::XML::Namespace] other
|
||||
# @return [TrueClass|FalseClass]
|
||||
#
|
||||
def ==(other)
|
||||
return other.is_a?(self.class) && name == other.name && uri == other.uri
|
||||
end
|
||||
end # Namespace
|
||||
end # XML
|
||||
end # Oga
|
||||
|
|
|
@ -20,4 +20,42 @@ describe Oga::XML::Namespace do
|
|||
ns.inspect.should == 'Namespace(name: "x" uri: "y")'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#==' do
|
||||
describe 'when comparing with an object that is not a Namespace' do
|
||||
ns = described_class.new(:name => 'a')
|
||||
|
||||
ns.should_not == 10
|
||||
end
|
||||
|
||||
describe 'when comparing two Namespace instances' do
|
||||
it 'returns true if both namespace names are equal' do
|
||||
ns1 = described_class.new(:name => 'a')
|
||||
ns2 = described_class.new(:name => 'a')
|
||||
|
||||
ns1.should == ns2
|
||||
end
|
||||
|
||||
it 'returns true if both namespace names and URIs are equal' do
|
||||
ns1 = described_class.new(:name => 'a', :uri => 'foo')
|
||||
ns2 = described_class.new(:name => 'a', :uri => 'foo')
|
||||
|
||||
ns1.should == ns2
|
||||
end
|
||||
|
||||
it 'returns false if two namespace names are not equal' do
|
||||
ns1 = described_class.new(:name => 'a')
|
||||
ns2 = described_class.new(:name => 'b')
|
||||
|
||||
ns1.should_not == ns2
|
||||
end
|
||||
|
||||
it 'retrns false if two namespace URIs are not equal' do
|
||||
ns1 = described_class.new(:name => 'a', :uri => 'foo')
|
||||
ns2 = described_class.new(:name => 'a', :uri => 'bar')
|
||||
|
||||
ns1.should_not == ns2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue