File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -392,8 +392,11 @@ defmodule ExUnit.Assertions do
392392 Regex . regex? ( message ) -> Exception . message ( error ) =~ message
393393 end
394394
395- msg = "Wrong message for #{ inspect exception } . " <>
396- "Expected #{ inspect message } , got #{ inspect Exception . message ( error ) } "
395+ msg = "Wrong message for #{ inspect exception } \n " <>
396+ "Expected:\n " <>
397+ " #{ inspect message } \n " <>
398+ "Got:\n " <>
399+ " #{ inspect Exception . message ( error ) } "
397400 assert is_match , message: msg
398401
399402 error
Original file line number Diff line number Diff line change @@ -336,6 +336,32 @@ defmodule ExUnit.AssertionsTest do
336336 "Expected exception SyntaxError but got FunctionClauseError (no function clause matching in :lists.flatten/1)" = error . message
337337 end
338338
339+ test "assert raise comparing messages (for equality)" do
340+ assert_raise RuntimeError , "foo" , fn ->
341+ raise RuntimeError , "bar"
342+ end
343+ rescue
344+ error in [ ExUnit.AssertionError ] ->
345+ "Wrong message for RuntimeError" <>
346+ "\n Expected:" <>
347+ "\n \" foo\" " <>
348+ "\n Got:" <>
349+ "\n \" bar\" " = error . message
350+ end
351+
352+ test "assert raise comparing messages (with a regex)" do
353+ assert_raise RuntimeError , ~r/ ba[zk]/ , fn ->
354+ raise RuntimeError , "bar"
355+ end
356+ rescue
357+ error in [ ExUnit.AssertionError ] ->
358+ "Wrong message for RuntimeError" <>
359+ "\n Expected:" <>
360+ "\n ~r/ba[zk]/" <>
361+ "\n Got:" <>
362+ "\n \" bar\" " = error . message
363+ end
364+
339365 test "assert greater than operator" do
340366 true = assert 2 > 1
341367 end
You can’t perform that action at this time.
0 commit comments