Testing Elixir: Test pid confusion (page 28)

The text reads:

Additionally, we have to define the test’s pid outside of the function because self() wouldn’t be evaluated until the function is executed, inside the process of the code under test, which could have a different pid than our test.

But the example code is:

weather_fn_double = fn city ->
    send(self(), {:get_forecast_called, city})
    ...
end

Which looks like the test pid (self()) is defined inside the function. It’s a little confusing, so maybe the text could be improved.

Thanks.

2 Likes