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,231 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test/helper'
4
-
5
- class Nanoc3::Filters::RelativizePathsTest < MiniTest::Unit::TestCase
6
-
7
- include Nanoc3::TestHelpers
8
-
9
- def test_filter_html_with_double_quotes
10
- # Create filter with mock item
11
- filter = Nanoc3::Filters::RelativizePaths.new
12
-
13
- # Mock item
14
- filter.instance_eval do
15
- @item_rep = MiniTest::Mock.new
16
- @item_rep.expect(:path, '/foo/bar/baz/')
17
- end
18
-
19
- # Set content
20
- raw_content = %[<a href="/foo">foo</a>]
21
- expected_content = %[<a href="../..">foo</a>]
22
-
23
- # Test
24
- actual_content = filter.run(raw_content, :type => :html)
25
- assert_equal(expected_content, actual_content)
26
- end
27
-
28
- def test_filter_html_with_single_quotes
29
- # Create filter with mock item
30
- filter = Nanoc3::Filters::RelativizePaths.new
31
-
32
- # Mock item
33
- filter.instance_eval do
34
- @item_rep = MiniTest::Mock.new
35
- @item_rep.expect(:path, '/foo/bar/baz/')
36
- end
37
-
38
- # Set content
39
- raw_content = %[<a href='/foo'>foo</a>]
40
- expected_content = %[<a href='../..'>foo</a>]
41
-
42
- # Test
43
- actual_content = filter.run(raw_content, :type => :html)
44
- assert_equal(expected_content, actual_content)
45
- end
46
-
47
- def test_filter_html_without_quotes
48
- # Create filter with mock item
49
- filter = Nanoc3::Filters::RelativizePaths.new
50
-
51
- # Mock item
52
- filter.instance_eval do
53
- @item_rep = MiniTest::Mock.new
54
- @item_rep.expect(:path, '/foo/bar/baz/')
55
- end
56
-
57
- # Set content
58
- raw_content = %[<a href=/foo>foo</a>]
59
- expected_content = %[<a href=../..>foo</a>]
60
-
61
- # Test
62
- actual_content = filter.run(raw_content, :type => :html)
63
- assert_equal(expected_content, actual_content)
64
- end
65
-
66
- def test_filter_html_multiple
67
- # Create filter with mock item
68
- filter = Nanoc3::Filters::RelativizePaths.new
69
-
70
- # Mock item
71
- filter.instance_eval do
72
- @item_rep = MiniTest::Mock.new
73
- @item_rep.expect(:path, '/foo/bar/baz/')
74
- end
75
-
76
- # Set content
77
- raw_content = %[<a href="/foo">foo</a> <a href="/bar">bar</a>]
78
- expected_content = %[<a href="../..">foo</a> <a href="../../../bar">bar</a>]
79
-
80
- # Test
81
- actual_content = filter.run(raw_content, :type => :html)
82
- assert_equal(expected_content, actual_content)
83
- end
84
-
85
- def test_filter_html_outside_tag
86
- # Create filter with mock item
87
- filter = Nanoc3::Filters::RelativizePaths.new
88
-
89
- # Mock item
90
- filter.instance_eval do
91
- @item_rep = MiniTest::Mock.new
92
- @item_rep.expect(:path, '/foo/bar/baz/')
93
- end
94
-
95
- # Set content
96
- raw_content = %[stuff href="/foo" more stuff]
97
- expected_content = %[stuff href="/foo" more stuff]
98
-
99
- # Test
100
- actual_content = filter.run(raw_content, :type => :html)
101
- assert_equal(expected_content, actual_content)
102
- end
103
-
104
- def test_filter_html_root
105
- # Create filter with mock item
106
- filter = Nanoc3::Filters::RelativizePaths.new
107
-
108
- # Mock item
109
- filter.instance_eval do
110
- @item_rep = MiniTest::Mock.new
111
- @item_rep.expect(:path, '/woof/meow/')
112
- end
113
-
114
- # Set content
115
- raw_content = %[<a href="/">foo</a>]
116
- expected_content = %[<a href="../../">foo</a>]
117
-
118
- # Test
119
- actual_content = filter.run(raw_content, :type => :html)
120
- assert_equal(expected_content, actual_content)
121
- end
122
-
123
- def test_filter_implicit
124
- # Create filter with mock item
125
- filter = Nanoc3::Filters::RelativizePaths.new
126
-
127
- # Test
128
- assert_raises(RuntimeError) do
129
- filter.run("moo")
130
- end
131
- end
132
-
133
- def test_filter_css_with_double_quotes
134
- # Create filter with mock item
135
- filter = Nanoc3::Filters::RelativizePaths.new
136
-
137
- # Mock item
138
- filter.instance_eval do
139
- @item_rep = MiniTest::Mock.new
140
- @item_rep.expect(:path, '/foo/bar/baz/')
141
- end
142
-
143
- # Set content
144
- raw_content = %[background: url("/foo/bar/background.png");]
145
- expected_content = %[background: url("../background.png");]
146
-
147
- # Test
148
- actual_content = filter.run(raw_content, :type => :css)
149
- assert_equal(expected_content, actual_content)
150
- end
151
-
152
- def test_filter_css_with_single_quotes
153
- # Create filter with mock item
154
- filter = Nanoc3::Filters::RelativizePaths.new
155
-
156
- # Mock item
157
- filter.instance_eval do
158
- @item_rep = MiniTest::Mock.new
159
- @item_rep.expect(:path, '/foo/bar/baz/')
160
- end
161
-
162
- # Set content
163
- raw_content = %[background: url('/foo/bar/background.png');]
164
- expected_content = %[background: url('../background.png');]
165
-
166
- # Test
167
- actual_content = filter.run(raw_content, :type => :css)
168
- assert_equal(expected_content, actual_content)
169
- end
170
-
171
- def test_filter_css_without_quotes
172
- # Create filter with mock item
173
- filter = Nanoc3::Filters::RelativizePaths.new
174
-
175
- # Mock item
176
- filter.instance_eval do
177
- @item_rep = MiniTest::Mock.new
178
- @item_rep.expect(:path, '/foo/bar/baz/')
179
- end
180
-
181
- # Set content
182
- raw_content = %[background: url(/foo/bar/background.png);]
183
- expected_content = %[background: url(../background.png);]
184
-
185
- # Test
186
- actual_content = filter.run(raw_content, :type => :css)
187
- assert_equal(expected_content, actual_content)
188
- end
189
-
190
- def test_filter_css_multiple
191
- # Create filter with mock item
192
- filter = Nanoc3::Filters::RelativizePaths.new
193
-
194
- # Mock item
195
- filter.instance_eval do
196
- @item_rep = MiniTest::Mock.new
197
- @item_rep.expect(:path, '/foo/bar/baz/')
198
- end
199
-
200
- # Set content
201
- raw_content = %[background: url(/foo/bar/a.png) url(/foo/bar/b.png);]
202
- expected_content = %[background: url(../a.png) url(../b.png);]
203
-
204
- # Test
205
- actual_content = filter.run(raw_content, :type => :css)
206
- assert_equal(expected_content, actual_content)
207
- end
208
-
209
- def test_filter_css_root
210
- # It is probably a bit weird to have “url(/)” in CSS, but I’ve made a
211
- # test case for this situation anyway. Can’t hurt…
212
-
213
- # Create filter with mock item
214
- filter = Nanoc3::Filters::RelativizePaths.new
215
-
216
- # Mock item
217
- filter.instance_eval do
218
- @item_rep = MiniTest::Mock.new
219
- @item_rep.expect(:path, '/woof/meow/')
220
- end
221
-
222
- # Set content
223
- raw_content = %[background: url(/);]
224
- expected_content = %[background: url(../../);]
225
-
226
- # Test
227
- actual_content = filter.run(raw_content, :type => :css)
228
- assert_equal(expected_content, actual_content)
229
- end
230
-
231
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test/helper'
4
-
5
- class Nanoc3::Filters::RubyPantsTest < MiniTest::Unit::TestCase
6
-
7
- include Nanoc3::TestHelpers
8
-
9
- def test_filter
10
- if_have 'rubypants' do
11
- # Get filter
12
- filter = ::Nanoc3::Filters::RubyPants.new
13
-
14
- # Run filter
15
- result = filter.run("Wait---what?")
16
- assert_equal("Wait&#8212;what?", result)
17
- end
18
- end
19
-
20
- end
@@ -1,235 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test/helper'
4
-
5
- class Nanoc3::Filters::SassTest < MiniTest::Unit::TestCase
6
-
7
- include Nanoc3::TestHelpers
8
-
9
- def test_filter
10
- if_have 'sass' do
11
- # Get filter
12
- filter = create_filter({ :foo => 'bar' })
13
-
14
- # Run filter
15
- result = filter.run(".foo #bar\n color: #f00")
16
- assert_match(/.foo\s+#bar\s*\{\s*color:\s+(red|#f00);?\s*\}/, result)
17
- end
18
- end
19
-
20
- def test_filter_with_params
21
- if_have 'sass' do
22
- # Create filter
23
- filter = create_filter({ :foo => 'bar' })
24
-
25
- # Check with compact
26
- result = filter.run(".foo #bar\n color: #f00", :style => 'compact')
27
- assert_match(/^\.foo #bar[\s\n]*\{[\s\n]*color:\s*(red|#f00);?[\s\n]*\}/m, result)
28
-
29
- # Check with compressed
30
- result = filter.run(".foo #bar\n color: #f00", :style => 'compressed')
31
- assert_match(/^\.foo #bar[\s\n]*\{[\s\n]*color:\s*(red|#f00);?[\s\n]*\}/m, result)
32
- end
33
- end
34
-
35
- def test_filter_error
36
- if_have 'sass' do
37
- # Create filter
38
- filter = create_filter
39
-
40
- # Run filter
41
- raised = false
42
- begin
43
- filter.run('$*#&!@($')
44
- rescue Sass::SyntaxError => e
45
- assert_match ':1', e.backtrace[0]
46
- raised = true
47
- end
48
- assert raised
49
- end
50
- end
51
-
52
- def test_filter_can_import_external_files
53
- if_have 'sass' do
54
- # Create filter
55
- filter = create_filter
56
-
57
- # Create sample file
58
- File.open('moo.sass', 'w') { |io| io.write "body\n color: red" }
59
-
60
- # Run filter
61
- filter.run('@import moo')
62
- end
63
- end
64
-
65
- def test_filter_can_import_relative_files
66
- if_have 'sass' do
67
- # Create filter
68
- filter = create_filter
69
-
70
- # Create sample file
71
- File.open('moo.sass', 'w') { |io| io.write %Q{@import subdir/relative} }
72
- FileUtils.mkdir_p("subdir")
73
- File.open('subdir/relative.sass', 'w') { |io| io.write "body\n color: red" }
74
-
75
- # Run filter
76
- filter.run('@import moo')
77
- end
78
- end
79
-
80
- def test_filter_will_skip_items_without_filename
81
- if_have 'sass' do
82
- # Create filter
83
- filter = create_filter
84
-
85
- # Create sample file
86
- File.open('moo.sass', 'w') { |io| io.write "body\n color: red" }
87
-
88
- # Run filter
89
- filter.run('@import moo')
90
- end
91
- end
92
-
93
- def test_css_imports_work
94
- if_have 'sass' do
95
- # Create filter
96
- filter = create_filter
97
-
98
- # Run filter
99
- filter.run('@import moo.css')
100
- end
101
- end
102
-
103
- def test_recompile_includes
104
- if_have 'sass' do
105
- # Create site
106
- Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
107
- FileUtils.cd('bar') do
108
- # Create two Sass files
109
- Dir['content/*'].each { |i| FileUtils.rm(i) }
110
- File.open('content/a.sass', 'w') do |io|
111
- io.write('@import b.sass')
112
- end
113
- File.open('content/b.sass', 'w') do |io|
114
- io.write("p\n color: red")
115
- end
116
-
117
- # Update rules
118
- File.open('Rules', 'w') do |io|
119
- io.write "compile '*' do\n"
120
- io.write " filter :sass\n"
121
- io.write "end\n"
122
- io.write "\n"
123
- io.write "route '/a/' do\n"
124
- io.write " item.identifier.chop + '.css'\n"
125
- io.write "end\n"
126
- io.write "\n"
127
- io.write "route '/b/' do\n"
128
- io.write " nil\n"
129
- io.write "end\n"
130
- end
131
-
132
- # Compile
133
- site = Nanoc3::Site.new('.')
134
- site.load_data
135
- site.compiler.run
136
-
137
- # Check
138
- assert Dir['output/*'].size == 1
139
- assert File.file?('output/a.css')
140
- refute File.file?('output/b.css')
141
- assert_match /^p\s*{\s*color:\s*red;?\s*}/, File.read('output/a.css')
142
-
143
- # Update included file
144
- File.open('content/b.sass', 'w') do |io|
145
- io.write("p\n color: blue")
146
- end
147
-
148
- # Recompile
149
- site = Nanoc3::Site.new('.')
150
- site.load_data
151
- site.compiler.run
152
-
153
- # Recheck
154
- assert Dir['output/*'].size == 1
155
- assert File.file?('output/a.css')
156
- refute File.file?('output/b.css')
157
- assert_match /^p\s*{\s*color:\s*blue;?\s*}/, File.read('output/a.css')
158
- end
159
- end
160
- end
161
-
162
- def test_recompile_includes_with_underscore_without_extension
163
- if_have 'sass' do
164
- # Create site
165
- Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
166
- FileUtils.cd('bar') do
167
- # Create two Sass files
168
- Dir['content/*'].each { |i| FileUtils.rm(i) }
169
- File.open('content/a.sass', 'w') do |io|
170
- io.write('@import b')
171
- end
172
- File.open('content/_b.sass', 'w') do |io|
173
- io.write("p\n color: red")
174
- end
175
-
176
- # Update rules
177
- File.open('Rules', 'w') do |io|
178
- io.write "compile '*' do\n"
179
- io.write " filter :sass\n"
180
- io.write "end\n"
181
- io.write "\n"
182
- io.write "route '/a/' do\n"
183
- io.write " item.identifier.chop + '.css'\n"
184
- io.write "end\n"
185
- io.write "\n"
186
- io.write "route '/_b/' do\n"
187
- io.write " nil\n"
188
- io.write "end\n"
189
- end
190
-
191
- # Compile
192
- site = Nanoc3::Site.new('.')
193
- site.load_data
194
- site.compiler.run
195
-
196
- # Check
197
- assert Dir['output/*'].size == 1
198
- assert File.file?('output/a.css')
199
- refute File.file?('output/b.css')
200
- assert_match /^p\s*{\s*color:\s*red;?\s*}/, File.read('output/a.css')
201
-
202
- # Update included file
203
- File.open('content/_b.sass', 'w') do |io|
204
- io.write("p\n color: blue")
205
- end
206
-
207
- # Recompile
208
- site = Nanoc3::Site.new('.')
209
- site.load_data
210
- site.compiler.run
211
-
212
- # Recheck
213
- assert Dir['output/*'].size == 1
214
- assert File.file?('output/a.css')
215
- refute File.file?('output/b.css')
216
- assert_match /^p\s*{\s*color:\s*blue;?\s*}/, File.read('output/a.css')
217
- end
218
- end
219
- end
220
-
221
- private
222
-
223
- def create_filter(params={})
224
- FileUtils.mkdir_p('content')
225
- File.open('content/xyzzy.sass', 'w') { |io| io.write('p\n color: green')}
226
-
227
- items = [ Nanoc3::Item.new(
228
- 'blah',
229
- { :content_filename => 'content/xyzzy.sass' },
230
- '/blah/') ]
231
- params = { :item => items[0], :items => items }.merge(params)
232
- ::Nanoc3::Filters::Sass.new(params)
233
- end
234
-
235
- end
data/test/gem_loader.rb DELETED
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'rubygems'
5
-
6
- gemspec = File.expand_path("nanoc3.gemspec", Dir.pwd)
7
- Gem::Specification.load(gemspec).dependencies.each do |dep|
8
- gem dep.name, *dep.requirement.as_list
9
- end
10
- rescue LoadError => e
11
- end
data/test/helper.rb DELETED
@@ -1,99 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # Set up gem loading (necessary for cri dependency)
4
- require File.dirname(__FILE__) + '/gem_loader.rb'
5
-
6
- # Load unit testing stuff
7
- begin
8
- require 'minitest/unit'
9
- require 'minitest/spec'
10
- require 'minitest/mock'
11
- require 'mocha'
12
- rescue => e
13
- $stderr.puts "To run the nanoc unit tests, you need minitest and mocha."
14
- raise e
15
- end
16
-
17
- # Load nanoc
18
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
19
- require 'nanoc3'
20
- require 'nanoc3/cli'
21
- require 'nanoc3/tasks'
22
-
23
- # Load miscellaneous requirements
24
- require 'stringio'
25
-
26
- module Nanoc3::TestHelpers
27
-
28
- def if_have(*libs)
29
- libs.each do |lib|
30
- begin
31
- require lib
32
- rescue LoadError
33
- skip "requiring #{lib} failed"
34
- return
35
- end
36
- end
37
-
38
- yield
39
- end
40
-
41
- def if_implemented
42
- begin
43
- yield
44
- rescue NotImplementedError, NameError
45
- skip $!
46
- return
47
- end
48
- end
49
-
50
- def setup
51
- # Clean up
52
- GC.start
53
-
54
- # Go quiet
55
- unless ENV['QUIET'] == 'false'
56
- $stdout = StringIO.new
57
- $stderr = StringIO.new
58
- end
59
-
60
- # Enter tmp
61
- FileUtils.mkdir_p('tmp')
62
- FileUtils.cd('tmp')
63
- end
64
-
65
- def teardown
66
- # Exit tmp
67
- FileUtils.cd('..')
68
- FileUtils.rm_rf('tmp')
69
-
70
- # Go unquiet
71
- unless ENV['QUIET'] == 'false'
72
- $stdout = STDOUT
73
- $stderr = STDERR
74
- end
75
- end
76
-
77
- # Adapted from http://github.com/lsegal/yard-examples/tree/master/doctest
78
- def assert_examples_correct(object)
79
- P(object).tags(:example).each do |example|
80
- begin
81
- # Get input and output
82
- parts = example.text.split(/# ?=>/).map { |s| s.strip }
83
- code = parts[0].strip
84
- expected_out_raw = parts[1].strip
85
-
86
- # Evaluate
87
- expected_out = eval(parts[1])
88
- actual_out = instance_eval("#{code}")
89
- rescue Exception => e
90
- e.message << " (code: #{code}; expected output: #{expected_out_raw})"
91
- raise e
92
- end
93
-
94
- assert_equal expected_out, actual_out,
95
- "Incorrect example: #{code}"
96
- end
97
- end
98
-
99
- end