Posted over 9 years ago. Visible to the public. Repeats.

Keeping your specs DRY

I often see long before blocks with lots of should_receive ... and_return inside.

Remember that before blocks are about setting up the "stage" (the context of your test), not declaring your expectations!
Also, they get run for every spec (every it block).

So :

  • convert your should_receives to stub calls in before blocks;
  • have one or more it blocks with should_receive, if you actually care that the calls are made (watch out not to expect calls that are just an implementation details, only things that you need to see called)

Owner of this card:

Avatar
Julien Letessier
Last edit:
almost 4 years ago
Tags:
rspec, testing, tip
Posted by Julien Letessier to HouseTrip Deck
This website uses short-lived cookies to improve usability.
Accept or learn more