method
equal
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
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
emime -
April 22, 2011
![Default_avatar_30](https://www.gravatar.com/avatar/1a3cc3e60e9f6c21ac0f105b5d6c796c?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
![Default_avatar_30](https://www.gravatar.com/avatar/dc0c13189cad0b78bcc4e441329ea03d?default=http://apidock.com/images/default_avatar_30.png&size=30)
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