Hi!
When using assert_receive
, how do you avoid leaking messages between tests?
Let’s assume that Test.publish(1)
just sends the 1
to the test process (self()).
test "do something" do
result = Test.publish(1)
assert result == :ok
end
test "do something else" do
# We forgot to publish
# Test.publish(1)
assert_receive 1 # This would succeed randomly
end
The second test here would succeed randomly, if it’s being run after the first test.
How do you avoid this? Just adding a function to clear the mailbox between each test?