nanoc3 3.1.7 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +9 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/nanoc3/base/item.rb +1 -1
  6. data/lib/nanoc3/base/item_rep.rb +1 -0
  7. data/lib/nanoc3/base/layout.rb +1 -1
  8. data/lib/nanoc3/cli/base.rb +4 -2
  9. data/lib/nanoc3/cli/commands/view.rb +1 -0
  10. data/lib/nanoc3/data_sources/filesystem.rb +25 -6
  11. data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
  12. data/lib/nanoc3/extra/validators/links.rb +1 -1
  13. data/lib/nanoc3/filters/rdiscount.rb +2 -1
  14. data/lib/nanoc3/filters/sass.rb +20 -8
  15. data/lib/nanoc3/filters/sass.rb.orig +75 -0
  16. data/lib/nanoc3.rb +1 -1
  17. data/nanoc3.gemspec +41 -0
  18. data/tasks/clean.rake +11 -0
  19. data/tasks/doc.rake +14 -0
  20. data/tasks/gem.rake +13 -0
  21. data/tasks/test.rake +38 -0
  22. data/test/base/core_ext/array_spec.rb +23 -0
  23. data/test/base/core_ext/hash_spec.rb +41 -0
  24. data/test/base/core_ext/string_spec.rb +27 -0
  25. data/test/base/test_code_snippet.rb +33 -0
  26. data/test/base/test_compiler.rb +410 -0
  27. data/test/base/test_compiler_dsl.rb +121 -0
  28. data/test/base/test_context.rb +33 -0
  29. data/test/base/test_data_source.rb +48 -0
  30. data/test/base/test_dependency_tracker.rb +510 -0
  31. data/test/base/test_directed_graph.rb +91 -0
  32. data/test/base/test_filter.rb +85 -0
  33. data/test/base/test_item.rb +141 -0
  34. data/test/base/test_item_rep.rb +953 -0
  35. data/test/base/test_layout.rb +44 -0
  36. data/test/base/test_notification_center.rb +36 -0
  37. data/test/base/test_plugin.rb +32 -0
  38. data/test/base/test_rule.rb +21 -0
  39. data/test/base/test_rule_context.rb +63 -0
  40. data/test/base/test_site.rb +366 -0
  41. data/test/cli/commands/test_compile.rb +12 -0
  42. data/test/cli/commands/test_create_item.rb +12 -0
  43. data/test/cli/commands/test_create_layout.rb +28 -0
  44. data/test/cli/commands/test_create_site.rb +24 -0
  45. data/test/cli/commands/test_help.rb +12 -0
  46. data/test/cli/commands/test_info.rb +12 -0
  47. data/test/cli/commands/test_update.rb +12 -0
  48. data/test/cli/test_logger.rb +12 -0
  49. data/test/data_sources/test_filesystem.rb +420 -0
  50. data/test/data_sources/test_filesystem_unified.rb +538 -0
  51. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  52. data/test/extra/core_ext/test_enumerable.rb +32 -0
  53. data/test/extra/core_ext/test_time.rb +17 -0
  54. data/test/extra/deployers/test_rsync.rb +234 -0
  55. data/test/extra/test_auto_compiler.rb +482 -0
  56. data/test/extra/test_file_proxy.rb +21 -0
  57. data/test/extra/test_vcs.rb +24 -0
  58. data/test/extra/validators/test_links.rb +53 -0
  59. data/test/extra/validators/test_w3c.rb +49 -0
  60. data/test/filters/test_bluecloth.rb +20 -0
  61. data/test/filters/test_coderay.rb +46 -0
  62. data/test/filters/test_colorize_syntax.rb +56 -0
  63. data/test/filters/test_erb.rb +72 -0
  64. data/test/filters/test_erubis.rb +72 -0
  65. data/test/filters/test_haml.rb +98 -0
  66. data/test/filters/test_kramdown.rb +20 -0
  67. data/test/filters/test_less.rb +59 -0
  68. data/test/filters/test_markaby.rb +26 -0
  69. data/test/filters/test_maruku.rb +20 -0
  70. data/test/filters/test_rainpress.rb +31 -0
  71. data/test/filters/test_rdiscount.rb +33 -0
  72. data/test/filters/test_rdoc.rb +18 -0
  73. data/test/filters/test_redcloth.rb +20 -0
  74. data/test/filters/test_relativize_paths.rb +231 -0
  75. data/test/filters/test_rubypants.rb +20 -0
  76. data/test/filters/test_sass.rb +170 -0
  77. data/test/filters/test_sass.rb.orig +103 -0
  78. data/test/gem_loader.rb +11 -0
  79. data/test/helper.rb +99 -0
  80. data/test/helpers/test_blogging.rb +808 -0
  81. data/test/helpers/test_breadcrumbs.rb +83 -0
  82. data/test/helpers/test_capturing.rb +42 -0
  83. data/test/helpers/test_filtering.rb +108 -0
  84. data/test/helpers/test_html_escape.rb +18 -0
  85. data/test/helpers/test_link_to.rb +251 -0
  86. data/test/helpers/test_rendering.rb +109 -0
  87. data/test/helpers/test_tagging.rb +89 -0
  88. data/test/helpers/test_text.rb +26 -0
  89. data/test/helpers/test_xml_sitemap.rb +69 -0
  90. data/test/tasks/test_clean.rb +71 -0
  91. metadata +83 -8
