Skip to content
Mike Miller edited this page Mar 8, 2020 · 5 revisions

Matchers check whether some expected value or block behaves as described in the spec. They are essentially assertions in other test frameworks. There are many different types of matchers.

Matchers are generally created and passed to an "expectation partial." They follow (are passed to) the #to or #to_not method of expect. Or the should or should_not method when the "should" syntax is used.

For instance:

expect(foo).to eq(bar)
#              ^^^^^^^ This is the matcher.

Similar to the Regex class, matchers return MatchData when they are used. The match data includes information such as: whether the match was successful, expected and actual values, and messages for output.

Matchers can be grouped into the following categories. For a list of available matchers and what they do, check the links below.

Clone this wiki locally