|
45 | 45 | end
|
46 | 46 |
|
47 | 47 | context 'When "config/routes.rb" exists' do
|
48 |
| - let :rake_routes_result do |
49 |
| - <<-EOS |
50 |
| - Prefix Verb URI Pattern Controller#Action |
51 |
| - myaction1 GET /url1(.:format) mycontroller1#action |
52 |
| - myaction2 POST /url2(.:format) mycontroller2#action |
53 |
| - myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
54 |
| - EOS |
55 |
| - end |
56 |
| - |
57 |
| - let :route_file_content do |
58 |
| - '' |
59 |
| - end |
60 |
| - |
61 | 48 | before(:each) do
|
62 | 49 | expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true).once
|
63 | 50 | expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content).once
|
64 | 51 |
|
65 | 52 | expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return(rake_routes_result).once
|
66 | 53 | end
|
67 | 54 |
|
68 |
| - context 'When the file does not contain magic comment' do |
69 |
| - context 'When the file does not contain annotation yet' do |
70 |
| - context 'When no option is passed' do |
71 |
| - let :expected_result do |
72 |
| - <<~EOS |
73 |
| -
|
74 |
| - # == Route Map |
75 |
| - # |
76 |
| - # Prefix Verb URI Pattern Controller#Action |
77 |
| - # myaction1 GET /url1(.:format) mycontroller1#action |
78 |
| - # myaction2 POST /url2(.:format) mycontroller2#action |
79 |
| - # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
80 |
| - EOS |
81 |
| - end |
82 |
| - |
83 |
| - it 'annotates normally' do |
84 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
85 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
86 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
87 |
| - |
88 |
| - AnnotateRoutes.do_annotations |
89 |
| - end |
| 55 | + context 'When the result of `rake routes` is present' do |
| 56 | + context 'When the file does not contain magic comment' do |
| 57 | + let :rake_routes_result do |
| 58 | + <<-EOS |
| 59 | + Prefix Verb URI Pattern Controller#Action |
| 60 | + myaction1 GET /url1(.:format) mycontroller1#action |
| 61 | + myaction2 POST /url2(.:format) mycontroller2#action |
| 62 | + myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
| 63 | + EOS |
90 | 64 | end
|
91 | 65 |
|
92 |
| - context 'When the option "format_markdown" is passed' do |
93 |
| - let :expected_result do |
94 |
| - <<~EOS |
| 66 | + let :route_file_content do |
| 67 | + '' |
| 68 | + end |
95 | 69 |
|
96 |
| - # ## Route Map |
97 |
| - # |
98 |
| - # Prefix | Verb | URI Pattern | Controller#Action |
99 |
| - # --------- | ---------- | --------------- | -------------------- |
100 |
| - # myaction1 | GET | /url1(.:format) | mycontroller1#action |
101 |
| - # myaction2 | POST | /url2(.:format) | mycontroller2#action |
102 |
| - # myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action |
103 |
| - EOS |
104 |
| - end |
| 70 | + context 'When the file does not contain annotation yet' do |
| 71 | + context 'When no option is passed' do |
| 72 | + let :expected_result do |
| 73 | + <<~EOS |
| 74 | +
|
| 75 | + # == Route Map |
| 76 | + # |
| 77 | + # Prefix Verb URI Pattern Controller#Action |
| 78 | + # myaction1 GET /url1(.:format) mycontroller1#action |
| 79 | + # myaction2 POST /url2(.:format) mycontroller2#action |
| 80 | + # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
| 81 | + EOS |
| 82 | + end |
105 | 83 |
|
106 |
| - it 'annotates in Markdown format' do |
107 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
108 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
109 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 84 | + it 'annotates normally' do |
| 85 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 86 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 87 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
110 | 88 |
|
111 |
| - AnnotateRoutes.do_annotations(format_markdown: true) |
| 89 | + AnnotateRoutes.do_annotations |
| 90 | + end |
112 | 91 | end
|
113 |
| - end |
114 | 92 |
|
115 |
| - context 'When the options "wrapper_open" and "wrapper_close" are passed' do |
116 |
| - let :expected_result do |
117 |
| - <<~EOS |
| 93 | + context 'When the option "format_markdown" is passed' do |
| 94 | + let :expected_result do |
| 95 | + <<~EOS |
| 96 | +
|
| 97 | + # ## Route Map |
| 98 | + # |
| 99 | + # Prefix | Verb | URI Pattern | Controller#Action |
| 100 | + # --------- | ---------- | --------------- | -------------------- |
| 101 | + # myaction1 | GET | /url1(.:format) | mycontroller1#action |
| 102 | + # myaction2 | POST | /url2(.:format) | mycontroller2#action |
| 103 | + # myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action |
| 104 | + EOS |
| 105 | + end |
118 | 106 |
|
119 |
| - # START |
120 |
| - # == Route Map |
121 |
| - # |
122 |
| - # Prefix Verb URI Pattern Controller#Action |
123 |
| - # myaction1 GET /url1(.:format) mycontroller1#action |
124 |
| - # myaction2 POST /url2(.:format) mycontroller2#action |
125 |
| - # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
126 |
| - # END |
127 |
| - EOS |
| 107 | + it 'annotates in Markdown format' do |
| 108 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 109 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 110 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 111 | + |
| 112 | + AnnotateRoutes.do_annotations(format_markdown: true) |
| 113 | + end |
128 | 114 | end
|
129 | 115 |
|
130 |
| - it 'annotates and wraps annotation with specified words' do |
131 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
132 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
133 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 116 | + context 'When the options "wrapper_open" and "wrapper_close" are passed' do |
| 117 | + let :expected_result do |
| 118 | + <<~EOS |
| 119 | +
|
| 120 | + # START |
| 121 | + # == Route Map |
| 122 | + # |
| 123 | + # Prefix Verb URI Pattern Controller#Action |
| 124 | + # myaction1 GET /url1(.:format) mycontroller1#action |
| 125 | + # myaction2 POST /url2(.:format) mycontroller2#action |
| 126 | + # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
| 127 | + # END |
| 128 | + EOS |
| 129 | + end |
134 | 130 |
|
135 |
| - AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END') |
| 131 | + it 'annotates and wraps annotation with specified words' do |
| 132 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 133 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 134 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 135 | + |
| 136 | + AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END') |
| 137 | + end |
136 | 138 | end
|
137 | 139 | end
|
138 | 140 | end
|
139 |
| - end |
140 | 141 |
|
141 |
| - context 'When the file contains magic comments' do |
142 |
| - MAGIC_COMMENTS.each do |magic_comment| |
143 |
| - describe "magic comment: #{magic_comment.inspect}" do |
144 |
| - let :route_file_content do |
145 |
| - <<~EOS |
146 |
| - #{magic_comment} |
147 |
| - EOS |
148 |
| - end |
| 142 | + context 'When the file contains magic comments' do |
| 143 | + MAGIC_COMMENTS.each do |magic_comment| |
| 144 | + describe "magic comment: #{magic_comment.inspect}" do |
| 145 | + let :route_file_content do |
| 146 | + <<~EOS |
| 147 | + #{magic_comment} |
| 148 | + EOS |
| 149 | + end |
149 | 150 |
|
150 |
| - let :rake_routes_result do |
151 |
| - <<-EOS |
| 151 | + let :rake_routes_result do |
| 152 | + <<-EOS |
152 | 153 | Prefix Verb URI Pattern Controller#Action
|
153 | 154 | myaction1 GET /url1(.:format) mycontroller1#action
|
154 | 155 | myaction2 POST /url2(.:format) mycontroller2#action
|
155 | 156 | myaction3 DELETE|GET /url3(.:format) mycontroller3#action
|
156 |
| - EOS |
157 |
| - end |
158 |
| - |
159 |
| - context 'When the file does not contain annotation yet' do |
160 |
| - context 'When no option is passed' do |
161 |
| - let :expected_result do |
162 |
| - <<~EOS |
163 |
| - #{magic_comment} |
164 |
| -
|
165 |
| - # == Route Map |
166 |
| - # |
167 |
| - # Prefix Verb URI Pattern Controller#Action |
168 |
| - # myaction1 GET /url1(.:format) mycontroller1#action |
169 |
| - # myaction2 POST /url2(.:format) mycontroller2#action |
170 |
| - # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
171 |
| - EOS |
172 |
| - end |
173 |
| - |
174 |
| - it 'annotates normally' do |
175 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
176 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
177 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
178 |
| - |
179 |
| - AnnotateRoutes.do_annotations |
180 |
| - end |
| 157 | + EOS |
181 | 158 | end
|
182 | 159 |
|
183 |
| - context 'When the option "format_markdown" is passed' do |
184 |
| - let :expected_result do |
185 |
| - <<~EOS |
186 |
| - #{magic_comment} |
187 |
| -
|
188 |
| - # ## Route Map |
189 |
| - # |
190 |
| - # Prefix | Verb | URI Pattern | Controller#Action |
191 |
| - # --------- | ---------- | --------------- | -------------------- |
192 |
| - # myaction1 | GET | /url1(.:format) | mycontroller1#action |
193 |
| - # myaction2 | POST | /url2(.:format) | mycontroller2#action |
194 |
| - # myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action |
195 |
| - EOS |
| 160 | + context 'When the file does not contain annotation yet' do |
| 161 | + context 'When no option is passed' do |
| 162 | + let :expected_result do |
| 163 | + <<~EOS |
| 164 | + #{magic_comment} |
| 165 | +
|
| 166 | + # == Route Map |
| 167 | + # |
| 168 | + # Prefix Verb URI Pattern Controller#Action |
| 169 | + # myaction1 GET /url1(.:format) mycontroller1#action |
| 170 | + # myaction2 POST /url2(.:format) mycontroller2#action |
| 171 | + # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
| 172 | + EOS |
| 173 | + end |
| 174 | + |
| 175 | + it 'annotates normally' do |
| 176 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 177 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 178 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 179 | + |
| 180 | + AnnotateRoutes.do_annotations |
| 181 | + end |
196 | 182 | end
|
197 | 183 |
|
198 |
| - it 'annotates in Markdown format' do |
199 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
200 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
201 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
202 |
| - |
203 |
| - AnnotateRoutes.do_annotations(format_markdown: true) |
| 184 | + context 'When the option "format_markdown" is passed' do |
| 185 | + let :expected_result do |
| 186 | + <<~EOS |
| 187 | + #{magic_comment} |
| 188 | +
|
| 189 | + # ## Route Map |
| 190 | + # |
| 191 | + # Prefix | Verb | URI Pattern | Controller#Action |
| 192 | + # --------- | ---------- | --------------- | -------------------- |
| 193 | + # myaction1 | GET | /url1(.:format) | mycontroller1#action |
| 194 | + # myaction2 | POST | /url2(.:format) | mycontroller2#action |
| 195 | + # myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action |
| 196 | + EOS |
| 197 | + end |
| 198 | + |
| 199 | + it 'annotates in Markdown format' do |
| 200 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 201 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 202 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 203 | + |
| 204 | + AnnotateRoutes.do_annotations(format_markdown: true) |
| 205 | + end |
204 | 206 | end
|
205 |
| - end |
206 |
| - |
207 |
| - context 'When the options "wrapper_open" and "wrapper_close" are passed' do |
208 |
| - let :expected_result do |
209 |
| - <<~EOS |
210 |
| - #{magic_comment} |
211 |
| -
|
212 |
| - # START |
213 |
| - # == Route Map |
214 |
| - # |
215 |
| - # Prefix Verb URI Pattern Controller#Action |
216 |
| - # myaction1 GET /url1(.:format) mycontroller1#action |
217 |
| - # myaction2 POST /url2(.:format) mycontroller2#action |
218 |
| - # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
219 |
| - # END |
220 |
| - EOS |
221 |
| - end |
222 |
| - |
223 |
| - it 'annotates and wraps annotation with specified words' do |
224 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
225 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
226 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
227 | 207 |
|
228 |
| - AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END') |
| 208 | + context 'When the options "wrapper_open" and "wrapper_close" are passed' do |
| 209 | + let :expected_result do |
| 210 | + <<~EOS |
| 211 | + #{magic_comment} |
| 212 | +
|
| 213 | + # START |
| 214 | + # == Route Map |
| 215 | + # |
| 216 | + # Prefix Verb URI Pattern Controller#Action |
| 217 | + # myaction1 GET /url1(.:format) mycontroller1#action |
| 218 | + # myaction2 POST /url2(.:format) mycontroller2#action |
| 219 | + # myaction3 DELETE|GET /url3(.:format) mycontroller3#action |
| 220 | + # END |
| 221 | + EOS |
| 222 | + end |
| 223 | + |
| 224 | + it 'annotates and wraps annotation with specified words' do |
| 225 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 226 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 227 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 228 | + |
| 229 | + AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END') |
| 230 | + end |
229 | 231 | end
|
230 | 232 | end
|
231 | 233 | end
|
|
235 | 237 | end
|
236 | 238 | end
|
237 | 239 |
|
238 |
| - describe 'When adding' do |
| 240 | + describe 'When the result of `rake routes` is blank' do |
239 | 241 | before(:each) do
|
240 | 242 | expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true).once
|
241 | 243 | expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content).once
|
|
0 commit comments