forked from x4lldux/ashes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Gazler/test/generators
test(Mix.Tasks.Ashes.Generate): tests for controller, model and channel
- Loading branch information
Showing
6 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/deps | ||
erl_crash.dump | ||
*.ez | ||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%{"cowboy": {:hex, :cowboy, "1.0.0"}, | ||
"cowlib": {:hex, :cowlib, "1.0.1"}, | ||
"phoenix": {:hex, :phoenix, "0.8.0"}, | ||
"plug": {:hex, :plug, "0.9.0"}, | ||
"poison": {:hex, :poison, "1.3.0"}, | ||
"ranch": {:hex, :ranch, "1.0.0"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
defmodule PhotoBlog.Router do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule MixHelper do | ||
import ExUnit.Assertions | ||
|
||
def tmp_path do | ||
Path.expand("../../tmp", __DIR__) | ||
end | ||
|
||
def assert_file(file) do | ||
assert File.regular?(file), "Expected #{file} to exist, but does not" | ||
end | ||
|
||
def assert_file(file, match) do | ||
cond do | ||
Regex.regex?(match) -> | ||
assert_file file, &(assert &1 =~ match) | ||
is_function(match, 1) -> | ||
assert_file(file) | ||
match.(File.read!(file)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Code.require_file "../../mix_helper.exs", __DIR__ | ||
|
||
defmodule Mix.Tasks.Ashes.GenerateTest do | ||
use ExUnit.Case | ||
|
||
import MixHelper | ||
import ExUnit.CaptureIO | ||
|
||
@app_name "photo_blog" | ||
@tmp_path tmp_path() | ||
@project_path Path.join(@tmp_path, @app_name) | ||
|
||
setup_all do | ||
templates_path = Path.join([@project_path, "deps", "ashes", "templates"]) | ||
root_path = File.cwd! | ||
|
||
#Clean up | ||
File.rm_rf @project_path | ||
|
||
#Create path for app | ||
File.mkdir_p Path.join(@project_path, "web") | ||
|
||
#Copy fixture router into web directory | ||
File.cp! Path.join([root_path, "test", "fixtures", "router.ex"]), Path.join([@project_path, "web", "router.ex"]) | ||
|
||
#Create path for templates | ||
File.mkdir_p templates_path | ||
|
||
#Copy templates into `deps/ashes/templates` to mimic a real Phoenix application | ||
File.cp_r! Path.join(root_path, "templates"), templates_path | ||
|
||
#Move into the project directory to run the generator | ||
File.cd! @project_path | ||
end | ||
|
||
test "creates controller files and directories" do | ||
Mix.Tasks.Ashes.Generate.run(["controller", "user"]) | ||
assert_file "web/controllers/user_controller.ex" | ||
|
||
assert File.exists?("web/templates/user") | ||
end | ||
|
||
test "creates controller files with --skip-template" do | ||
Mix.Tasks.Ashes.Generate.run(["controller", "photo", "--skip-template"]) | ||
assert_file "web/controllers/photo_controller.ex" | ||
|
||
refute File.exists?("web/templates/photo") | ||
end | ||
|
||
test "creates a channel file" do | ||
Mix.Tasks.Ashes.Generate.run(["channel", "user"]) | ||
assert_file "web/channels/user_channel.ex" | ||
end | ||
|
||
test "creates model file" do | ||
Mix.Tasks.Ashes.Generate.run(["model", "user"]) | ||
assert_file "web/models/user.ex" | ||
end | ||
|
||
end |