devonestes / assertions

Helpful assertions for ExUnit
MIT License
143 stars 29 forks source link

Feature request: Version of assert with my custom message being purely additional to the error message #11

Closed axelson closed 3 years ago

axelson commented 4 years ago

Sometimes when I have data-driven tests the default error messages are not very helpful

for grouped_item <- grouped_items do
  # Non-grouped items should be listed with no_route_defined for the test
  assert expected_url == :no_route_defined, "my message"

Without "my message" the error looks like:

     Assertion with == failed
     code:  assert expected_url == :no_route_defined
     left:  "/activities"
     right: :no_route_defined
     stacktrace:

With "my message" the error looks like:

     my message
     code: for [slug, ids_map, expected_url] <- @grouped_data do
     stacktrace:

What I would want is a new assert-type test macro that would accept a message and be purely additional resulting in an error like:

     Assertion with == failed
     my message
     code:  assert expected_url == :no_route_defined
     left:  "/activities"
     right: :no_route_defined
     stacktrace:

That way I don't have to go out of my way every time to put /activities and :no_route_defined into the message passed to assert.

Is that in scope for this library?

devonestes commented 4 years ago

That seems like a bug in ExUnit to me, actually. Passing a custom error message shouldn't cause that other information to disappear. I'd raise that there.