blob: 8503cd9914055dd7766588c0e33bbe0f5cd21425 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
defmodule Couch.Test.ExUnit.Case do
@moduledoc """
Template for ExUnit test case. It can be used as follows:
```
defmodule Couch.Test.CRUD do
use Couch.Test.ExUnit.Case
...
def with_db(context, setup) do
setup = setup
|> Step.Start.new(:start, extra_apps: [:chttpd])
|> Setup.run
context = Map.merge(context, %{
base_url: setup |> Setup.get(:start) |> Step.Start.clustered_url
})
{context, setup}
end
describe "Group of tests" do
@describetag setup: &__MODULE__.with_db/2
test "Single test in a group", ctx do
ctx.base_url
end
...
end
```
"""
use ExUnit.CaseTemplate
alias Couch.Test.Setup
using do
quote do
require Logger
use ExUnit.Case
end
end
setup context do
on_exit(fn ->
:meck.unload()
end)
case context do
%{:setup => setup_fun} ->
{:ok, Setup.setup(context, setup_fun)}
_ -> {:ok, context}
end
end
end
|