Why does Rubocop prefer `have_received` to `receive`?

Viewed 13

I have tests of the form:

expect(ClassA).to receive(:method)
ClassB.perform

Rubocop would prefer if I refactored this to use have_received, which requires ClassA to be mocked. In other words, I need to set up:

allow(ClassA).to receive(:method)
ClassB.perform
expect(ClassA).not_to have_received(:method)

What's the point? Just following the Arrange Act Assert format?

1 Answers

Refactoring to used have_received allowed me to move a lot of the set-up into a before block, and put tests after the action following the Arrange Ace Assert format.

The code noticeably reads better.

Related