struct_assert v0.5.0 StructAssert
A useful tool for testing sturct and map in Elixir.
Link to this section Summary
Link to this section Functions
assert only a part of struct and map.
defmodule MyStruct do
defstruct a: 1, b: 1, z: 10
end
defmodule Example
use ExUnit.Case
use StructAssert
test "example" do
assert_subset(%MyStruct{}, [a: 1, b: 2])
# code: assert_subset(%MyStruct{}, [a: 1, b: 2])
# left: %{a: 1, b: 1, z: 10}
# right: %{a: 1, b: 2, z: 10}
assert_subset(%MyStruct{}, [a: 1, b: &is_atom(&1)])
# code: assert_subset(%MyStruct{}, [a: 1, b: &(is_atom(&1))])
# left: %{a: 1, z: 10, b: 1}
# right: %{a: 1, z: 10, b: &:erlang.is_atom/1}
end
end
deprecated
Link to this function
build_expr_for_error_message(got, expect)