-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathscenic_new_example_test.exs
126 lines (99 loc) · 4.82 KB
/
scenic_new_example_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Code.require_file("mix_helper.exs", __DIR__)
defmodule Mix.Tasks.Scenic.NewExampleTest do
use ExUnit.Case, async: false
import ScenicNew.MixHelper
import ExUnit.CaptureIO
@app_name "scenic_demo"
@module_name "ScenicDemo"
test "new.example with defaults" do
in_tmp("new with defaults", fn ->
assert capture_io(fn ->
Mix.Tasks.Scenic.New.Example.run([@app_name])
assert_file("#{@app_name}/README.md")
assert_file("#{@app_name}/.formatter.exs")
assert_file("#{@app_name}/.gitignore")
assert_file("#{@app_name}/assets/images/attribution.txt")
assert_file("#{@app_name}/assets/images/fairy_grove.jpg")
assert_file("#{@app_name}/assets/images/cyanoramphus_zealandicus_1849.jpg")
assert_file("#{@app_name}/config/config.exs", fn file ->
assert file =~ "config :#{@app_name}, :viewport"
assert file =~ "size: {800, 600}"
assert file =~
"default_scene: #{@module_name}.Scene.Components"
assert file =~ ", title: \"#{@app_name}\""
end)
assert_file("#{@app_name}/lib/#{@app_name}.ex", fn file ->
assert file =~ "defmodule #{@module_name} do"
assert file =~ "Application.get_env(:#{@app_name}, :viewport)"
assert file =~ "#{@module_name}.PubSub.Supervisor"
end)
assert_file("#{@app_name}/lib/scenes/components.ex")
assert_file("#{@app_name}/lib/scenes/sensor.ex")
assert_file("#{@app_name}/lib/scenes/sensor_spec.ex")
assert_file("#{@app_name}/lib/scenes/primitives.ex")
assert_file("#{@app_name}/lib/scenes/transforms.ex")
assert_file("#{@app_name}/lib/scenes/fills.ex")
assert_file("#{@app_name}/lib/scenes/strokes.ex")
assert_file("#{@app_name}/lib/scenes/sprites.ex")
assert_file("#{@app_name}/lib/components/nav.ex")
assert_file("#{@app_name}/lib/components/notes.ex")
assert_file("#{@app_name}/lib/pubsub/supervisor.ex")
assert_file("#{@app_name}/lib/pubsub/temperature.ex")
assert_file("#{@app_name}/mix.exs", fn file ->
assert file =~ "mod: {#{@module_name}, []}"
assert file =~ "{:scenic, \"~> 0.11.0\"}"
assert file =~ "{:scenic_driver_local, \"~> 0.11.0\"}"
end)
end) =~ "Your Scenic project was created successfully."
end)
end
test "new with invalid args" do
assert_raise Mix.Error, ~r"Application name cannot be scenic", fn ->
Mix.Tasks.Scenic.New.Example.run(["scenic"])
end
assert_raise Mix.Error, ~r"Application name cannot be scenic", fn ->
Mix.Tasks.Scenic.New.Example.run(["folder/scenic"])
end
assert_raise Mix.Error, ~r"Application name must start with a lowercase ASCII letter,", fn ->
Mix.Tasks.Scenic.New.Example.run(["007invalid"])
end
assert_raise Mix.Error, ~r"Application name must start with a lowercase ASCII letter, ", fn ->
Mix.Tasks.Scenic.New.Example.run(["valid", "--app", "007invalid"])
end
assert_raise Mix.Error, ~r"Module name must be a valid Elixir alias", fn ->
Mix.Tasks.Scenic.New.Example.run(["valid", "--module", "not.valid"])
end
assert_raise Mix.Error, ~r"Module name \w+ is already taken", fn ->
Mix.Tasks.Scenic.New.Example.run(["string"])
end
assert_raise Mix.Error, ~r"Module name \w+ is already taken", fn ->
Mix.Tasks.Scenic.New.Example.run(["string", "chars"])
end
assert_raise Mix.Error, ~r"Module name \w+ is already taken", fn ->
Mix.Tasks.Scenic.New.Example.run(["valid", "--app", "mix"])
end
assert_raise Mix.Error, ~r"Module name \w+ is already taken", fn ->
Mix.Tasks.Scenic.New.Example.run(["valid", "--module", "String"])
end
end
test "new without args" do
assert capture_io(fn -> Mix.Tasks.Scenic.New.Example.run([]) end) =~
"Generates a starter Scenic application."
end
test "new check for directory existence" do
shell = Mix.shell()
in_tmp("check for directory existence", fn ->
File.mkdir!(@app_name)
# Send Mix messages to the current process instead of performing IO
Mix.shell(Mix.Shell.Process)
msg = "The directory \"scenic_demo\" already exists. Are you sure you want to continue?"
assert_raise Mix.Error, ~r"Please select another directory for installation", fn ->
# The shell ask if we want to continue. We will say no.
send(self(), {:mix_shell_input, :yes?, false})
Mix.Tasks.Scenic.New.Example.run([@app_name])
assert_received {:mix_shell, :yes?, [^msg]}
end
end)
Mix.shell(shell)
end
end