Created
March 16, 2012 10:54
-
-
Save dchelimsky/2049574 to your computer and use it in GitHub Desktop.
What happens when objects implement == incorrectly
This file contains hidden or 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
$ rspec example_spec.rb | |
F | |
Failures: | |
1) Pessimist never thinks its equal, even to itself | |
Failure/Error: pessimist.should eq(pessimist) | |
expected: #<Pessimist:0x007fb82a9bae80> | |
got: #<Pessimist:0x007fb82a9bae80> | |
(compared using ==) | |
Diff: | |
# ./example_spec.rb:10:in `block (2 levels) in <top (required)>' | |
Finished in 0.00143 seconds | |
1 example, 1 failure |
This file contains hidden or 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
class Pessimist | |
def ==(other) | |
false | |
end | |
end | |
describe Pessimist do | |
it "never thinks its equal, even to itself" do | |
pessimist = Pessimist.new | |
pessimist.should eq(pessimist) | |
end | |
end |
@lucapette - thanks - I had seen that locally too but I guess I copied it to the gist before I fixed it :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Little typo in describe argument ;) BTW I really like the naming. A class that implements
==
that way should be calledPessimist
for sure.