Repost: RSpec 3 and deprecated .and_return blocks
Dec 22, 2014Over at the owowthathurts blog, a nice little tidbit of information on a difference between RSpec version 2 and version 3:
RSpec 3 and Deprecated .and_return Blocks
A deprecation warning I received after upgrading RSpec:
`and_return { value }` is deprecated. Use `and_return(value)` or
an implementation block without `and_return` instead
An example of code it’s complaining about:
@mock_thing.should_receive(:something).and_return do
double("SomeKindOfRelationship").tap do | mock_assoc |
mock_assoc.should_receive(:where).and_return([ @mock_relationship ])
end
end
To fix, just remove the .and_return
:
@mock_thing.should_receive(:something) do
double("SomeKindOfRelationship").tap do | mock_assoc |
mock_assoc.should_receive(:where).and_return([ @mock_relationship])
end
end
Of course, make sure your tests pass after the change.