Open pirj opened 5 years ago
What does “local” mean in this context? Would you recommend defining one-off matchers for a single example group?
Yep, local to an example group, so that it's not accessible in the other example groups.
It depends on the number of examples in the group and the complexity of the match condition. Sometimes two examples are enough to start thinking of extracting them. Shared examples might be an option, but they create additional group, and with expensive setup this might not be desirable.
The matcher defined does not necessarily have to be defined in the example group itself, it may be in the module, and be included in the example group, or several example groups even spread over different spec files.
E.g.
Related docs: https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/custom-matchers/define-a-custom-matcher#scoped-in-a-module https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/custom-matchers/define-a-custom-matcher#scoped-in-an-example-group
Caveats
I personally find it very confusing that those matchers don't have access to group variables, as opposed to ad-hoc methods:
With a matcher: