-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathclean_spec.rb
151 lines (117 loc) · 3.31 KB
/
clean_spec.rb
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# frozen_string_literal: true
require "./test/helper"
clean_describe "clean" do
subject { run_cmd("#{quiet} clean") }
let(:quiet) { nil }
let(:content) { nil }
it "outputs a message" do
stdout_only "File cleaned: \"#{filename}\""
end
describe "when file does not exist" do
let(:content) { nil }
it "does not create the file" do
value(File.exist?(filename)).must_equal false
end
end
describe "when file is empty" do
let(:content) { "" }
it "adds the file structure" do
file_equals <<-FILE
### Activities:
### Notes:
### Friends:
### Locations:
FILE
end
end
describe "when file is missing some headers and sections are out of order" do
let(:content) do
<<-CONTENT
### Friends:
- Marie Curie
### Activities:
- 2016-01-01: Celebrated the new year with **Marie Curie**.
CONTENT
end
it "adds the missing file structure and reorders the sections" do
file_equals <<-FILE
### Activities:
- 2016-01-01: Celebrated the new year with **Marie Curie**.
### Notes:
### Friends:
- Marie Curie
### Locations:
FILE
end
end
describe "when file has content" do
describe "when content is formatted correctly" do
let(:content) { SCRAMBLED_CONTENT }
it "writes the file with contents sorted" do
file_equals CONTENT
end
describe "when the content includes friends and locations that have not yet been added" do
let(:content) do
<<-CONTENT
### Activities:
- 2017-01-01: Celebrated the new year in _Paris_ with **Marie Curie** and her husband **Pierre Curie**. **Marie Curie** loves _Paris_!
### Notes:
- 2017-01-01: I just learned that **Jacques Cousteau** is thinking about moving from _Gironde_ to _The Lost City of Atlantis_ (_Gironde_ did seem a bit too terrestrial for him).
### Friends:
- Grace Hopper [NYC]
### Locations:
- NYC
CONTENT
end
it "adds those friends and locations" do
file_equals <<-CONTENT
### Activities:
- 2017-01-01: Celebrated the new year in _Paris_ with **Marie Curie** and her husband **Pierre Curie**. **Marie Curie** loves _Paris_!
### Notes:
- 2017-01-01: I just learned that **Jacques Cousteau** is thinking about moving from _Gironde_ to _The Lost City of Atlantis_ (_Gironde_ did seem a bit too terrestrial for him).
### Friends:
- Grace Hopper [NYC]
- Jacques Cousteau
- Marie Curie
- Pierre Curie
### Locations:
- Gironde
- NYC
- Paris
- The Lost City of Atlantis
CONTENT
end
it "prints messages for both cleaning and adding friends/locations" do
stdout_only <<-OUTPUT
Friend added: \"Marie Curie\"
Friend added: \"Pierre Curie\"
Location added: \"Paris\"
Friend added: \"Jacques Cousteau\"
Location added: \"Gironde\"
Location added: \"The Lost City of Atlantis\"
File cleaned: \"#{filename}\"
OUTPUT
end
describe "when output is quieted" do
let(:quiet) { "--quiet" }
it "prints no messages" do
stdout_only ""
end
end
end
end
describe "when a header is malformed" do
let(:content) do
<<-FILE
### Activities:
### Garbage:
### Friends:
### Locations:
FILE
end
it "prints an error message" do
stderr_only 'Error: Expected "a valid header" on line 3'
end
end
end
end