nanoc3 3.2.0a3 → 3.2.0a4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +23 -4
  4. data/README.md +7 -0
  5. data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
  6. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
  7. data/lib/nanoc3/base/compilation/compiler.rb +112 -175
  8. data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
  9. data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
  10. data/lib/nanoc3/base/compilation/filter.rb +4 -3
  11. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
  12. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
  13. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
  14. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
  15. data/lib/nanoc3/base/compilation/rule.rb +3 -1
  16. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
  17. data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
  18. data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
  19. data/lib/nanoc3/base/core_ext/array.rb +20 -0
  20. data/lib/nanoc3/base/core_ext/hash.rb +30 -0
  21. data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
  22. data/lib/nanoc3/base/core_ext/string.rb +12 -0
  23. data/lib/nanoc3/base/core_ext.rb +1 -0
  24. data/lib/nanoc3/base/directed_graph.rb +11 -3
  25. data/lib/nanoc3/base/errors.rb +0 -4
  26. data/lib/nanoc3/base/memoization.rb +72 -0
  27. data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
  28. data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
  29. data/lib/nanoc3/base/source_data/configuration.rb +20 -0
  30. data/lib/nanoc3/base/source_data/item.rb +29 -4
  31. data/lib/nanoc3/base/source_data/layout.rb +20 -1
  32. data/lib/nanoc3/base/source_data/site.rb +49 -26
  33. data/lib/nanoc3/base/store.rb +10 -1
  34. data/lib/nanoc3/base.rb +6 -1
  35. data/lib/nanoc3/cli/base.rb +20 -7
  36. data/lib/nanoc3/cli/commands/compile.rb +0 -2
  37. data/lib/nanoc3/cli/commands/create_site.rb +16 -7
  38. data/lib/nanoc3/cli/commands/debug.rb +3 -3
  39. data/lib/nanoc3/cli/commands/view.rb +1 -0
  40. data/lib/nanoc3/cli/commands/watch.rb +2 -1
  41. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
  42. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
  43. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
  44. data/lib/nanoc3/data_sources/filesystem.rb +17 -3
  45. data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
  46. data/lib/nanoc3/extra/auto_compiler.rb +5 -1
  47. data/lib/nanoc3/extra/core_ext/time.rb +1 -1
  48. data/lib/nanoc3/extra/file_proxy.rb +11 -1
  49. data/lib/nanoc3/extra/validators/links.rb +1 -1
  50. data/lib/nanoc3/filters/asciidoc.rb +3 -3
  51. data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
  52. data/lib/nanoc3/filters/erb.rb +16 -6
  53. data/lib/nanoc3/filters/erubis.rb +5 -1
  54. data/lib/nanoc3/filters/haml.rb +2 -1
  55. data/lib/nanoc3/filters/less.rb +3 -6
  56. data/lib/nanoc3/filters/mustache.rb +3 -0
  57. data/lib/nanoc3/filters/redcarpet.rb +27 -0
  58. data/lib/nanoc3/filters/sass.rb +1 -5
  59. data/lib/nanoc3/filters/slim.rb +25 -0
  60. data/lib/nanoc3/filters/typogruby.rb +23 -0
  61. data/lib/nanoc3/filters.rb +6 -0
  62. data/lib/nanoc3/helpers/blogging.rb +22 -26
  63. data/lib/nanoc3/helpers/rendering.rb +1 -1
  64. data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
  65. data/lib/nanoc3.rb +24 -3
  66. data/nanoc3.gemspec +4 -3
  67. data/tasks/clean.rake +11 -0
  68. data/tasks/doc.rake +14 -0
  69. data/tasks/test.rake +38 -0
  70. data/test/base/core_ext/array_spec.rb +55 -0
  71. data/test/base/core_ext/hash_spec.rb +82 -0
  72. data/test/base/core_ext/pathname_spec.rb +29 -0
  73. data/test/base/core_ext/string_spec.rb +39 -0
  74. data/test/base/test_checksum_store.rb +37 -0
  75. data/test/base/test_code_snippet.rb +33 -0
  76. data/test/base/test_compiler.rb +303 -0
  77. data/test/base/test_compiler_dsl.rb +156 -0
  78. data/test/base/test_context.rb +33 -0
  79. data/test/base/test_data_source.rb +48 -0
  80. data/test/base/test_dependency_tracker.rb +264 -0
  81. data/test/base/test_directed_graph.rb +285 -0
  82. data/test/base/test_filter.rb +85 -0
  83. data/test/base/test_item.rb +164 -0
  84. data/test/base/test_item_rep.rb +555 -0
  85. data/test/base/test_layout.rb +44 -0
  86. data/test/base/test_memoization.rb +53 -0
  87. data/test/base/test_notification_center.rb +36 -0
  88. data/test/base/test_outdatedness_checker.rb +365 -0
  89. data/test/base/test_plugin.rb +32 -0
  90. data/test/base/test_rule.rb +21 -0
  91. data/test/base/test_rule_context.rb +67 -0
  92. data/test/base/test_site.rb +144 -0
  93. data/test/cli/commands/test_compile.rb +12 -0
  94. data/test/cli/commands/test_create_item.rb +12 -0
  95. data/test/cli/commands/test_create_layout.rb +28 -0
  96. data/test/cli/commands/test_create_site.rb +24 -0
  97. data/test/cli/commands/test_help.rb +12 -0
  98. data/test/cli/commands/test_info.rb +12 -0
  99. data/test/cli/commands/test_update.rb +12 -0
  100. data/test/cli/test_logger.rb +12 -0
  101. data/test/data_sources/test_filesystem.rb +420 -0
  102. data/test/data_sources/test_filesystem_unified.rb +562 -0
  103. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  104. data/test/extra/core_ext/test_enumerable.rb +32 -0
  105. data/test/extra/core_ext/test_time.rb +17 -0
  106. data/test/extra/deployers/test_rsync.rb +234 -0
  107. data/test/extra/test_auto_compiler.rb +417 -0
  108. data/test/extra/test_file_proxy.rb +21 -0
  109. data/test/extra/test_vcs.rb +24 -0
  110. data/test/extra/validators/test_links.rb +53 -0
  111. data/test/extra/validators/test_w3c.rb +49 -0
  112. data/test/filters/test_asciidoc.rb +22 -0
  113. data/test/filters/test_bluecloth.rb +20 -0
  114. data/test/filters/test_coderay.rb +46 -0
  115. data/test/filters/test_colorize_syntax.rb +149 -0
  116. data/test/filters/test_erb.rb +101 -0
  117. data/test/filters/test_erubis.rb +72 -0
  118. data/test/filters/test_haml.rb +98 -0
  119. data/test/filters/test_kramdown.rb +20 -0
  120. data/test/filters/test_less.rb +59 -0
  121. data/test/filters/test_markaby.rb +26 -0
  122. data/test/filters/test_maruku.rb +20 -0
  123. data/test/filters/test_mustache.rb +27 -0
  124. data/test/filters/test_rainpress.rb +31 -0
  125. data/test/filters/test_rdiscount.rb +33 -0
  126. data/test/filters/test_rdoc.rb +18 -0
  127. data/test/filters/test_redcarpet.rb +63 -0
  128. data/test/filters/test_redcloth.rb +35 -0
  129. data/test/filters/test_relativize_paths.rb +231 -0
  130. data/test/filters/test_rubypants.rb +20 -0
  131. data/test/filters/test_sass.rb +103 -0
  132. data/test/filters/test_slim.rb +37 -0
  133. data/test/filters/test_typogruby.rb +23 -0
  134. data/test/helper.rb +161 -0
  135. data/test/helpers/test_blogging.rb +756 -0
  136. data/test/helpers/test_breadcrumbs.rb +83 -0
  137. data/test/helpers/test_capturing.rb +43 -0
  138. data/test/helpers/test_filtering.rb +108 -0
  139. data/test/helpers/test_html_escape.rb +34 -0
  140. data/test/helpers/test_link_to.rb +251 -0
  141. data/test/helpers/test_rendering.rb +90 -0
  142. data/test/helpers/test_tagging.rb +89 -0
  143. data/test/helpers/test_text.rb +26 -0
  144. data/test/helpers/test_xml_sitemap.rb +105 -0
  145. data/test/tasks/test_clean.rb +69 -0
  146. metadata +96 -27
  147. data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -0,0 +1,417 @@
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_with_index_filename
10
+ if_have 'mime/types', 'rack' do
11
+ # Create site
12
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
13
+
14
+ FileUtils.cd('bar') do
15
+ # Create item
16
+ FileUtils.mkdir_p('content/foo')
17
+ File.open('content/foo/index.html', 'w') do |io|
18
+ io.write "Moo!"
19
+ end
20
+
21
+ # Create output file
22
+ FileUtils.mkdir_p('output/foo')
23
+ File.open('output/foo/index.html', 'w') do |io|
24
+ io.write "Compiled moo!"
25
+ end
26
+
27
+ # Create site
28
+ site = Nanoc3::Site.new('.')
29
+ site.expects(:compile)
30
+
31
+ # Create autocompiler
32
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
33
+ autocompiler.stubs(:build_site)
34
+ autocompiler.stubs(:site).returns(site)
35
+
36
+ # Serve
37
+ status, headers, body = autocompiler.instance_eval { call('PATH_INFO' => '/foo/index.html') }
38
+
39
+ # Check response
40
+ assert_equal(200, status)
41
+ assert_equal('text/html', headers['Content-Type'])
42
+ body.each do |b|
43
+ assert_equal "Compiled moo!", b
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def test_handle_request_with_broken_url
50
+ if_have 'mime/types', 'rack' do
51
+ # Create site
52
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
53
+
54
+ FileUtils.cd('bar') do
55
+ # Create site
56
+ site = Nanoc3::Site.new('.')
57
+
58
+ # Create autocompiler
59
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
60
+ autocompiler.stubs(:build_site)
61
+ autocompiler.stubs(:site).returns(site)
62
+
63
+ # Serve
64
+ status, headers, body = autocompiler.instance_eval { call('PATH_INFO' => '/afjwiagoawf.html') }
65
+
66
+ # Check response
67
+ assert_equal(404, status)
68
+ end
69
+ end
70
+ end
71
+
72
+ def test_handle_request_with_file
73
+ if_have 'rack' do
74
+ # Create file
75
+ FileUtils.mkdir_p('out')
76
+ File.open('out/somefile.txt', 'w') { |io| io.write('hello') }
77
+
78
+ # Create file server
79
+ file_server = mock
80
+ def file_server.call(env)
81
+ @expected_path_info = 'somefile.txt'
82
+ @actual_path_info = env['PATH_INFO']
83
+ end
84
+ def file_server.expected_path_info ; @expected_path_info ; end
85
+ def file_server.actual_path_info ; @actual_path_info ; end
86
+
87
+ # Create site
88
+ site = mock
89
+ site.expects(:items).returns([])
90
+ site.expects(:config).returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
91
+
92
+ # Create autocompiler
93
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
94
+ autocompiler.stubs(:build_site)
95
+ autocompiler.stubs(:site).returns(site)
96
+ autocompiler.expects(:file_server).returns(file_server)
97
+
98
+ # Run
99
+ autocompiler.instance_eval { call('PATH_INFO' => 'somefile.txt') }
100
+
101
+ # Check
102
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
103
+ end
104
+ end
105
+
106
+ def test_handle_request_with_dir_with_slash_with_index_file
107
+ if_have 'rack' do
108
+ # Create file
109
+ FileUtils.mkdir_p('out/foo/bar')
110
+ File.open('out/foo/bar/index.html', 'w') { |io| io.write('hello') }
111
+
112
+ # Create file server
113
+ file_server = mock
114
+ def file_server.call(env)
115
+ @expected_path_info = '/foo/bar/index.html'
116
+ @actual_path_info = env['PATH_INFO']
117
+ end
118
+ def file_server.expected_path_info ; @expected_path_info ; end
119
+ def file_server.actual_path_info ; @actual_path_info ; end
120
+
121
+ # Create site
122
+ site = mock
123
+ site.expects(:items).returns([])
124
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
125
+
126
+ # Create autocompiler
127
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
128
+ autocompiler.stubs(:build_site)
129
+ autocompiler.stubs(:site).returns(site)
130
+ autocompiler.expects(:file_server).returns(file_server)
131
+
132
+ # Run
133
+ autocompiler.instance_eval { call('PATH_INFO' => '/foo/bar/') }
134
+
135
+ # Check
136
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
137
+ end
138
+ end
139
+
140
+ def test_handle_request_with_dir_with_slash_without_index_file
141
+ if_have 'rack' do
142
+ # Create file
143
+ FileUtils.mkdir_p('out/foo/bar')
144
+ File.open('out/foo/bar/someotherfile.txt', 'w') { |io| io.write('hello') }
145
+
146
+ # Create file server
147
+ file_server = mock
148
+ def file_server.call(env)
149
+ @expected_path_info = 'foo/bar/'
150
+ @actual_path_info = env['PATH_INFO']
151
+ end
152
+ def file_server.expected_path_info ; @expected_path_info ; end
153
+ def file_server.actual_path_info ; @actual_path_info ; end
154
+
155
+ # Create site
156
+ site = mock
157
+ site.expects(:items).returns([])
158
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
159
+
160
+ # Create autocompiler
161
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
162
+ autocompiler.stubs(:build_site)
163
+ autocompiler.stubs(:site).returns(site)
164
+ autocompiler.expects(:file_server).returns(file_server)
165
+
166
+ # Run
167
+ autocompiler.instance_eval { call('PATH_INFO' => 'foo/bar/') }
168
+
169
+ # Check
170
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
171
+ end
172
+ end
173
+
174
+ def test_handle_request_with_dir_without_slash_with_index_file
175
+ if_have 'rack' do
176
+ # Create file
177
+ FileUtils.mkdir_p('out/foo/bar')
178
+ File.open('out/foo/bar/index.html', 'w') { |io| io.write('hello') }
179
+
180
+ # Create file server
181
+ file_server = mock
182
+ def file_server.call(env)
183
+ @expected_path_info = 'foo/bar'
184
+ @actual_path_info = env['PATH_INFO']
185
+ end
186
+ def file_server.expected_path_info ; @expected_path_info ; end
187
+ def file_server.actual_path_info ; @actual_path_info ; end
188
+
189
+ # Create site
190
+ site = mock
191
+ site.expects(:items).returns([])
192
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
193
+
194
+ # Create autocompiler
195
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
196
+ autocompiler.stubs(:build_site)
197
+ autocompiler.stubs(:site).returns(site)
198
+ autocompiler.expects(:file_server).returns(file_server)
199
+
200
+ # Run
201
+ autocompiler.instance_eval { call('PATH_INFO' => 'foo/bar') }
202
+
203
+ # Check
204
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
205
+ end
206
+ end
207
+
208
+ def test_handle_request_with_dir_without_slash_without_index_file
209
+ if_have 'rack' do
210
+ # Create file
211
+ FileUtils.mkdir_p('out/foo/bar')
212
+ File.open('out/foo/bar/someotherfile.txt', 'w') { |io| io.write('hello') }
213
+
214
+ # Create file server
215
+ file_server = mock
216
+ def file_server.call(env)
217
+ @expected_path_info = 'foo/bar'
218
+ @actual_path_info = env['PATH_INFO']
219
+ end
220
+ def file_server.expected_path_info ; @expected_path_info ; end
221
+ def file_server.actual_path_info ; @actual_path_info ; end
222
+
223
+ # Create site
224
+ site = mock
225
+ site.expects(:items).returns([])
226
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
227
+
228
+ # Create autocompiler
229
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
230
+ autocompiler.stubs(:build_site)
231
+ autocompiler.stubs(:site).returns(site)
232
+ autocompiler.expects(:file_server).returns(file_server)
233
+
234
+ # Run
235
+ autocompiler.instance_eval { call('PATH_INFO' => 'foo/bar') }
236
+
237
+ # Check
238
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
239
+ end
240
+ end
241
+
242
+ def test_handle_request_with_404
243
+ if_have 'rack' do
244
+ # Create file server
245
+ file_server = mock
246
+ def file_server.call(env)
247
+ @expected_path_info = 'four-oh-four.txt'
248
+ @actual_path_info = env['PATH_INFO']
249
+ end
250
+ def file_server.expected_path_info ; @expected_path_info ; end
251
+ def file_server.actual_path_info ; @actual_path_info ; end
252
+
253
+ # Create site
254
+ site = mock
255
+ site.expects(:items).returns([])
256
+ site.expects(:config).at_least_once.returns({ :output_dir => 'out', :index_filenames => [ 'index.html' ] })
257
+
258
+ # Create autocompiler
259
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
260
+ autocompiler.stubs(:build_site)
261
+ autocompiler.stubs(:site).returns(site)
262
+ autocompiler.expects(:file_server).returns(file_server)
263
+
264
+ # Run
265
+ autocompiler.instance_eval { call('PATH_INFO' => 'four-oh-four.txt') }
266
+
267
+ # Check
268
+ assert_equal(file_server.expected_path_info, file_server.actual_path_info)
269
+ end
270
+ end
271
+
272
+ def test_mime_type_of
273
+ if_have 'mime/types', 'rack' do
274
+ # Create autocompiler
275
+ autocompiler = Nanoc3::Extra::AutoCompiler.new(nil)
276
+
277
+ # Create known test file
278
+ File.open('foo.html', 'w') { |io| io.write('hello') }
279
+ assert_equal(
280
+ 'text/html',
281
+ autocompiler.instance_eval { mime_type_of('foo.html', 'huh') }
282
+ )
283
+
284
+ # Create unknown test file
285
+ File.open('foo', 'w') { |io| io.write('hello') }
286
+ assert_equal(
287
+ 'huh',
288
+ autocompiler.instance_eval { mime_type_of('foo', 'huh') }
289
+ )
290
+ end
291
+ end
292
+
293
+ def test_serve_with_working_item
294
+ if_have 'mime/types', 'rack' do
295
+ # Create site
296
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
297
+
298
+ FileUtils.cd('bar') do
299
+ # Create item
300
+ File.open('content/index.html', 'w') do |io|
301
+ io.write "Moo!"
302
+ end
303
+
304
+ # Create output file
305
+ File.open('output/index.html', 'w') do |io|
306
+ io.write "Compiled moo!"
307
+ end
308
+
309
+ # Create site
310
+ site = Nanoc3::Site.new('.')
311
+ site.expects(:compile)
312
+
313
+ # Create autocompiler
314
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
315
+ autocompiler.stubs(:build_site)
316
+ autocompiler.stubs(:site).returns(site)
317
+
318
+ # Serve
319
+ status, headers, body = autocompiler.instance_eval { call('PATH_INFO' => '/') }
320
+
321
+ # Check response
322
+ assert_equal(200, status)
323
+ assert_equal('text/html', headers['Content-Type'])
324
+ body.each do |b|
325
+ assert_equal "Compiled moo!", b
326
+ end
327
+ end
328
+ end
329
+ end
330
+
331
+ def test_serve_with_broken_item
332
+ if_have 'mime/types', 'rack' do
333
+ # Create site
334
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
335
+
336
+ FileUtils.cd('bar') do
337
+ # Create item
338
+ File.open('content/whatever.html', 'w') do |io|
339
+ io.write "Whatever!"
340
+ end
341
+
342
+ # Create site
343
+ site = Nanoc3::Site.new('.')
344
+ site.expects(:compile).raises(RuntimeError, 'aah! fail!')
345
+
346
+ # Create autocompiler
347
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
348
+ autocompiler.stubs(:build_site)
349
+ autocompiler.stubs(:site).returns(site)
350
+
351
+ # Serve
352
+ assert_raises(RuntimeError) do
353
+ autocompiler.instance_eval { call('PATH_INFO' => '/whatever/') }
354
+ end
355
+ end
356
+ end
357
+ end
358
+
359
+ def test_reload_config_file_before_each_request
360
+ if_have 'rack' do
361
+ # Create site
362
+ Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
363
+
364
+ FileUtils.cd('foo') do
365
+ # Create item that outputs config elements
366
+ File.open('content/index.html', 'w') do |io|
367
+ io.write "The Grand Value of Configuration is <%= @config[:value] %>!"
368
+ end
369
+
370
+ # Create autocompiler
371
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
372
+
373
+ # Set config to 1st value
374
+ File.open('config.yaml', 'w') do |io|
375
+ io.write "value: Foo"
376
+ end
377
+ File.utime(Time.now+5, Time.now+5, 'config.yaml')
378
+
379
+ # Check
380
+ status, headers, body = autocompiler.call('PATH_INFO' => '/')
381
+ body.each do |b|
382
+ assert_match /The Grand Value of Configuration is Foo!/, b
383
+ end
384
+
385
+ # Set config to 2nd value
386
+ File.open('config.yaml', 'w') do |io|
387
+ io.write "value: Bar"
388
+ end
389
+ File.utime(Time.now+5, Time.now+5, 'config.yaml')
390
+
391
+ # Check
392
+ status, headers, body = autocompiler.call('PATH_INFO' => '/')
393
+ body.each do |b|
394
+ assert_match /The Grand Value of Configuration is Bar!/, b
395
+ end
396
+ end
397
+ end
398
+ end
399
+
400
+ def test_call_with_uri_encoded_path
401
+ # Create autocompiler
402
+ autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
403
+
404
+ # Mock dependencies
405
+ site = mock
406
+ site.stubs(:config).returns({ :output_dir => 'output/' })
407
+ site.stubs(:items).returns([])
408
+ autocompiler.stubs(:build_site)
409
+ autocompiler.stubs(:site).returns(site)
410
+
411
+ # Test
412
+ result = autocompiler.call('PATH_INFO' => '/%73oftware')
413
+ assert_equal 404, result[0]
414
+ assert_match "File not found: /software\n", result[2][0]
415
+ end
416
+
417
+ 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,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::Filters::AsciiDocTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_filter
10
+ if `which asciidoc`.strip.empty?
11
+ skip "could not find asciidoc"
12
+ end
13
+
14
+ # Create filter
15
+ filter = ::Nanoc3::Filters::AsciiDoc.new
16
+
17
+ # Run filter
18
+ result = filter.run("== Blah blah")
19
+ assert_match %r{<h2 id="_blah_blah">Blah blah</h2>}, result
20
+ end
21
+
22
+ 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 => 'skldfhjsdhfjszfnocmluhfixfmersumulh')
42
+ assert_equal code, result
43
+ end
44
+ end
45
+
46
+ end