|
1 | 1 | defmodule Loki.FileManipulationTest do
|
2 | 2 | use ExUnit.Case, async: true
|
3 | 3 |
|
4 |
| - import Loki.File |
5 |
| - import Loki.Directory |
6 | 4 | import Loki.FileManipulation
|
| 5 | + import Loki.TestHelpers |
7 | 6 | import ExUnit.CaptureIO
|
8 | 7 |
|
9 | 8 |
|
10 |
| - setup_all do |
11 |
| - create_directory("temp") |
12 |
| - :ok |
13 |
| - end |
14 |
| - |
15 | 9 | describe "FileManipulation" do
|
16 | 10 | test "#append_to_file" do
|
17 |
| - capture_io(fn -> create_file("temp/append") end) |
| 11 | + create_file_silently("append") |
18 | 12 |
|
19 | 13 | assert capture_io(fn ->
|
20 | 14 | append_to_file("temp/append", "appended")
|
21 | 15 | end) == "\e[32m * append \e[0mtemp/append\e[0m\n"
|
22 | 16 | end
|
23 | 17 |
|
24 | 18 | test "#prepend_to_file" do
|
25 |
| - capture_io(fn -> create_file("temp/prepend") end) |
| 19 | + create_file_silently("prepend") |
26 | 20 |
|
27 | 21 | assert capture_io(fn ->
|
28 | 22 | prepend_to_file("temp/prepend", "prepended")
|
29 | 23 | end) == "\e[32m * prepend \e[0mtemp/prepend\e[0m\n"
|
30 | 24 | end
|
31 | 25 |
|
32 | 26 | test "#remove_from_file" do
|
33 |
| - capture_io(fn -> create_file("temp/remove", "remove") end) |
| 27 | + create_file_silently("remove", "remove") |
34 | 28 |
|
35 | 29 | assert capture_io(fn ->
|
36 | 30 | remove_from_file("temp/remove", "remove")
|
37 | 31 | end) == "\e[32m * remove \e[0mtemp/remove\e[0m\n"
|
38 | 32 | end
|
39 | 33 |
|
40 | 34 | test "#inject_into_file" do
|
41 |
| - capture_io(fn -> create_file("temp/inject", "line") end) |
| 35 | + create_file_silently("inject", "line") |
42 | 36 |
|
43 | 37 | assert capture_io(fn ->
|
44 | 38 | inject_into_file("temp/inject", "injected", :after, "line")
|
45 | 39 | end) == "\e[32m * inject \e[0mtemp/inject\e[0m\n"
|
46 | 40 | end
|
47 | 41 |
|
48 | 42 | test "#replace_in_file" do
|
49 |
| - capture_io(fn -> create_file("temp/replace", "replace") end) |
| 43 | + create_file_silently("replace", "replace") |
50 | 44 |
|
51 | 45 | assert capture_io(fn ->
|
52 | 46 | replace_in_file("temp/replace", "replaced", "replace")
|
53 | 47 | end) == "\e[32m * replace \e[0mtemp/replace\e[0m\n"
|
54 | 48 | end
|
55 | 49 |
|
56 | 50 | test "#comment_in_file" do
|
57 |
| - capture_io(fn -> create_file("temp/comment", "comment") end) |
| 51 | + create_file_silently("comment", "comment") |
58 | 52 |
|
59 | 53 | assert capture_io(fn ->
|
60 | 54 | comment_in_file("temp/comment", "comment")
|
61 | 55 | end) == "\e[32m * comment \e[0mtemp/comment\e[0m\n"
|
62 | 56 | end
|
63 | 57 |
|
64 | 58 | test "#uncomment_in_file" do
|
65 |
| - capture_io(fn -> create_file("temp/uncomment", "# uncomment") end) |
| 59 | + create_file_silently("uncomment", "# uncomment") |
66 | 60 |
|
67 | 61 | assert capture_io(fn ->
|
68 | 62 | comment_in_file("temp/uncomment", "# uncomment")
|
69 | 63 | end) == "\e[32m * comment \e[0mtemp/uncomment\e[0m\n"
|
70 | 64 | end
|
71 | 65 |
|
72 | 66 | test "#remove_comments_in_file" do
|
73 |
| - capture_io(fn -> create_file("temp/remove_all_comments", "# comment\n # comment") end) |
| 67 | + create_file_silently("remove_all_comments", "# comment\n # comment") |
74 | 68 |
|
75 | 69 | assert capture_io(fn ->
|
76 | 70 | remove_comments_in_file("temp/remove_all_comments")
|
|
0 commit comments