-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Expand file tree
/
Copy pathtest_cleaner.rb
More file actions
107 lines (81 loc) · 2.83 KB
/
Copy pathtest_cleaner.rb
File metadata and controls
107 lines (81 loc) · 2.83 KB
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
# frozen_string_literal: true
require "helper"
class TestCleaner < JekyllUnitTest
context "directory in keep_files" do
setup do
clear_dest
FileUtils.mkdir_p(dest_dir("to_keep/child_dir"))
FileUtils.touch(File.join(dest_dir("to_keep"), "index.html"))
FileUtils.touch(File.join(dest_dir("to_keep/child_dir"), "index.html"))
@site = fixture_site
@site.keep_files = ["to_keep/child_dir"]
@cleaner = Cleaner.new(@site)
@cleaner.cleanup!
end
teardown do
FileUtils.rm_rf(dest_dir("to_keep"))
end
should "keep the parent directory" do
assert_exist dest_dir("to_keep")
end
should "keep the child directory" do
assert_exist dest_dir("to_keep", "child_dir")
end
should "keep the file in the directory in keep_files" do
assert_exist dest_dir("to_keep", "child_dir", "index.html")
end
should "delete the file in the directory not in keep_files" do
refute_exist dest_dir("to_keep", "index.html")
end
end
context "non-nested directory & similarly-named directory *not* in keep_files" do
setup do
clear_dest
FileUtils.mkdir_p(dest_dir(".git/child_dir"))
FileUtils.mkdir_p(dest_dir("username.github.io"))
FileUtils.touch(File.join(dest_dir(".git"), "index.html"))
FileUtils.touch(File.join(dest_dir("username.github.io"), "index.html"))
@site = fixture_site
@site.keep_files = [".git"]
@cleaner = Cleaner.new(@site)
@cleaner.cleanup!
end
teardown do
FileUtils.rm_rf(dest_dir(".git"))
FileUtils.rm_rf(dest_dir("username.github.io"))
end
should "keep the file in the directory in keep_files" do
assert_path_exists(File.join(dest_dir(".git"), "index.html"))
end
should "delete the file in the directory not in keep_files" do
refute_path_exists(File.join(dest_dir("username.github.io"), "index.html"))
end
should "delete the directory not in keep_files" do
refute_path_exists(dest_dir("username.github.io"))
end
end
context "directory containing no files and non-empty directories" do
setup do
clear_dest
FileUtils.mkdir_p(source_dir("no_files_inside", "child_dir"))
FileUtils.touch(source_dir("no_files_inside", "child_dir", "index.html"))
@site = fixture_site
@site.process
@cleaner = Cleaner.new(@site)
@cleaner.cleanup!
end
teardown do
FileUtils.rm_rf(source_dir("no_files_inside"))
FileUtils.rm_rf(dest_dir("no_files_inside"))
end
should "keep the parent directory" do
assert_exist dest_dir("no_files_inside")
end
should "keep the child directory" do
assert_exist dest_dir("no_files_inside", "child_dir")
end
should "keep the file" do
assert_exist source_dir("no_files_inside", "child_dir", "index.html")
end
end
end