struct_assert v0.1.0 StructAssert

A useful tool for testing sturct and map in Elixir.

Link to this section Summary

Functions

assert only a part of struct and map

Link to this section Functions

Link to this macro assert_subset?(got, expect) (macro)

assert only a part of struct and map.

defmodule MyStruct do
  defstruct a: 1, b: 1, z: 10
end

defmodule Example
  use ExUnit.Case
  import StructAssert, only: [assert_subset?: 2]

  got  = %MyStruct{}
  assert_subset?(
    got,
    %{
      a: 1,
      b: 2
    }
  )
end

# code:  assert_subset?(got, %{a: 1, b: 2})
# left:  %{a: 1, z: 10, b: 1}
# right: %{a: 1, z: 10, b: 2}