v0.3.0-rc.0 released
I’m hoping to cut a full release soon, but would like to give folks a few days to try things out and report any bugs that I missed, so I’ve pushed this release as an RC.
defp deps do
[
{:mneme, "~> 0.3.0-rc.0", only: :test}
]
end
Breaking change
auto_assert
will now use <-
when comparing against falsy values instead of ==
, and support for ==
has been removed.
# old
auto_assert Function.identity(nil) == nil
# new
auto_assert nil <- Function.identity(nil)
When I started on Mneme, I wanted the behavior of auto_assert
to exactly match that of assert
, including the expectation of a truthy value. Consider the following ExUnit assertions:
# this will fail
assert false = Function.identity(false)
# this would succeed
assert Function.identity(false) == false
# this might succeed or fail
assert some_predicate?()
assert
has to expect a truthy value to support that third case, but that case doesn’t make sense for auto_assert
. We’re always trying to construct a match pattern, and we use the presence of <-
in an AST to disambiguate between a new assertion and one that is being (potentially) updated.
All in all, supporting ==
comparisons after auto_assert
complicated the code and didn’t (in my opinion) add significant value, so I’ve decided to deviate from ExUnit in this particular way and to allow matches on falsy values to succeed.
New stuff
In addition to a number of fixes, this release is largely about introducing auto_assert_raise
, auto_assert_receive
, and auto_assert_received
.
Example: auto_assert_raise
test "raises when passed invalid arguments" do
auto_assert_raise fn -> some_call!(:invalid) end
end
Running the test gives you two auto-generated options, one with and one without a message:
test "raises when passed invalid arguments" do
auto_assert_raise ArgumentError, fn -> some_call!(:invalid) end
# or
auto_assert_raise ArgumentError, "expected message", fn -> some_call!(:invalid) end
end
Example: auto_assert_receive
/ auto_assert_received
Example test case:
test "current process should receive an ack" do
ref = send_request!()
auto_assert_receive()
end
Running the test will prompt you with options for each message received by the current process during the timeout window (default 100ms, same as ExUnit’s assert_receive
):
test "current process should receive an ack" do
ref = send_request!()
auto_assert_receive {:ack, ^ref}
end
As with ExUnit, auto_assert_received
is the same as auto_assert_receive
with a timeout of 0.
As always, any feedback is greatly appreciated!