Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should stubs be protected too? #56

Closed
randycoulman opened this issue Oct 9, 2020 · 2 comments
Closed

Should stubs be protected too? #56

randycoulman opened this issue Oct 9, 2020 · 2 comments
Labels
question Further information is requested

Comments

@randycoulman
Copy link
Contributor

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!

randycoulman pushed a commit to randycoulman/hammox that referenced this issue Oct 9, 2020
Closes msz#56

Currently, only mocks created with `expect` are type-checked by Hammox.

This provides the same protection for stubs created with `stub`.
@msz
Copy link
Owner

msz commented Oct 11, 2020

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.

@msz msz added the question Further information is requested label Oct 11, 2020
@msz
Copy link
Owner

msz commented Oct 11, 2020

I'll close this now as stub has a PR in #58 and I created an issue for stub_with in #59!

@msz msz closed this as completed Oct 11, 2020
randycoulman pushed a commit to randycoulman/hammox that referenced this issue Oct 12, 2020
Closes msz#56

Currently, only mocks created with `expect` are type-checked by Hammox.

This provides the same protection for stubs created with `stub`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants