I think you could use the "failure_message" argument for that:
for times <- 0..2, do: assert_receive({"msg", _}, 100, "message received
only #{times}, expected 3")
On Thursday, December 6, 2018 at 4:24:55 PM UTC+1, Anastasiya Dyachenko
wrote:
>
> Looks nice, but if there will be an error, then line number in error
> message will say nothing.
> But if it would be native function, then it might have special error
> message, like
> "Message ... received only 2 times, expected 3"
>
> четверг, 6 декабря 2018 г., 16:31:57 UTC+3 пользователь Sven Gehring
> написал:
>>
>> Hi,
>>
>> Assuming you want to receive the same message, wouldn't this only be
>> slightly shorter than using
>> ```
>> for _ <- 1..3, do: assert_receive({"msg", _})
>> ```
>>
>> - Sven
>>
>> On Thu, 6 Dec 2018 at 14:25 Anastasiya Dyachenko <[email protected]>
>> wrote:
>>
>>> Hi,
>>> In tests often face with need to write code like
>>> ```
>>> assert_receive {"msg", _}
>>> assert_receive {"msg", _}
>>> assert_receive {"msg", _}
>>> ```
>>> where same messages or same matching messages expected to receive
>>> multiple times.
>>> It would be match better to have ability to set number of times message
>>> must be received, like
>>>
>>> ```
>>> assert_receive {"msg", _}, 5_000, "message", 3
>>> ```
>>> or
>>> ```
>>> assert_receive {"msg", _}, times: 3, timeout: 5_000, message: "message"
>>> ```
>>>
>>> Thanks
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "elixir-lang-core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/elixir-lang-core/1ab2968a-9a6c-444f-b9e2-ab164c9673ad%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/elixir-lang-core/1ab2968a-9a6c-444f-b9e2-ab164c9673ad%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/600a2727-3528-46aa-aac4-23fff18c8fec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.