diff --git a/lib/oga/xml/namespace.rb b/lib/oga/xml/namespace.rb index 213668d..938330b 100644 --- a/lib/oga/xml/namespace.rb +++ b/lib/oga/xml/namespace.rb @@ -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 diff --git a/spec/oga/xml/namespace_spec.rb b/spec/oga/xml/namespace_spec.rb index 1ddf80a..f2e7269 100644 --- a/spec/oga/xml/namespace_spec.rb +++ b/spec/oga/xml/namespace_spec.rb @@ -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