I am trying to unit test a function that returns a very long list (by necessity), every element of which should satisfy a certain condition. I am presently testing it like this…
assert Enum.all?(some_func(...), fn x ->
...
end)
…which works, but I have to look through the list manually to see which element failed the test. How could I get better reporting that gives me this information?
How about using Enum.filter/2 where you keep all the elements that does not satisfy the condition?
The list should be smaller and it’d be easier to inspect.
@Marcus gave you an excellent suggestion IMO. This will give you a context – the index of the element and the element itself – after an assertion fails.