@@ -0,0 +1,482 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Extra::AutoCompilerTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_handle_request_with_item_rep
10
+ if_have 'rack' do
11
+ # Create items
12
+ items = [
13
+ Nanoc3::Item.new('content 0', {}, '/item0/'),
14
+ Nanoc3::Item.new('content 1', {}, '/item1/')
15
+ ]
16
+
17
+ # Create reps
18
+ items[0].reps << Nanoc3::ItemRep.new(items[0], :rep00).tap do |r|
19
+ r.stubs(:path).returns('/foo/1/')
20
+ r.stubs(:raw_path).returns('out/foo/1/index.html')
21
+ end
22
+ items[0].reps << Nanoc3::ItemRep.new(items[0], :rep10).tap do |r|
23
+ r.stubs(:path).returns('/foo/2/')
24
+ r.stubs(:raw_path).returns('out/foo/2/index.html')
25
+ end
26
+ items[1].reps << Nanoc3::ItemRep.new(items[1], :rep11).tap do |r|
27
+ r.stubs(:path).returns('/foo/3/')
28
+ r.stubs(:raw_path).returns('out/foo/3/index.html')
29
+ end
30
+
31
+ # Create compiler
32
+ compiler = mock
33
+ compiler.expects(:run).with(items[0])
34
+
35
+ # Create site
36
+ site = mock
37
+ site.stubs(:items).returns(items)
38
+ site.stubs(:config).returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
39
+ site.stubs(:compiler).returns(compiler)
40
+
41
+ # Create autocompiler
42
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
43
+ autocompiler.stubs(:build_site)
44
+ autocompiler.stubs(:site).returns(site)
45
+ autocompiler.stubs(:build_reps)
46
+
47
+ # Run
48
+ autocompiler.instance_eval { call('PATH_INFO' => '/foo/2/') }
49
+ end
50
+ end
51
+
52
+ def test_handle_request_with_item_rep_with_index_filename
53
+ if_have 'rack' do
54
+ # Create items
55
+ items = [
56
+ Nanoc3::Item.new('content 0', {}, '/item0/'),
57
+ Nanoc3::Item.new('content 1', {}, '/item1/')
58
+ ]
59
+
60
+ # Create reps
61
+ items[0].reps << Nanoc3::ItemRep.new(items[0], :rep00).tap do |r|
62
+ r.stubs(:path).returns('/foo/1/')
63
+ r.stubs(:raw_path).returns('out/foo/1/index.html')
64
+ end
65
+ items[0].reps << Nanoc3::ItemRep.new(items[0], :rep10).tap do |r|
66
+ r.stubs(:path).returns('/foo/2/')
67
+ r.stubs(:raw_path).returns('out/foo/2/index.html')
68
+ end
69
+ items[1].reps << Nanoc3::ItemRep.new(items[1], :rep11).tap do |r|
70
+ r.stubs(:path).returns('/foo/3/')
71
+ r.stubs(:raw_path).returns('out/foo/3/index.html')
72
+ end
73
+
74
+ # Create compiler
75
+ stack = []
76
+ compiler = mock('Nanoc3::Compiler')
77
+ compiler.expects(:run).with(items[0])
78
+ compiler.stubs(:stack).returns([])
79
+
80
+ # Create site
81
+ site = mock('Nanoc3::Site')
82
+ site.stubs(:items).returns(items)
83
+ site.stubs(:config).returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
84
+ site.stubs(:compiler).returns(compiler)
85
+
86
+ # Create autocompiler
87
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
88
+ autocompiler.stubs(:build_site)
89
+ autocompiler.stubs(:site).returns(site)
90
+ autocompiler.stubs(:build_reps)
91
+
92
+ # Create file
93
+ FileUtils.mkdir_p('out/foo/2')
94
+ File.open('out/foo/2/index.html', 'w') { |io| io.write('omg hi') }
95
+
96
+ # Run
97
+ res = nil
98
+ autocompiler.instance_eval do
99
+ res = call('PATH_INFO' => '/foo/2/index.html')
100
+ end
101
+ assert_equal 200, res[0]
102
+ assert_equal 'out/foo/2/index.html', res[2].path
103
+ assert_equal 'omg hi', File.read(res[2].path)
104
+ end
105
+ end
106
+
107
+ def test_handle_request_with_broken_url
108
+ if_have 'rack' do
109
+ # Create site
110
+ site = mock('Nanoc3::Site')
111
+ site.expects(:items).returns([])
112
+ site.stubs(:config).returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
113
+
114
+ # Create file server
115
+ file_server = mock
116
+ def file_server.call(env)
117
+ @expected_path_info = '/foo/2'
118
+ @actual_path_info = env['PATH_INFO']
119
+ end
120
+ def file_server.expected_path_info ; @expected_path_info ; end
121
+ def file_server.actual_path_info ; @actual_path_info ; end
122
+
123
+ # Create autocompiler
124
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
125
+ autocompiler.stubs(:build_site)
126
+ autocompiler.stubs(:site).returns(site)
127
+ autocompiler.expects(:file_server).returns(file_server)
128
+
129
+ # Run
130
+ autocompiler.instance_eval { call('PATH_INFO' => '/foo/2') }
131
+
132
+ # Check
133
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
134
+ end
135
+ end
136
+
137
+ def test_handle_request_with_file
138
+ if_have 'rack' do
139
+ # Create file
140
+ FileUtils.mkdir_p('out')
141
+ File.open('out/somefile.txt', 'w') { |io| io.write('hello') }
142
+
143
+ # Create file server
144
+ file_server = mock
145
+ def file_server.call(env)
146
+ @expected_path_info = 'somefile.txt'
147
+ @actual_path_info = env['PATH_INFO']
148
+ end
149
+ def file_server.expected_path_info ; @expected_path_info ; end
150
+ def file_server.actual_path_info ; @actual_path_info ; end
151
+
152
+ # Create site
153
+ site = mock
154
+ site.expects(:items).returns([])
155
+ site.expects(:config).returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
156
+
157
+ # Create autocompiler
158
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
159
+ autocompiler.stubs(:build_site)
160
+ autocompiler.stubs(:site).returns(site)
161
+ autocompiler.expects(:file_server).returns(file_server)
162
+
163
+ # Run
164
+ autocompiler.instance_eval { call('PATH_INFO' => 'somefile.txt') }
165
+
166
+ # Check
167
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
168
+ end
169
+ end
170
+
171
+ def test_handle_request_with_dir_with_slash_with_index_file
172
+ if_have 'rack' do
173
+ # Create file
174
+ FileUtils.mkdir_p('out/foo/bar')
175
+ File.open('out/foo/bar/index.html', 'w') { |io| io.write('hello') }
176
+
177
+ # Create file server
178
+ file_server = mock
179
+ def file_server.call(env)
180
+ @expected_path_info = '/foo/bar/index.html'
181
+ @actual_path_info = env['PATH_INFO']
182
+ end
183
+ def file_server.expected_path_info ; @expected_path_info ; end
184
+ def file_server.actual_path_info ; @actual_path_info ; end
185
+
186
+ # Create site
187
+ site = mock
188
+ site.expects(:items).returns([])
189
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
190
+
191
+ # Create autocompiler
192
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
193
+ autocompiler.stubs(:build_site)
194
+ autocompiler.stubs(:site).returns(site)
195
+ autocompiler.expects(:file_server).returns(file_server)
196
+
197
+ # Run
198
+ autocompiler.instance_eval { call('PATH_INFO' => '/foo/bar/') }
199
+
200
+ # Check
201
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
202
+ end
203
+ end
204
+
205
+ def test_handle_request_with_dir_with_slash_without_index_file
206
+ if_have 'rack' do
207
+ # Create file
208
+ FileUtils.mkdir_p('out/foo/bar')
209
+ File.open('out/foo/bar/someotherfile.txt', 'w') { |io| io.write('hello') }
210
+
211
+ # Create file server
212
+ file_server = mock
213
+ def file_server.call(env)
214
+ @expected_path_info = 'foo/bar/'
215
+ @actual_path_info = env['PATH_INFO']
216
+ end
217
+ def file_server.expected_path_info ; @expected_path_info ; end
218
+ def file_server.actual_path_info ; @actual_path_info ; end
219
+
220
+ # Create site
221
+ site = mock
222
+ site.expects(:items).returns([])
223
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
224
+
225
+ # Create autocompiler
226
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
227
+ autocompiler.stubs(:build_site)
228
+ autocompiler.stubs(:site).returns(site)
229
+ autocompiler.expects(:file_server).returns(file_server)
230
+
231
+ # Run
232
+ autocompiler.instance_eval { call('PATH_INFO' => 'foo/bar/') }
233
+
234
+ # Check
235
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
236
+ end
237
+ end
238
+
239
+ def test_handle_request_with_dir_without_slash_with_index_file
240
+ if_have 'rack' do
241
+ # Create file
242
+ FileUtils.mkdir_p('out/foo/bar')
243
+ File.open('out/foo/bar/index.html', 'w') { |io| io.write('hello') }
244
+
245
+ # Create file server
246
+ file_server = mock
247
+ def file_server.call(env)
248
+ @expected_path_info = 'foo/bar'
249
+ @actual_path_info = env['PATH_INFO']
250
+ end
251
+ def file_server.expected_path_info ; @expected_path_info ; end
252
+ def file_server.actual_path_info ; @actual_path_info ; end
253
+
254
+ # Create site
255
+ site = mock
256
+ site.expects(:items).returns([])
257
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
258
+
259
+ # Create autocompiler
260
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
261
+ autocompiler.stubs(:build_site)
262
+ autocompiler.stubs(:site).returns(site)
263
+ autocompiler.expects(:file_server).returns(file_server)
264
+
265
+ # Run
266
+ autocompiler.instance_eval { call('PATH_INFO' => 'foo/bar') }
267
+
268
+ # Check
269
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
270
+ end
271
+ end
272
+
273
+ def test_handle_request_with_dir_without_slash_without_index_file
274
+ if_have 'rack' do
275
+ # Create file
276
+ FileUtils.mkdir_p('out/foo/bar')
277
+ File.open('out/foo/bar/someotherfile.txt', 'w') { |io| io.write('hello') }
278
+
279
+ # Create file server
280
+ file_server = mock
281
+ def file_server.call(env)
282
+ @expected_path_info = 'foo/bar'
283
+ @actual_path_info = env['PATH_INFO']
284
+ end
285
+ def file_server.expected_path_info ; @expected_path_info ; end
286
+ def file_server.actual_path_info ; @actual_path_info ; end
287
+
288
+ # Create site
289
+ site = mock
290
+ site.expects(:items).returns([])
291
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
292
+
293
+ # Create autocompiler
294
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
295
+ autocompiler.stubs(:build_site)
296
+ autocompiler.stubs(:site).returns(site)
297
+ autocompiler.expects(:file_server).returns(file_server)
298
+
299
+ # Run
300
+ autocompiler.instance_eval { call('PATH_INFO' => 'foo/bar') }
301
+
302
+ # Check
303
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
304
+ end
305
+ end
306
+
307
+ def test_handle_request_with_404
308
+ if_have 'rack' do
309
+ # Create file server
310
+ file_server = mock
311
+ def file_server.call(env)
312
+ @expected_path_info = 'four-oh-four.txt'
313
+ @actual_path_info = env['PATH_INFO']
314
+ end
315
+ def file_server.expected_path_info ; @expected_path_info ; end
316
+ def file_server.actual_path_info ; @actual_path_info ; end
317
+
318
+ # Create site
319
+ site = mock
320
+ site.expects(:items).returns([])
321
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
322
+
323
+ # Create autocompiler
324
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
325
+ autocompiler.stubs(:build_site)
326
+ autocompiler.stubs(:site).returns(site)
327
+ autocompiler.expects(:file_server).returns(file_server)
328
+
329
+ # Run
330
+ autocompiler.instance_eval { call('PATH_INFO' => 'four-oh-four.txt') }
331
+
332
+ # Check
333
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
334
+ end
335
+ end
336
+
337
+ def test_mime_type_of
338
+ if_have 'mime/types', 'rack' do
339
+ # Create autocompiler
340
+ autocompiler = Nanoc3::Extra::AutoCompiler.new(nil)
341
+
342
+ # Create known test file
343
+ File.open('foo.html', 'w') { |io| io.write('hello') }
344
+ assert_equal(
345
+ 'text/html',
346
+ autocompiler.instance_eval { mime_type_of('foo.html', 'huh') }
347
+ )
348
+
349
+ # Create unknown test file
350
+ File.open('foo', 'w') { |io| io.write('hello') }
351
+ assert_equal(
352
+ 'huh',
353
+ autocompiler.instance_eval { mime_type_of('foo', 'huh') }
354
+ )
355
+ end
356
+ end
357
+
358
+ def test_serve_with_working_item
359
+ if_have 'mime/types', 'rack' do
360
+ # Create site
361
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
362
+
363
+ FileUtils.cd('bar') do
364
+ # Create item
365
+ File.open('content/index.html', 'w') do |io|
366
+ io.write "Moo!"
367
+ end
368
+
369
+ # Create output file
370
+ File.open('output/index.html', 'w') do |io|
371
+ io.write "Compiled moo!"
372
+ end
373
+
374
+ # Create site
375
+ site = Nanoc3::Site.new('.')
376
+ site.load_data
377
+ site.compiler.expects(:run).with(site.items[0])
378
+
379
+ # Create autocompiler
380
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
381
+ autocompiler.stubs(:build_site)
382
+ autocompiler.stubs(:site).returns(site)
383
+
384
+ # Serve
385
+ status, headers, body = autocompiler.instance_eval { call('PATH_INFO' => '/') }
386
+
387
+ # Check response
388
+ assert_equal(200, status)
389
+ assert_equal('text/html', headers['Content-Type'])
390
+ body.each do |b|
391
+ assert_equal "Compiled moo!", b
392
+ end
393
+ end
394
+ end
395
+ end
396
+
397
+ def test_serve_with_broken_item
398
+ if_have 'mime/types', 'rack' do
399
+ # Create site
400
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
401
+
402
+ FileUtils.cd('bar') do
403
+ # Create item
404
+ File.open('content/whatever.html', 'w') do |io|
405
+ io.write "Whatever!"
406
+ end
407
+
408
+ # Create site
409
+ site = Nanoc3::Site.new('.')
410
+ site.load_data
411
+ site.compiler.expects(:run).raises(RuntimeError, 'aah! fail!')
412
+
413
+ # Create autocompiler
414
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
415
+ autocompiler.stubs(:build_site)
416
+ autocompiler.stubs(:site).returns(site)
417
+
418
+ # Serve
419
+ assert_raises(RuntimeError) do
420
+ autocompiler.instance_eval { call('PATH_INFO' => '/whatever/') }
421
+ end
422
+ end
423
+ end
424
+ end
425
+
426
+ def test_reload_config_file_before_each_request
427
+ # Create site
428
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
429
+
430
+ FileUtils.cd('foo') do
431
+ # Create item that outputs config elements
432
+ File.open('content/index.html', 'w') do |io|
433
+ io.write "The Grand Value of Configuration is <%= @config[:value] %>!"
434
+ end
435
+
436
+ # Create autocompiler
437
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
438
+
439
+ # Set config to 1st value
440
+ File.open('config.yaml', 'w') do |io|
441
+ io.write "value: Foo"
442
+ end
443
+ File.utime(Time.now+5, Time.now+5, 'config.yaml')
444
+
445
+ # Check
446
+ status, headers, body = autocompiler.call('PATH_INFO' => '/')
447
+ body.each do |b|
448
+ assert_match /The Grand Value of Configuration is Foo!/, b
449
+ end
450
+
451
+ # Set config to 2nd value
452
+ File.open('config.yaml', 'w') do |io|
453
+ io.write "value: Bar"
454
+ end
455
+ File.utime(Time.now+5, Time.now+5, 'config.yaml')
456
+
457
+ # Check
458
+ status, headers, body = autocompiler.call('PATH_INFO' => '/')
459
+ body.each do |b|
460
+ assert_match /The Grand Value of Configuration is Bar!/, b
461
+ end
462
+ end
463
+ end
464
+
465
+ def test_call_with_uri_encoded_path
466
+ # Create autocompiler
467
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
468
+
469
+ # Mock dependencies
470
+ site = mock
471
+ site.stubs(:config).returns({ :output_dir => 'output/' })
472
+ site.stubs(:items).returns([])
473
+ autocompiler.stubs(:build_site)
474
+ autocompiler.stubs(:site).returns(site)
475
+
476
+ # Test
477
+ result = autocompiler.call('PATH_INFO' => '/%73oftware')
478
+ assert_equal 404, result[0]
479
+ assert_match "File not found: /software\n", result[2][0]
480
+ end
481
+
482
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Extra::FileProxyTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_create_many
10
+ if_implemented do
11
+ # Create test file
12
+ File.open('test.txt', 'w') { |io| }
13
+
14
+ # Create lots of file proxies
15
+ count = Process.getrlimit(Process::RLIMIT_NOFILE)[0] + 5
16
+ file_proxies = []
17
+ count.times { file_proxies << Nanoc3::Extra::FileProxy.new('test.txt') }
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Extra::VCSTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_named
10
+ assert_nil(Nanoc3::Extra::VCS.named(:lkasjdlkfjlkasdfkj))
11
+
12
+ refute_nil(Nanoc3::Extra::VCS.named(:svn))
13
+ refute_nil(Nanoc3::Extra::VCS.named(:subversion))
14
+ end
15
+
16
+ def test_not_implemented
17
+ vcs = Nanoc3::Extra::VCS.new
18
+
19
+ assert_raises(NotImplementedError) { vcs.add('x') }
20
+ assert_raises(NotImplementedError) { vcs.remove('x') }
21
+ assert_raises(NotImplementedError) { vcs.move('x', 'y') }
22
+ end
23
+
24
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Extra::Validators::LinksTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_is_external_href?
10
+ # Create validator
11
+ validator = Nanoc3::Extra::Validators::Links.new(nil, nil)
12
+
13
+ # Test
14
+ assert validator.send(:is_external_href?, 'http://example.com/')
15
+ assert validator.send(:is_external_href?, 'https://example.com/')
16
+ assert validator.send(:is_external_href?, 'mailto:bob@example.com')
17
+ assert !validator.send(:is_external_href?, '../stuff')
18
+ assert !validator.send(:is_external_href?, '/stuff')
19
+ end
20
+
21
+ def test_is_valid_internal_href?
22
+ # Create files
23
+ FileUtils.mkdir_p('output')
24
+ FileUtils.mkdir_p('output/stuff')
25
+ File.open('output/origin', 'w') { |io| io.write('hi') }
26
+ File.open('output/foo', 'w') { |io| io.write('hi') }
27
+ File.open('output/stuff/blah', 'w') { |io| io.write('hi') }
28
+
29
+ # Create validator
30
+ validator = Nanoc3::Extra::Validators::Links.new('output', [ 'index.html' ])
31
+
32
+ # Test
33
+ assert validator.send(:is_valid_internal_href?, 'foo', 'output/origin')
34
+ assert validator.send(:is_valid_internal_href?, 'origin', 'output/origin')
35
+ assert validator.send(:is_valid_internal_href?, 'stuff/blah', 'output/origin')
36
+ assert validator.send(:is_valid_internal_href?, '/foo', 'output/origin')
37
+ assert validator.send(:is_valid_internal_href?, '/origin', 'output/origin')
38
+ assert validator.send(:is_valid_internal_href?, '/stuff/blah', 'output/origin')
39
+ end
40
+
41
+ def test_is_valid_external_href?
42
+ # Create validator
43
+ validator = Nanoc3::Extra::Validators::Links.new('output', [ 'index.html' ])
44
+ validator.stubs(:fetch_http_status_for).returns(200)
45
+
46
+ # Test
47
+ assert validator.send(:is_valid_external_href?, 'http://example.com/')
48
+ assert validator.send(:is_valid_external_href?, 'https://example.com/')
49
+ assert validator.send(:is_valid_external_href?, 'foo://example.com/')
50
+ refute validator.send(:is_valid_external_href?, 'http://example.com/">')
51
+ end
52
+
53
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Extra::Validators::W3CTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_simple
10
+ if_have 'w3c_validators' do
11
+ # Create some sample files
12
+ %w{ foo bar baz }.each do |filename|
13
+ %w{ xxx yyy }.each do |extension|
14
+ File.open("#{filename}.#{extension}", 'w') { |io| io.write("hello") }
15
+ end
16
+ end
17
+
18
+ # Create validator
19
+ w3c = Nanoc3::Extra::Validators::W3C.new('.', [ :xxx ])
20
+
21
+ # Configure expectations
22
+ validator_result = mock
23
+ validator_result.expects(:errors).times(3)
24
+ validator = mock
25
+ validator.expects(:validate_file).times(3).returns(validator_result)
26
+ w3c.expects(:types_to_extensions).with([ :xxx ]).returns([ 'xxx' ])
27
+ w3c.expects(:validator_for).with('xxx').times(3).returns(validator)
28
+ w3c.expects(:validation_started).times(3)
29
+ w3c.expects(:validation_ended).times(3)
30
+
31
+ # Run
32
+ w3c.run
33
+ end
34
+ end
35
+
36
+ def test_with_unknown_types
37
+ if_have 'w3c_validators' do
38
+ # Create validator
39
+ w3c = Nanoc3::Extra::Validators::W3C.new('.', [ :foo ])
40
+
41
+ # Test
42
+ exception = assert_raises RuntimeError do
43
+ w3c.run
44
+ end
45
+ assert_equal 'unknown type: foo', exception.message
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::BlueClothTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if_have 'bluecloth' do
11
+ # Create filter
12
+ filter = ::Nanoc3::Filters::BlueCloth.new
13
+
14
+ # Run filter
15
+ result = filter.run("> Quote")
16
+ assert_match %r{<blockquote>\s*<p>Quote</p>\s*</blockquote>}, result
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::CodeRayTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter_without_language
10
+ if_have 'coderay' do
11
+ # Get filter
12
+ filter = ::Nanoc3::Filters::CodeRay.new
13
+
14
+ # Run filter
15
+ code = "def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end"
16
+ assert_raises(ArgumentError) do
17
+ filter.run(code)
18
+ end
19
+ end
20
+ end
21
+
22
+ def test_filter_with_known_language
23
+ if_have 'coderay' do
24
+ # Get filter
25
+ filter = ::Nanoc3::Filters::CodeRay.new
26
+
27
+ # Run filter
28
+ code = "def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end"
29
+ result = filter.run(code, :language => 'ruby')
30
+ assert_match %r{^<span class="r">def</span> <span class="fu">some_function</span>}, result
31
+ end
32
+ end
33
+
34
+ def test_filter_with_unknown_language
35
+ if_have 'coderay' do
36
+ # Get filter
37
+ filter = ::Nanoc3::Filters::CodeRay.new
38
+
39
+ # Run filter
40
+ code = "def some_function ; x = blah.foo ; x.bar 'xyzzy' ; end"
41
+ result = filter.run(code, :language => 'skldfhjsdhfjszfnocmluhfixmersumulh')
42
+ assert_equal code, result
43
+ end
44
+ end
45
+
46
+ end