Permalink
Browse files

Only equal if we're the same class

  • Loading branch information...
1 parent 0d49471 commit 572bf043a8d4f707aa98eb03793d3aaa524c842f @tatey committed Jan 5, 2012
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/conformist/hash_struct.rb
  2. +10 −0 test/unit/conformist/hash_struct_test.rb
@@ -17,7 +17,7 @@ def merge other
end
def == other
- attributes == other.attributes
+ other.class == self.class && attributes == other.attributes
end
protected
@@ -14,6 +14,16 @@ def test_delegates
assert hash.respond_to?(:key?)
end
+ def test_equality
+ hash1 = HashStruct.new :a => 1
+ hash2 = HashStruct.new :a => 1
+ hash3 = MiniTest::Mock.new
+ hash3.expect :attributes, {:a => 1}
+ hash3.expect :class, MiniTest::Mock
+ assert_equal hash1, hash2
+ refute_equal hash1, hash3
+ end
+
def test_merge
hash1 = HashStruct.new
hash2 = hash1.merge :a => 1

0 comments on commit 572bf04

Please sign in to comment.