Spex.Testing (spex v0.1.2)

Copy Markdown View Source

Test helpers for preparing and manipulating Spex runtime state.

Summary

Functions

Inserts or updates a mock instance at a specific state for test setup.

Prepares after-suite hooks that export collected implementation models.

Types

opt()

@type opt() :: {:instance_manager, module()} | {:impl_models_dir, Path.t()}

Functions

mock_instance!(spec, instance_identifier, state, meta \\ nil)

Inserts or updates a mock instance at a specific state for test setup.

Use this in unit tests to setup an instance without affecting the impl_model.

prepare_for_test_suite(opts \\ [])

@spec prepare_for_test_suite([opt()]) :: :ok

Prepares after-suite hooks that export collected implementation models.

Call this in your test_helper.exs.

It accepts the following opts:

  • :instance_manager: An instance manager module. By default, it uses the configured default instance manager (see Spex). Specify this if you are starting your instance manager in your supervision tree directly.
  • :impl_models_dir: Path to the directory where collected implementation models are exported after tests. By default, this is the configured implementation models directory (see Spex).