Rulestead.TestHelpers (rulestead v1.0.0)

Copy Markdown View Source

Fake-backed test helpers for host-app tests.

Rulestead.TestHelpers is a Supported adopter facade in the 1.x contract (api_stability.md — "Supported adopter facades"). It provides a stable, in-memory-backed API your host application's ExUnit tests can use to control flag state without touching a real store or database.

Quickstart

# In your test_helper.exs or a shared test support module:
import Rulestead.TestHelpers

# Seed a flag for the duration of a block:
with_flag("my_feature", true) do
  assert MyApp.feature_enabled?()
end

# Or seed for the remainder of a test:
put_flag("my_feature", true)

Public API (closed catalog)

The backing store (Rulestead.Fake) and its control module are internal and not part of the 1.x public contract.

Summary

Functions

Asserts that the enclosed code emits a matching eval stop event.

Clears fake state for test isolation.

Seeds a fake-backed flag for the remainder of the current test.

Pins a variant assignment for one targeting key through the fake-backed contract.

Seeds a flag value for the duration of the block and restores prior fake state.

Functions

assert_flag_evaluated(flag_key, list)

(macro)

Asserts that the enclosed code emits a matching eval stop event.

clear_flags()

@spec clear_flags() :: :ok

Clears fake state for test isolation.

put_flag(flag_key, value, opts \\ [])

@spec put_flag(String.t() | atom(), term(), keyword()) :: map()

Seeds a fake-backed flag for the remainder of the current test.

seed_bucket(flag_key, targeting_key, variant)

@spec seed_bucket(String.t() | atom(), String.t() | atom(), String.t() | atom()) ::
  map()

Pins a variant assignment for one targeting key through the fake-backed contract.

with_flag(flag_key, value, list)

(macro)

Seeds a flag value for the duration of the block and restores prior fake state.