exhal v8.2.0 ExHal.Assertions

Convenience functions for asserting things about HAL documents

iex> import ExUnit.Assertions
nil
iex> import ExHal.Assertions
nil
iex> assert_property ~s({"name": "foo"}), "name"
true
iex> assert_property ~s({"name": "foo"}), "address"
** (ExUnit.AssertionError) address is absent
iex> assert_property ~s({"name": "foo"}), "name", eq "foo"
true
iex> assert_property ~s({"name": "foo"}), "name", matches ~r/fo/
true
iex> assert_property ~s({"name": "foo"}), "name", eq "bar"
** (ExUnit.AssertionError) expected property `name` to eq("bar")
iex> assert_link_target ~s({"_links": { "profile": {"href": "http://example.com" }}}),
...>   "profile"
true
iex> assert_link_target ~s({"_links": { "profile": {"href": "http://example.com" }}}),
...>   "item"
** (ExUnit.AssertionError) link `item` is absent
iex> assert_link_target ~s({"_links": { "profile": {"href": "http://example.com" }}}),
...>   "profile", eq "http://example.com"
true
iex> assert_link_target ~s({"_links": { "profile": {"href": "http://example.com" }}}),
...>   "profile", matches ~r/example.com/
true
iex> assert_link_target ~s({"_links": { "profile": {"href": "http://example.com" }}}),
...>   "profile", eq "http://bad.com"
** (ExUnit.AssertionError) expected (at least one) `item` link to eq("http://bad.com") but found only http://example.com
iex> assert collection("{}") |> Enum.empty?
true
iex> assert 1 == collection("{}") |> Enum.count
** (ExUnit.AssertionError) Assertion with == failed

Link to this section Summary

Functions

Asserts that the specifed link exists and that its target checks out.

Asserts that a property exists and, optionally, that its value checks out.

Returns a stream representation of the document.

Returns a function that checks if the actual value is equal to the expected.

Returns a function that checks if the actual value matches the expected pattern.

Link to this section Functions

Link to this macro

assert_property(doc, rel) (macro)

Asserts that a property exists and, optionally, that its value checks out.

Link to this macro

assert_property(doc, rel, check_fn) (macro)

Link to this function

collection(doc)

Returns a stream representation of the document.

Returns a function that checks if the actual value is equal to the expected.

Link to this function

matches(expected)

Returns a function that checks if the actual value matches the expected pattern.

Link to this function

p_assert_property(doc, prop_name, check_fn, check_desc)
p_assert_property(
  String.t() | ExHal.Document.t(),
  String.t(),
  (any() -> boolean()),
  String.t()
) :: any()