method
equal
1.2.0 -
Show latest stable
- Class:
Spec::Matchers
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
2Notes
Test strings with match
To test a string use match, e.g.
"test".should match("test")
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