@@ -305,14 +305,16 @@ defmodule ExUnit.Assertions do
305
305
306
306
defp do_assert_receive ( expected , timeout , message ) do
307
307
binary = Macro . to_string ( expected )
308
+ message = message ||
309
+ "Expected to have received message matching #{ binary } "
308
310
309
311
{ :receive , meta , args } =
310
312
quote do
311
313
receive do
312
314
unquote ( expected ) = received -> received
313
315
after
314
316
unquote ( timeout ) ->
315
- flunk unquote ( message ) || "Expected to have received message matching #{ unquote binary } "
317
+ flunk unquote ( message )
316
318
end
317
319
end
318
320
@@ -488,18 +490,31 @@ defmodule ExUnit.Assertions do
488
490
end
489
491
490
492
defp do_refute_receive ( not_expected , timeout , message ) do
491
- binary = Macro . to_string ( not_expected )
493
+ receive_clause = refute_receive_recv ( not_expected , message )
492
494
493
495
quote do
494
496
receive do
495
- unquote ( not_expected ) = actual ->
496
- flunk unquote ( message ) || "Expected to not have received message matching #{ unquote binary } , got #{ inspect actual } "
497
+ unquote ( receive_clause )
497
498
after
498
499
unquote ( timeout ) -> false
499
500
end
500
501
end
501
502
end
502
503
504
+ defp refute_receive_recv ( not_expected , nil ) do
505
+ binary = Macro . to_string ( not_expected )
506
+ quote do
507
+ unquote ( not_expected ) = actual ->
508
+ flunk "Expected to not have received message matching #{ unquote binary } , got #{ inspect actual } "
509
+ end
510
+ end
511
+
512
+ defp refute_receive_recv ( not_expected , message ) do
513
+ quote do
514
+ unquote ( not_expected ) -> flunk unquote ( message )
515
+ end
516
+ end
517
+
503
518
@ doc """
504
519
Asserts the `expected` and `received` are not within `delta`.
505
520
0 commit comments