Testing Elixir: assert_receive throws "no matching message" error (page 85, B6.0)

Okay, I’ve figured out:

  1. The test should not be in async mode, i.e., use ExUnit.Case, async: false. Also, instead of :set_mox_from_context, be explicit and use :set_mox_global (for simpler test body) or use allow/3 to grant the sharing (more verbose); refer to Mox — Mox v1.0.0 for more info.
  2. The (test) config file needs to reference the mocked version.

To ensure repeatability, SoggyWaffle.WeatherAPI.Behavior should also be stubbed to make SoggyWaffle.rain?/2 always return true.

HTH.