Cache.CaseTemplate (elixir_cache v0.4.5)
View SourceA reusable ExUnit case template for applications using elixir_cache.
Creates a CacheCase module that automatically starts sandboxed caches in
setup for every test that uses it.
Creating a CacheCase module
Pass an explicit list of cache modules:
defmodule MyApp.CacheCase do
use Cache.CaseTemplate, default_caches: [MyApp.UserCache, MyApp.SessionCache]
endOr discover caches at runtime by inspecting a running supervisor:
defmodule MyApp.CacheCase do
use Cache.CacheTemplate, supervisors: [MyApp.Supervisor]
endUsing the CacheCase in a test file
defmodule MyApp.SomeTest do
use ExUnit.Case, async: true
use MyApp.CacheCase
# or with additional caches just for this file:
use MyApp.CacheCase, caches: [MyApp.ExtraCache]
end
Options for use Cache.CaseTemplate
:default_caches— list of cache modules to start for every test:supervisors— list of supervisor atoms; theirCachechildren are discovered at runtime
Options for use MyApp.CacheCase
:caches— additional cache modules for this test file only:sleep— milliseconds to sleep after starting caches (default:10)
Summary
Functions
Inspects a running supervisor's children to find cache modules started under a
Cache supervisor child.
Raises if the given supervisor is not running or has no Cache child.
Validates that the list of cache modules contains no duplicates.
Raises with a descriptive message listing the duplicates if any are found.