Multiple validations in rspec "it" block

I know that technically there should only be one “expect” within an “it” block.

However, I’m writing a simple test that needs to verify that a method creates some record and returns a certain value.

With feature specs (aka “scenarios”), it’s common to have many expects within a scenario.

What’s the general thinking on non-feature tests? Only one expect per “it”, or, if it’s totally clear, use several “expects”.

Justin… I’ll add more than one ‘expect’ if they’re all part of a set, or a sequence of things that all occur essentially at once. Otherwise, I try to stick to the one it / one expect suggestion.

1 Like

@Justin_Gordon The idea is not that you can only have one “expect” is that you should only assert one thing. That thing might only get assert by more than one expectation. Does that make sense?

1 Like

I completely agree with the others, but I’ll just quickly add my two cents here. A quick way that I determine when expectations belong together is:

Since the test will stop running when it hits the first failing expectation, ask yourself: If the first expectation fails, do I care about the the outcome of the other expectations? If the answer is “no”, then they belong in the same block.