Should stubs be `protected` too?
randycoulman opened this issue · 2 comments
As I was reading through the code, I noticed that while expect
wraps the replacement implementation with protected
, stub
(and stub_with
) do not.
Is there a reason for this decision? Would you consider a PR that wraps stub
's code with protected
?
I'm thinking of an implementation like this:
def stub(mock, name, code) do
arity = :erlang.fun_info(code)[:arity]
hammox_code =
case fetch_typespecs_for_mock(mock, name, arity) do
# This is really an error case where we're trying to mock a function
# that does not exist in the behaviour. Mox will flag it better though
# so just let it pass through.
[] -> code
typespecs -> protected(code, typespecs, arity)
end
Mox.stub(mock, name, hammox_code)
end
I'm not sure what a protected implementation for stub_with
would look like, though, so ideas are welcome there.
Thanks for this awesome library!
Yes! This was an oversight, because I barely ever use stub
and stub_with
.
I think stub
should work the same as expect
, as you've already done in #58. Thanks!
For stub_with
, we probably can't defer to Mox
directly. We likely need to copy the Mox implementation and make it stub with protected functions instead.