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