v0.7.0 is now available
This is the first release targeting Elixir 1.17.0 and Erlang/OTP 27. If you are using either of those, please let me know if you encounter anything odd!
Also, some improvements from v0.6.1
While I didn’t make a post for it, v0.6.1 was released a week ago and includes some nice quality-of-life improvements when matching maps. For instance, if you previously had an assertion that looked like this:
auto_assert %{foo: 1, bar: _} <- Map.put(%{bar: 2}, :foo, 1}
and the value of :foo
changed, Mneme would suggest a pattern that also asserted the value of :bar
:
auto_assert %{foo: 2, bar: 2} <- Map.put(%{bar: 2}, :foo, 2}
As of v0.6.1, Mneme will see that your pattern used _
and will suggest a similar pattern that only updates :foo
:
auto_assert %{foo: 2, bar: _} <- Map.put(%{bar: 2}, :foo, 2}
My goal with Mneme is to generate the assertions you would write. When you manually edit a pattern (for instance, by using _
for a map value), Mneme should respect that. If you find other instances where Mneme could have generated a pattern closer to what you wanted, please file an issue!
Preview: File-based snapshots and “matchers”
If you’re interested in what may be coming up next, there are two issues that may be of interest:
These issues include details for something I’m calling matchers (other naming suggestions welcome), which are ways of modifying the behavior of assertions. For instance:
# assert that a larger string contains some substring
auto_assert substring("an error occurred") <-
capture_log(fn -> Logger.error("some error") end)
# save the generated pattern in `test_snapshots/my_snapshot.exs`
auto_assert snapshot(:my_snapshot) <- my_fun()
# save each result for a list of examples in its own snapshot file
for {name, input} <- examples do
auto_assert snapshot(name) <- my_fun(input)
end
Any input or feedback on this is greatly appreciated.