@@ -3,13 +3,14 @@ defmodule Mix.Tasks.InstallTest do
3
3
4
4
use ExUnit.Case , async: false
5
5
use GitHooks.TestSupport.ConfigCase
6
+ use GitHooks.TestSupport.GitProjectCase
6
7
7
8
alias Mix.Tasks.GitHooks.Install
8
9
9
10
@ tag capture_log: true
10
11
11
12
describe "run/1" do
12
- test "replaces the hook template with config values" do
13
+ test "replaces the hook template with config values" , % { tmp_dir: project_path } do
13
14
put_git_hook_config (
14
15
[ :pre_commit , :pre_push ] ,
15
16
tasks: { :cmd , "check" }
@@ -18,24 +19,27 @@ defmodule Mix.Tasks.InstallTest do
18
19
hooks_file = Install . run ( [ "--dry-run" , "--quiet" ] )
19
20
20
21
assert hooks_file == [
21
- pre_commit: expect_hook_template ( "pre_commit" ) ,
22
- pre_push: expect_hook_template ( "pre_push" )
22
+ pre_commit: expect_hook_template ( "pre_commit" , project_path ) ,
23
+ pre_push: expect_hook_template ( "pre_push" , project_path )
23
24
]
24
25
end
25
26
26
- test "allows setting a custom path to execute the hook" do
27
+ test "allows setting a custom path to execute the hook" , % { tmp_dir: project_path } do
27
28
put_git_hook_config (
28
29
[ :pre_commit , :pre_push ] ,
29
30
tasks: { :cmd , "check" }
30
31
)
31
32
32
- Application . put_env ( :git_hooks , :project_path , "a_custom_path" )
33
+ custom_path = Path . join ( project_path , "a_custom_path" )
34
+ File . mkdir_p! ( custom_path )
35
+ System . cmd ( "git" , [ "init" ] , cd: custom_path )
36
+ Application . put_env ( :git_hooks , :project_path , custom_path )
33
37
34
38
hooks_file = Install . run ( [ "--dry-run" , "--quiet" ] )
35
39
36
40
assert hooks_file == [
37
- pre_commit: expect_hook_template ( "pre_commit" , "a_custom_path" ) ,
38
- pre_push: expect_hook_template ( "pre_push" , "a_custom_path" )
41
+ pre_commit: expect_hook_template ( "pre_commit" , custom_path ) ,
42
+ pre_push: expect_hook_template ( "pre_push" , custom_path )
39
43
]
40
44
41
45
Application . delete_env ( :git_hooks , :project_path )
@@ -46,7 +50,7 @@ defmodule Mix.Tasks.InstallTest do
46
50
# Private functions
47
51
#
48
52
49
- defp expect_hook_template ( git_hook , project_path \\ "" ) do
53
+ defp expect_hook_template ( git_hook , project_path ) do
50
54
~s( #!/bin/sh
51
55
52
56
[ "#{ project_path } " != "" ] && cd "#{ project_path } "
0 commit comments