Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created March 16, 2012 10:54
Show Gist options
  • Save dchelimsky/2049574 to your computer and use it in GitHub Desktop.
Save dchelimsky/2049574 to your computer and use it in GitHub Desktop.
What happens when objects implement == incorrectly
$ 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
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
@dchelimsky
Copy link
Author

@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