method
equal
equal(expected)
public
Passes if actual and expected are the same object (object identity).
See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
Examples
5.should equal(5) #Fixnums are equal "5".should_not equal("5") #Strings that look the same are not the same object
Register or
log in
to add new notes.
lzap -
March 31, 2011
0 thanks
emime -
April 22, 2011
0 thanks
Test strings with eql
Equal fails when comparing two different string objects:
"test".should equal "test" #=> fail "test".should match "test" #=> pass "test".should eql "test" #=> pass
In fact:
"test".object_id.should_not eql "test".object_id #=> pass
Match fails when the string contains regex special characters not escaped:
"*test*".should match "*test*" #=> fail for invalid regex "*test*".should eql "*test*" #=> pass
In fact, match treats input as regexp:
"*test*".should match /\*test\*/ #=> pass