dashbitco / mox

Mocks and explicit contracts in Elixir
1.35k stars 77 forks source link

Use $callers to use expectations made in the calling process #53

Closed axelson closed 5 years ago

axelson commented 5 years ago

My first implementation passed the result of Process.get(:"$callers") in to the server for processing but it felt cleaner to do that call in Mox itself.

Questions:

josevalim commented 5 years ago
  1. Let’s do a version check that sets the tag
  2. No need
  3. I think only there but that’s a good point. It should be documented elsewhere.

--

José Valim www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D

axelson commented 5 years ago

Okay, updated with a version check to set the tags to exclude.

josevalim commented 5 years ago

Perfect. Although I think we should get the first entry (self()) in case of no matches (the current behavior). --

José Valimwww.plataformatec.com.br http://www.plataformatec.com.br/Founder and Director of R&D

axelson commented 5 years ago

I still need to fix up the assert_default_raise in the tests but I've updated the main check in server.ex to reflect "Although I think we should get the first entry (self()) in case of no matches (the current behavior)."

But isn't defaulting to the last caller (which will be the test process in these cases) cleaner?

    owner_pid = Enum.find_value(caller_pids, List.last(caller_pids), fn caller_pid ->
      state.allowances[caller_pid][mock]
    end)
josevalim commented 5 years ago

But isn't defaulting to the last caller (which will be the test process in these cases) cleaner?

I don't think it matters in the current code because the only scenario where it will use the default is when we don't have any allowances or expectations and that means both first or last will fail anyway?

josevalim commented 5 years ago

:heart: :green_heart: :blue_heart: :yellow_heart: :purple_heart:

axelson commented 5 years ago

Awesome, thanks!