Created
May 5, 2012 22:13
-
-
Save joshuaflanagan/2605925 to your computer and use it in GitHub Desktop.
DelegateClass instance doesn't eql? itself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
require 'delegate' | |
# These tests demonstrate some unexpected (to me) | |
# behavior of a class created by DelegateClass. | |
# An instance of a DelegateClass created class does not eql? itself. | |
# | |
# The WidgetTests all pass. | |
# The comparison and eql WidgetWrapperTests fail. | |
# ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] | |
class Widget | |
end | |
class WidgetWrapper < DelegateClass(Widget) | |
end | |
# no surprises here | |
class WidgetTests < Test::Unit::TestCase | |
def setup | |
@widget = Widget.new | |
end | |
def test_equal_operator | |
assert @widget == @widget | |
end | |
def test_equal | |
assert @widget.equal?(@widget) | |
end | |
def test_comparison | |
assert_equal 0, (@widget <=> @widget) | |
end | |
def test_eql | |
assert @widget.eql?(@widget) | |
end | |
end | |
# interesting results... | |
class WidgetWrapperTests < Test::Unit::TestCase | |
def setup | |
@wrapper = WidgetWrapper.new(Widget.new) | |
end | |
def test_equal_operator | |
assert @wrapper == @wrapper | |
end | |
def test_equal | |
assert @wrapper.equal?(@wrapper) | |
end | |
def test_comparison | |
assert_equal 0, (@wrapper <=> @wrapper) | |
end | |
def test_eql | |
assert @wrapper.eql?(@wrapper) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. It was useful for us to find out why our spec fails.