Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/wallaby/feature.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ defmodule Wallaby.Feature do
```
config :wallaby, otp_app: :your_app
```
When used, it accepts the following options:
* `:sandbox` - whether or not to use the sandbox in the tests. Defaults to `true`.
"""

defmacro __using__(_) do
defmacro __using__(opts \\ []) do
use_sandbox? = Keyword.get(opts, :sandbox, true)

quote do
ExUnit.Case.register_attribute(__MODULE__, :sessions)

Expand All @@ -24,7 +28,8 @@ defmodule Wallaby.Feature do

setup context do
if context[:test_type] == :feature do
metadata = unquote(__MODULE__).Utils.maybe_checkout_repos(context[:async])
metadata =
unquote(__MODULE__).Utils.maybe_checkout_repos(unquote(use_sandbox?), context[:async])

start_session_opts =
[metadata: metadata]
Expand Down Expand Up @@ -171,13 +176,15 @@ defmodule Wallaby.Feature do
def put_create_session_fn(opts, func), do: Keyword.put(opts, :create_session_fn, func)

if @includes_ecto do
def maybe_checkout_repos(async?) do
def maybe_checkout_repos(true, async?) do
otp_app()
|> ecto_repos()
|> Enum.map(&checkout_ecto_repos(&1, async?))
|> metadata_for_ecto_repos()
end

def maybe_checkout_repos(_, _), do: ""

defp otp_app(), do: Application.get_env(:wallaby, :otp_app)

defp ecto_repos(nil), do: []
Expand Down