Skip to content

Files

Latest commit

 

History

History
32 lines (23 loc) · 671 Bytes

RSpec-ReceiveMessages.md

File metadata and controls

32 lines (23 loc) · 671 Bytes

Pattern: Multiple messages stubbed on the same object

Issue: -

Description

Checks for multiple messages stubbed on the same object.

Examples

# bad
before do
  allow(Service).to receive(:foo).and_return(bar)
  allow(Service).to receive(:baz).and_return(qux)
end

# good
before do
  allow(Service).to receive_messages(foo: bar, baz: qux)
end

# good - ignore same message
before do
  allow(Service).to receive(:foo).and_return(bar)
  allow(Service).to receive(:foo).and_return(qux)
end

Further Reading