-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathmix_helpers.exs
More file actions
51 lines (41 loc) · 1.17 KB
/
Copy pathmix_helpers.exs
File metadata and controls
51 lines (41 loc) · 1.17 KB
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
49
50
51
# Get Mix output sent to the current
# process to avoid polluting tests.
Mix.shell(Mix.Shell.Process)
defmodule MixHelper do
import ExUnit.Assertions
def tmp_path do
Path.expand("../../tmp", __DIR__)
end
def in_tmp(which, function) do
path = Path.join(tmp_path(), which)
File.rm_rf!(path)
File.mkdir_p!(path)
File.cd!(path, function)
end
def assert_file(file) do
assert File.regular?(file), "Expected #{file} to exist, but does not"
end
def refute_file(file) do
refute File.regular?(file), "Expected #{file} to not exist, but it does"
end
def assert_file(file, match) do
cond do
is_list(match) ->
assert_file(file, &Enum.each(match, fn m -> assert &1 =~ m end))
is_binary(match) or is_struct(match, Regex) ->
assert_file(file, &assert(&1 =~ match))
is_function(match, 1) ->
assert_file(file)
match.(File.read!(file))
end
end
def with_generator_env(new_env, fun) do
old = Application.get_env(:phoenix, :generators)
Application.put_env(:phoenix, :generators, new_env)
try do
fun.()
after
Application.put_env(:phoenix, :generators, old)
end
end
end