Pattern: Inconsistent return from stub
Issue: -
Checks for consistent style of stub's return setting.
Enforces either and_return
or block-style return in the cases
where the returned value is constant. Ignores dynamic returned values
are the result would be different
This rule can be configured using the EnforcedStyle
option
# bad
allow(Foo).to receive(:bar).and_return("baz")
expect(Foo).to receive(:bar).and_return("baz")
# good
allow(Foo).to receive(:bar) { "baz" }
expect(Foo).to receive(:bar) { "baz" }
# also good as the returned value is dynamic
allow(Foo).to receive(:bar).and_return(bar.baz)
# bad
allow(Foo).to receive(:bar) { "baz" }
expect(Foo).to receive(:bar) { "baz" }
# good
allow(Foo).to receive(:bar).and_return("baz")
expect(Foo).to receive(:bar).and_return("baz")
# also good as the returned value is dynamic
allow(Foo).to receive(:bar) { bar.baz }
Name | Default value | Configurable values |
---|---|---|
EnforcedStyle | and_return |
and_return , block |