You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Taking that code and removing the argument to #call results in this code:
# encoding: utf-8RSpec.describe'When the caller passes a block'doit'can be yielded to from your implementation block'dodbl=doubleallow(dbl).toreceive(:foo){ |&block| block.call}expect{ |probe| dbl.foo(&probe)}.toyield_controlendend
Running RuboCop v0.34.0 gives me this offense:
test.rb:5:19: C: Pass &:call as an argument to receive instead of a block.
allow(dbl).to receive(:foo) { |&block| block.call }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuboCop is happy if I change receive(:foo) { |&block| block.call } into receive(:foo, &:call), but it doesn’t work. I guess the cop doesn’t take the & in |&block| into consideration.
In the RSpec documentation it is described how a stub can yield to the caller's block:
Taking that code and removing the argument to
#call
results in this code:Running RuboCop v0.34.0 gives me this offense:
RuboCop is happy if I change
receive(:foo) { |&block| block.call }
intoreceive(:foo, &:call)
, but it doesn’t work. I guess the cop doesn’t take the&
in|&block|
into consideration.cc @lumeet
The text was updated successfully, but these errors were encountered: