RSpec

Understanding RSpec be and eq Matchers

Avoid an error you'll see constantly with this trick

Andy Huynh

2 minute read

I confuse RSpec’s be and eq matchers when writing specs. It’s basically one or the other and the specs pass. Better you understand them to be a better programmer. Here’s my train of thought: scenario "User’s name is Jon" do let(:user) { Fabricate(:user, name: "Jon") } expect(user.name).to be "Jon" end Running this test we’ll get: Failures: 1) User’s name is Jon Failure/Error: expect(user.name).to be "Jon" expected #<String:70298288643660> => "Jon" got #<String:70298288643700> => "Jon" …