nanoc3 3.1.9 → 3.2.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/LICENSE +1 -1
  2. data/NEWS.md +0 -50
  3. data/README.md +3 -15
  4. data/bin/nanoc3 +2 -0
  5. data/lib/nanoc3/base/checksummer.rb +40 -0
  6. data/lib/nanoc3/base/code_snippet.rb +30 -12
  7. data/lib/nanoc3/base/compiled_content_cache.rb +86 -0
  8. data/lib/nanoc3/base/compiler.rb +134 -95
  9. data/lib/nanoc3/base/compiler_dsl.rb +12 -11
  10. data/lib/nanoc3/base/core_ext/string.rb +2 -2
  11. data/lib/nanoc3/base/data_source.rb +17 -16
  12. data/lib/nanoc3/base/dependency_tracker.rb +102 -121
  13. data/lib/nanoc3/base/directed_graph.rb +65 -3
  14. data/lib/nanoc3/base/errors.rb +20 -16
  15. data/lib/nanoc3/base/item.rb +58 -50
  16. data/lib/nanoc3/base/item_rep.rb +177 -150
  17. data/lib/nanoc3/base/layout.rb +51 -18
  18. data/lib/nanoc3/base/notification_center.rb +8 -8
  19. data/lib/nanoc3/base/plugin_registry.rb +9 -9
  20. data/lib/nanoc3/base/rule.rb +18 -9
  21. data/lib/nanoc3/base/rule_context.rb +5 -5
  22. data/lib/nanoc3/base/site.rb +135 -47
  23. data/lib/nanoc3/base.rb +21 -19
  24. data/lib/nanoc3/cli/base.rb +51 -74
  25. data/lib/nanoc3/cli/commands/autocompile.rb +3 -0
  26. data/lib/nanoc3/cli/commands/compile.rb +35 -74
  27. data/lib/nanoc3/cli/commands/create_site.rb +17 -5
  28. data/lib/nanoc3/cli/commands/debug.rb +11 -4
  29. data/lib/nanoc3/cli/commands/view.rb +0 -1
  30. data/lib/nanoc3/cli/commands/watch.rb +148 -0
  31. data/lib/nanoc3/cli/commands.rb +1 -0
  32. data/lib/nanoc3/cli/logger.rb +15 -21
  33. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -1
  34. data/lib/nanoc3/data_sources/filesystem.rb +11 -40
  35. data/lib/nanoc3/data_sources/filesystem_unified.rb +22 -22
  36. data/lib/nanoc3/extra/auto_compiler.rb +1 -1
  37. data/lib/nanoc3/extra/chick.rb +8 -8
  38. data/lib/nanoc3/extra/deployers/rsync.rb +2 -3
  39. data/lib/nanoc3/extra/validators/links.rb +32 -51
  40. data/lib/nanoc3/extra/validators/w3c.rb +2 -2
  41. data/lib/nanoc3/extra/vcs.rb +1 -1
  42. data/lib/nanoc3/filters/colorize_syntax.rb +15 -19
  43. data/lib/nanoc3/filters/erb.rb +1 -5
  44. data/lib/nanoc3/filters/erubis.rb +1 -5
  45. data/lib/nanoc3/filters/haml.rb +1 -2
  46. data/lib/nanoc3/filters/less.rb +2 -51
  47. data/lib/nanoc3/filters/mustache.rb +21 -0
  48. data/lib/nanoc3/filters/rdiscount.rb +1 -2
  49. data/lib/nanoc3/filters/relativize_paths.rb +3 -2
  50. data/lib/nanoc3/filters/sass.rb +50 -56
  51. data/lib/nanoc3/filters.rb +2 -0
  52. data/lib/nanoc3/helpers/blogging.rb +22 -29
  53. data/lib/nanoc3/helpers/breadcrumbs.rb +1 -1
  54. data/lib/nanoc3/helpers/capturing.rb +1 -1
  55. data/lib/nanoc3/helpers/filtering.rb +1 -1
  56. data/lib/nanoc3/helpers/link_to.rb +10 -21
  57. data/lib/nanoc3/helpers/rendering.rb +5 -24
  58. data/lib/nanoc3/helpers/tagging.rb +6 -6
  59. data/lib/nanoc3/helpers/text.rb +2 -2
  60. data/lib/nanoc3.rb +1 -1
  61. metadata +35 -93
  62. data/.gemtest +0 -0
  63. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  64. data/nanoc3.gemspec +0 -41
  65. data/tasks/clean.rake +0 -11
  66. data/tasks/doc.rake +0 -14
  67. data/tasks/gem.rake +0 -13
  68. data/tasks/test.rake +0 -38
  69. data/test/base/core_ext/array_spec.rb +0 -23
  70. data/test/base/core_ext/hash_spec.rb +0 -41
  71. data/test/base/core_ext/string_spec.rb +0 -27
  72. data/test/base/test_code_snippet.rb +0 -33
  73. data/test/base/test_compiler.rb +0 -410
  74. data/test/base/test_compiler_dsl.rb +0 -121
  75. data/test/base/test_context.rb +0 -33
  76. data/test/base/test_data_source.rb +0 -48
  77. data/test/base/test_dependency_tracker.rb +0 -510
  78. data/test/base/test_directed_graph.rb +0 -91
  79. data/test/base/test_filter.rb +0 -85
  80. data/test/base/test_item.rb +0 -141
  81. data/test/base/test_item_rep.rb +0 -953
  82. data/test/base/test_layout.rb +0 -44
  83. data/test/base/test_notification_center.rb +0 -36
  84. data/test/base/test_plugin.rb +0 -32
  85. data/test/base/test_rule.rb +0 -21
  86. data/test/base/test_rule_context.rb +0 -63
  87. data/test/base/test_site.rb +0 -366
  88. data/test/cli/commands/test_compile.rb +0 -12
  89. data/test/cli/commands/test_create_item.rb +0 -12
  90. data/test/cli/commands/test_create_layout.rb +0 -28
  91. data/test/cli/commands/test_create_site.rb +0 -24
  92. data/test/cli/commands/test_help.rb +0 -12
  93. data/test/cli/commands/test_info.rb +0 -12
  94. data/test/cli/commands/test_update.rb +0 -12
  95. data/test/cli/test_logger.rb +0 -12
  96. data/test/data_sources/test_filesystem.rb +0 -420
  97. data/test/data_sources/test_filesystem_unified.rb +0 -538
  98. data/test/data_sources/test_filesystem_verbose.rb +0 -359
  99. data/test/extra/core_ext/test_enumerable.rb +0 -32
  100. data/test/extra/core_ext/test_time.rb +0 -17
  101. data/test/extra/deployers/test_rsync.rb +0 -234
  102. data/test/extra/test_auto_compiler.rb +0 -482
  103. data/test/extra/test_file_proxy.rb +0 -21
  104. data/test/extra/test_vcs.rb +0 -24
  105. data/test/extra/validators/test_links.rb +0 -53
  106. data/test/extra/validators/test_w3c.rb +0 -49
  107. data/test/filters/test_bluecloth.rb +0 -20
  108. data/test/filters/test_coderay.rb +0 -46
  109. data/test/filters/test_colorize_syntax.rb +0 -84
  110. data/test/filters/test_erb.rb +0 -72
  111. data/test/filters/test_erubis.rb +0 -72
  112. data/test/filters/test_haml.rb +0 -98
  113. data/test/filters/test_kramdown.rb +0 -20
  114. data/test/filters/test_less.rb +0 -118
  115. data/test/filters/test_markaby.rb +0 -26
  116. data/test/filters/test_maruku.rb +0 -20
  117. data/test/filters/test_rainpress.rb +0 -31
  118. data/test/filters/test_rdiscount.rb +0 -33
  119. data/test/filters/test_rdoc.rb +0 -18
  120. data/test/filters/test_redcloth.rb +0 -20
  121. data/test/filters/test_relativize_paths.rb +0 -231
  122. data/test/filters/test_rubypants.rb +0 -20
  123. data/test/filters/test_sass.rb +0 -235
  124. data/test/gem_loader.rb +0 -11
  125. data/test/helper.rb +0 -99
  126. data/test/helpers/test_blogging.rb +0 -808
  127. data/test/helpers/test_breadcrumbs.rb +0 -83
  128. data/test/helpers/test_capturing.rb +0 -42
  129. data/test/helpers/test_filtering.rb +0 -108
  130. data/test/helpers/test_html_escape.rb +0 -18
  131. data/test/helpers/test_link_to.rb +0 -251
  132. data/test/helpers/test_rendering.rb +0 -109
  133. data/test/helpers/test_tagging.rb +0 -89
  134. data/test/helpers/test_text.rb +0 -26
  135. data/test/helpers/test_xml_sitemap.rb +0 -69
  136. data/test/tasks/test_clean.rb +0 -71
@@ -1,482 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,24 +0,0 @@
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
@@ -1,53 +0,0 @@
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
@@ -1,49 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,46 +0,0 @@
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