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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.