/
phx_new_ecto_test.exs
56 lines (45 loc) · 1.73 KB
/
phx_new_ecto_test.exs
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
52
53
54
55
56
Code.require_file "mix_helper.exs", __DIR__
defmodule Mix.Tasks.Phx.New.EctoTest do
use ExUnit.Case
import MixHelper
import ExUnit.CaptureIO
setup do
# The shell asks to install deps.
# We will politely say not.
send self(), {:mix_shell_input, :yes?, false}
:ok
end
@app_name "phx_ecto"
test "new without args" do
assert capture_io(fn -> Mix.Tasks.Phx.New.Ecto.run([]) end) =~
"Creates a new Ecto project within an umbrella project."
end
test "new with barebones umbrella" do
in_tmp_umbrella_project "new with barebones umbrella", fn ->
files = ~w[../config/dev.exs ../config/test.exs ../config/prod.exs ../config/prod.secret.exs]
Enum.each(files, &File.rm/1)
assert_file "../config/config.exs", &refute(&1 =~ ~S[import_config "#{Mix.env()}.exs"])
Mix.Tasks.Phx.New.Ecto.run([@app_name])
assert_file "../config/config.exs", &assert(&1 =~ ~S[import_config "#{Mix.env()}.exs"])
end
end
test "new outside umbrella", config do
in_tmp config.test, fn ->
assert_raise Mix.Error, ~r"The ecto task can only be run within an umbrella's apps directory", fn ->
Mix.Tasks.Phx.New.Ecto.run ["007invalid"]
end
end
end
test "new with defaults", config do
in_tmp_umbrella_project config.test, fn ->
Mix.Tasks.Phx.New.Ecto.run([@app_name])
# Install dependencies?
assert_received {:mix_shell, :yes?, ["\nFetch and install dependencies?"]}
# Instructions
assert_received {:mix_shell, :info, ["\nWe are almost there" <> _ = msg]}
assert msg =~ "$ cd phx_ecto"
assert msg =~ "$ mix deps.get"
assert_received {:mix_shell, :info, ["Then configure your database in config/dev.exs" <> _]}
end
end
end