Matchers

We've been using RSpec's eq matcher to make assertions so far. We don't absolutely need this or any of RSpec's other matchers. We could use standard Ruby or define our own helper methods, like so:

describe 'no matchers' do
  it "valid? returns false for incomplete address" do
    expected = AddressValidator.valid?(address)
    if expected != false
      # RSpec's fail method allows us to manually fail an example 
      fail "Expected #{expected} to have value of false"
    end
  end
end

There are a few problems with this approach. First, it is clumsy to write and read. Second, without a standard way of handling assertions, we're likely to wind up with a bunch of variations on the code above, making our output confusing. Finally, it is very easy to make mistakes with ...

Get RSpec Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.