espec_json_api_matchers v0.1.0 ESpecJSONAPIMatchers

Import this module in your spec module to make custom matchers available to your tests.

defmodule MyAppSpec do
  import ESpecJSONAPIMatchers
end

Once that’s done, you can use any of the provided matchers as documented in the functions below.

Summary

Functions

Ensures a resource object node contains the expected set of attributes

Ensures a resource object node’s relationships contain a key for the specified entity type

Ensures a top-level node has at least one included object of the specified entity type

Functions

conform_to_schema(schema)

Ensures a resource object node contains the expected set of attributes.

Any missing or extraneous attributes cause the test to fail.

expect(article_node) |> to(conform_to_schema [:title, :body, :published_at])
have_relationship_to(entity)

Ensures a resource object node’s relationships contain a key for the specified entity type.

expect(article_node) |> to(have_relationship_to :comments)
include_related(entity)

Ensures a top-level node has at least one included object of the specified entity type.

expect(top_level_node) |> to(include_related :comments)