History

Refactor :trailing_slash option tests

Thibaut committed 12 years ago

Commit 95ec3a51 parent 4a2a3931 file · +40 −23Browse files

Unified · Split

test/lib/docs/filters/core/internal_urls_test.rb+40−23
@@ -110,29 +110,6 @@ class InternalUrlsFilterTest < MiniTest::Spec · 109 unmodified lines
110 @body = link_to 'http://example.com/dir/file'110 @body = link_to 'http://example.com/dir/file'
111 assert_empty internal_urls111 assert_empty internal_urls
112 end112 end
113
114 context "when context[:trailing_slash] is true" do
115 it "adds a trailing slash" do
116 context[:trailing_slash] = true
117 @body = link_to 'http://example.com/dir/path'
118 assert_includes internal_urls, 'http://example.com/dir/path/'
119 end
120 end
121
122 context "when context[:trailing_slash] is false" do
123 before { context[:trailing_slash] = false }
124
125 it "removes trailing slashes" do
126 @body = link_to 'http://example.com/dir/path/'
127 assert_includes internal_urls, 'http://example.com/dir/path'
128 end
129
130 it "doesn't remove the leading slash" do
131 context[:base_url] = context[:root_url] = 'http://example.com/'
132 @body = link_to 'http://example.com/'
133 assert_includes internal_urls, 'http://example.com/'
134 end
135 end
136 end113 end
137 114
138 context "when the base url is 'example.com'" do115 context "when the base url is 'example.com'" do
@@ -258,6 +235,46 @@ class InternalUrlsFilterTest < MiniTest::Spec · 119 unmodified lines
258 end235 end
259 end236 end
260 237
238 context "context[:trailing_slash]" do
239 before do
240 @body = link_to('http://example.com/dir/path/') + link_to('http://example.com/dir/path')
241 end
242
243 context "when it is true" do
244 before do
245 context[:trailing_slash] = true
246 end
247
248 it "adds a trailing slash to :internal_urls" do
249 assert_equal ['http://example.com/dir/path/'], internal_urls
250 end
251
252 it "adds a trailing slash to replaced urls" do
253 assert_equal link_to('path/') * 2, filter_output_string
254 end
255 end
256
257 context "when it is false" do
258 before do
259 context[:trailing_slash] = false
260 end
261
262 it "removes the trailing slash from :internal_urls" do
263 assert_equal ['http://example.com/dir/path'], internal_urls
264 end
265
266 it "removes the trailing slash from replaced urls" do
267 assert_equal link_to('path') * 2, filter_output_string
268 end
269
270 it "doesn't remove the leading slash" do
271 url = context[:base_url] = context[:root_url] = 'http://example.com/'
272 @body = link_to(url)
273 assert_equal [url], internal_urls
274 end
275 end
276 end
277
261 context "context[:skip_links]" do278 context "context[:skip_links]" do
262 before do279 before do
263 @body = link_to context[:url]280 @body = link_to context[:url]