Matchers
Matchers are passed to to in an expectation.
| Matcher | Passes when | Example |
|---|---|---|
eq(expected) |
actual == expected |
expect(total).to eq(42) |
be_truthy |
actual is neither nil nor false |
expect(user.valid?).to be_truthy |
be_falsy |
actual is nil or false |
expect(cart.empty?).to be_falsy |
be_nil |
actual is nil |
expect(user.nickname).to be_nil |
be_a(Type) |
actual is an instance of Type or a subtype |
expect(shape).to be_a(Circle) |
be_between(min, max) |
min <= actual <= max |
expect(score).to be_between(0, 100) |
include(item) |
the collection or string contains item |
expect(tags).to include(:admin) |
match(pattern) |
the string matches the regex | expect(email).to match(/@/) |
raise_error(Type) |
the block raises Type or a subtype |
expect { parse("") }.to raise_error(ParseException) |