equal(expected) public

Passes if actual and expected are the same object (object identity).

See <a href="http://www.ruby-doc.org/core/classes/Object.html#M001057">http://www.ruby-doc.org/core/classes/Object.html#M001057</a> for more information about equality in Ruby.


  5.should equal(5) #Fixnums are equal
  "5".should_not equal("5") #Strings that look the same are not the same object
Show source
Register or log in to add new notes.
March 31, 2011
0 thanks

Test strings with match

To test a string use match, e.g.

"test".should match("test")
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