Closed sascha-wolf closed 7 years ago
I'm happy to submit a pull request but not sure where to start on this issue. Can somebody point me in the right direction?
Hi @Zeeker ! I suppose you mean code like:
assert {:ok, 1} = {:ok, 2}
It is quite tricky in espec, because under the hood 'assert' is just 'BeTruthy' assertion. So the expression above is the same as:
expect({:ok, 1} = {:ok, 2}).to be_truthy
To handle the case you mentioned we need to implemet 'assert' (and 'refute') in different way.
So, to help you start, take a look:
lib/espec/assert.ex
lib/espec/assertions/boolean/be_truthy.ex
lib/espec/assertion_helpers.ex
And, of courcse, take a look at the 'assert' implementation in ExUnit
https://github.com/elixir-lang/elixir/blob/v1.5.1/lib/ex_unit/lib/ex_unit/assertions.ex#L161
Thank you!
I would suggest a different approach. We could add another matcher which performs pattern matching. For that we can use Kernel.match?/2
. For a failed match a diff should suffice. I suggest match_pattern
.
In addition I would probably extend test error handling to handle MatchErrors more gracefully to be closer to ExUnits handling.
What do you think?
Sounds good! Let's try it!
When doing pattern matching in ExUnit via the match operator (
=
), a failed match will be nicely formatted in the following fashion:Without
assert
Using
assert
ESpec on the other hand does not handle
MatchError
s in any special way, so a failed match will look like this:IMO ESpec provides a great deal of information for failed tests, often being superior to ExUnit in that regard. As such I think this would be a useful extension and improve the testing experience.