nanoc 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/.gemtest +0 -0
  2. data/ChangeLog +3 -0
  3. data/Gemfile +32 -0
  4. data/LICENSE +19 -0
  5. data/NEWS.md +470 -0
  6. data/README.md +114 -0
  7. data/Rakefile +14 -0
  8. data/bin/nanoc +7 -27
  9. data/bin/nanoc3 +3 -0
  10. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  11. data/lib/nanoc.rb +41 -0
  12. data/lib/nanoc/base.rb +49 -0
  13. data/lib/nanoc/base/compilation/checksum_store.rb +57 -0
  14. data/lib/nanoc/base/compilation/compiled_content_cache.rb +62 -0
  15. data/lib/nanoc/base/compilation/compiler.rb +458 -0
  16. data/lib/nanoc/base/compilation/compiler_dsl.rb +214 -0
  17. data/lib/nanoc/base/compilation/dependency_tracker.rb +200 -0
  18. data/lib/nanoc/base/compilation/filter.rb +165 -0
  19. data/lib/nanoc/base/compilation/item_rep_proxy.rb +103 -0
  20. data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +102 -0
  21. data/lib/nanoc/base/compilation/outdatedness_checker.rb +223 -0
  22. data/lib/nanoc/base/compilation/outdatedness_reasons.rb +46 -0
  23. data/lib/nanoc/base/compilation/rule.rb +73 -0
  24. data/lib/nanoc/base/compilation/rule_context.rb +84 -0
  25. data/lib/nanoc/base/compilation/rule_memory_calculator.rb +40 -0
  26. data/lib/nanoc/base/compilation/rule_memory_store.rb +53 -0
  27. data/lib/nanoc/base/compilation/rules_collection.rb +243 -0
  28. data/lib/nanoc/base/context.rb +47 -0
  29. data/lib/nanoc/base/core_ext.rb +6 -0
  30. data/lib/nanoc/base/core_ext/array.rb +62 -0
  31. data/lib/nanoc/base/core_ext/hash.rb +63 -0
  32. data/lib/nanoc/base/core_ext/pathname.rb +26 -0
  33. data/lib/nanoc/base/core_ext/string.rb +46 -0
  34. data/lib/nanoc/base/directed_graph.rb +275 -0
  35. data/lib/nanoc/base/errors.rb +211 -0
  36. data/lib/nanoc/base/memoization.rb +67 -0
  37. data/lib/nanoc/base/notification_center.rb +84 -0
  38. data/lib/nanoc/base/ordered_hash.rb +200 -0
  39. data/lib/nanoc/base/plugin_registry.rb +181 -0
  40. data/lib/nanoc/base/result_data/item_rep.rb +492 -0
  41. data/lib/nanoc/base/source_data/code_snippet.rb +58 -0
  42. data/lib/nanoc/base/source_data/configuration.rb +24 -0
  43. data/lib/nanoc/base/source_data/data_source.rb +234 -0
  44. data/lib/nanoc/base/source_data/item.rb +301 -0
  45. data/lib/nanoc/base/source_data/layout.rb +130 -0
  46. data/lib/nanoc/base/source_data/site.rb +361 -0
  47. data/lib/nanoc/base/store.rb +135 -0
  48. data/lib/nanoc/cli.rb +137 -0
  49. data/lib/nanoc/cli/command_runner.rb +104 -0
  50. data/lib/nanoc/cli/commands/autocompile.rb +58 -0
  51. data/lib/nanoc/cli/commands/compile.rb +297 -0
  52. data/lib/nanoc/cli/commands/create_item.rb +60 -0
  53. data/lib/nanoc/cli/commands/create_layout.rb +73 -0
  54. data/lib/nanoc/cli/commands/create_site.rb +411 -0
  55. data/lib/nanoc/cli/commands/debug.rb +117 -0
  56. data/lib/nanoc/cli/commands/deploy.rb +79 -0
  57. data/lib/nanoc/cli/commands/info.rb +98 -0
  58. data/lib/nanoc/cli/commands/nanoc.rb +38 -0
  59. data/lib/nanoc/cli/commands/prune.rb +50 -0
  60. data/lib/nanoc/cli/commands/update.rb +70 -0
  61. data/lib/nanoc/cli/commands/view.rb +82 -0
  62. data/lib/nanoc/cli/commands/watch.rb +124 -0
  63. data/lib/nanoc/cli/error_handler.rb +199 -0
  64. data/lib/nanoc/cli/logger.rb +92 -0
  65. data/lib/nanoc/data_sources.rb +29 -0
  66. data/lib/nanoc/data_sources/deprecated/delicious.rb +42 -0
  67. data/lib/nanoc/data_sources/deprecated/last_fm.rb +87 -0
  68. data/lib/nanoc/data_sources/deprecated/twitter.rb +38 -0
  69. data/lib/nanoc/data_sources/filesystem.rb +299 -0
  70. data/lib/nanoc/data_sources/filesystem_unified.rb +121 -0
  71. data/lib/nanoc/data_sources/filesystem_verbose.rb +91 -0
  72. data/lib/nanoc/extra.rb +24 -0
  73. data/lib/nanoc/extra/auto_compiler.rb +103 -0
  74. data/lib/nanoc/extra/chick.rb +125 -0
  75. data/lib/nanoc/extra/core_ext.rb +6 -0
  76. data/lib/nanoc/extra/core_ext/enumerable.rb +33 -0
  77. data/lib/nanoc/extra/core_ext/pathname.rb +30 -0
  78. data/lib/nanoc/extra/core_ext/time.rb +19 -0
  79. data/lib/nanoc/extra/deployer.rb +47 -0
  80. data/lib/nanoc/extra/deployers.rb +15 -0
  81. data/lib/nanoc/extra/deployers/fog.rb +98 -0
  82. data/lib/nanoc/extra/deployers/rsync.rb +70 -0
  83. data/lib/nanoc/extra/file_proxy.rb +40 -0
  84. data/lib/nanoc/extra/pruner.rb +86 -0
  85. data/lib/nanoc/extra/validators.rb +12 -0
  86. data/lib/nanoc/extra/validators/links.rb +268 -0
  87. data/lib/nanoc/extra/validators/w3c.rb +95 -0
  88. data/lib/nanoc/extra/vcs.rb +66 -0
  89. data/lib/nanoc/extra/vcses.rb +17 -0
  90. data/lib/nanoc/extra/vcses/bazaar.rb +25 -0
  91. data/lib/nanoc/extra/vcses/dummy.rb +24 -0
  92. data/lib/nanoc/extra/vcses/git.rb +25 -0
  93. data/lib/nanoc/extra/vcses/mercurial.rb +25 -0
  94. data/lib/nanoc/extra/vcses/subversion.rb +25 -0
  95. data/lib/nanoc/filters.rb +59 -0
  96. data/lib/nanoc/filters/asciidoc.rb +38 -0
  97. data/lib/nanoc/filters/bluecloth.rb +19 -0
  98. data/lib/nanoc/filters/coderay.rb +21 -0
  99. data/lib/nanoc/filters/coffeescript.rb +20 -0
  100. data/lib/nanoc/filters/colorize_syntax.rb +298 -0
  101. data/lib/nanoc/filters/erb.rb +38 -0
  102. data/lib/nanoc/filters/erubis.rb +34 -0
  103. data/lib/nanoc/filters/haml.rb +27 -0
  104. data/lib/nanoc/filters/kramdown.rb +20 -0
  105. data/lib/nanoc/filters/less.rb +53 -0
  106. data/lib/nanoc/filters/markaby.rb +20 -0
  107. data/lib/nanoc/filters/maruku.rb +20 -0
  108. data/lib/nanoc/filters/mustache.rb +24 -0
  109. data/lib/nanoc/filters/rainpress.rb +19 -0
  110. data/lib/nanoc/filters/rdiscount.rb +22 -0
  111. data/lib/nanoc/filters/rdoc.rb +33 -0
  112. data/lib/nanoc/filters/redcarpet.rb +62 -0
  113. data/lib/nanoc/filters/redcloth.rb +47 -0
  114. data/lib/nanoc/filters/relativize_paths.rb +94 -0
  115. data/lib/nanoc/filters/rubypants.rb +20 -0
  116. data/lib/nanoc/filters/sass.rb +74 -0
  117. data/lib/nanoc/filters/slim.rb +25 -0
  118. data/lib/nanoc/filters/typogruby.rb +23 -0
  119. data/lib/nanoc/filters/uglify_js.rb +42 -0
  120. data/lib/nanoc/filters/xsl.rb +46 -0
  121. data/lib/nanoc/filters/yui_compressor.rb +23 -0
  122. data/lib/nanoc/helpers.rb +16 -0
  123. data/lib/nanoc/helpers/blogging.rb +319 -0
  124. data/lib/nanoc/helpers/breadcrumbs.rb +40 -0
  125. data/lib/nanoc/helpers/capturing.rb +138 -0
  126. data/lib/nanoc/helpers/filtering.rb +50 -0
  127. data/lib/nanoc/helpers/html_escape.rb +55 -0
  128. data/lib/nanoc/helpers/link_to.rb +151 -0
  129. data/lib/nanoc/helpers/rendering.rb +140 -0
  130. data/lib/nanoc/helpers/tagging.rb +71 -0
  131. data/lib/nanoc/helpers/text.rb +44 -0
  132. data/lib/nanoc/helpers/xml_sitemap.rb +76 -0
  133. data/lib/nanoc/tasks.rb +10 -0
  134. data/lib/nanoc/tasks/clean.rake +16 -0
  135. data/lib/nanoc/tasks/clean.rb +29 -0
  136. data/lib/nanoc/tasks/deploy/rsync.rake +16 -0
  137. data/lib/nanoc/tasks/validate.rake +92 -0
  138. data/nanoc.gemspec +49 -0
  139. data/tasks/doc.rake +16 -0
  140. data/tasks/test.rake +46 -0
  141. data/test/base/core_ext/array_spec.rb +73 -0
  142. data/test/base/core_ext/hash_spec.rb +98 -0
  143. data/test/base/core_ext/pathname_spec.rb +27 -0
  144. data/test/base/core_ext/string_spec.rb +37 -0
  145. data/test/base/test_checksum_store.rb +35 -0
  146. data/test/base/test_code_snippet.rb +31 -0
  147. data/test/base/test_compiler.rb +403 -0
  148. data/test/base/test_compiler_dsl.rb +161 -0
  149. data/test/base/test_context.rb +31 -0
  150. data/test/base/test_data_source.rb +46 -0
  151. data/test/base/test_dependency_tracker.rb +262 -0
  152. data/test/base/test_directed_graph.rb +288 -0
  153. data/test/base/test_filter.rb +83 -0
  154. data/test/base/test_item.rb +179 -0
  155. data/test/base/test_item_rep.rb +579 -0
  156. data/test/base/test_layout.rb +59 -0
  157. data/test/base/test_memoization.rb +90 -0
  158. data/test/base/test_notification_center.rb +34 -0
  159. data/test/base/test_outdatedness_checker.rb +394 -0
  160. data/test/base/test_plugin.rb +30 -0
  161. data/test/base/test_rule.rb +19 -0
  162. data/test/base/test_rule_context.rb +65 -0
  163. data/test/base/test_site.rb +190 -0
  164. data/test/cli/commands/test_compile.rb +33 -0
  165. data/test/cli/commands/test_create_item.rb +14 -0
  166. data/test/cli/commands/test_create_layout.rb +28 -0
  167. data/test/cli/commands/test_create_site.rb +24 -0
  168. data/test/cli/commands/test_deploy.rb +74 -0
  169. data/test/cli/commands/test_help.rb +12 -0
  170. data/test/cli/commands/test_info.rb +11 -0
  171. data/test/cli/commands/test_prune.rb +98 -0
  172. data/test/cli/commands/test_update.rb +10 -0
  173. data/test/cli/test_cli.rb +102 -0
  174. data/test/cli/test_error_handler.rb +29 -0
  175. data/test/cli/test_logger.rb +10 -0
  176. data/test/data_sources/test_filesystem.rb +433 -0
  177. data/test/data_sources/test_filesystem_unified.rb +536 -0
  178. data/test/data_sources/test_filesystem_verbose.rb +357 -0
  179. data/test/extra/core_ext/test_enumerable.rb +30 -0
  180. data/test/extra/core_ext/test_pathname.rb +17 -0
  181. data/test/extra/core_ext/test_time.rb +15 -0
  182. data/test/extra/deployers/test_fog.rb +67 -0
  183. data/test/extra/deployers/test_rsync.rb +100 -0
  184. data/test/extra/test_auto_compiler.rb +417 -0
  185. data/test/extra/test_file_proxy.rb +19 -0
  186. data/test/extra/test_vcs.rb +22 -0
  187. data/test/extra/validators/test_links.rb +62 -0
  188. data/test/extra/validators/test_w3c.rb +47 -0
  189. data/test/filters/test_asciidoc.rb +22 -0
  190. data/test/filters/test_bluecloth.rb +18 -0
  191. data/test/filters/test_coderay.rb +44 -0
  192. data/test/filters/test_coffeescript.rb +18 -0
  193. data/test/filters/test_colorize_syntax.rb +379 -0
  194. data/test/filters/test_erb.rb +105 -0
  195. data/test/filters/test_erubis.rb +78 -0
  196. data/test/filters/test_haml.rb +96 -0
  197. data/test/filters/test_kramdown.rb +18 -0
  198. data/test/filters/test_less.rb +113 -0
  199. data/test/filters/test_markaby.rb +24 -0
  200. data/test/filters/test_maruku.rb +18 -0
  201. data/test/filters/test_mustache.rb +25 -0
  202. data/test/filters/test_rainpress.rb +29 -0
  203. data/test/filters/test_rdiscount.rb +31 -0
  204. data/test/filters/test_rdoc.rb +18 -0
  205. data/test/filters/test_redcarpet.rb +73 -0
  206. data/test/filters/test_redcloth.rb +33 -0
  207. data/test/filters/test_relativize_paths.rb +533 -0
  208. data/test/filters/test_rubypants.rb +18 -0
  209. data/test/filters/test_sass.rb +229 -0
  210. data/test/filters/test_slim.rb +35 -0
  211. data/test/filters/test_typogruby.rb +21 -0
  212. data/test/filters/test_uglify_js.rb +30 -0
  213. data/test/filters/test_xsl.rb +105 -0
  214. data/test/filters/test_yui_compressor.rb +44 -0
  215. data/test/gem_loader.rb +11 -0
  216. data/test/helper.rb +207 -0
  217. data/test/helpers/test_blogging.rb +754 -0
  218. data/test/helpers/test_breadcrumbs.rb +81 -0
  219. data/test/helpers/test_capturing.rb +41 -0
  220. data/test/helpers/test_filtering.rb +106 -0
  221. data/test/helpers/test_html_escape.rb +32 -0
  222. data/test/helpers/test_link_to.rb +249 -0
  223. data/test/helpers/test_rendering.rb +89 -0
  224. data/test/helpers/test_tagging.rb +87 -0
  225. data/test/helpers/test_text.rb +24 -0
  226. data/test/helpers/test_xml_sitemap.rb +103 -0
  227. data/test/tasks/test_clean.rb +67 -0
  228. metadata +327 -15
  229. data/bin/nanoc-select +0 -86
  230. data/lib/nanoc-select.rb +0 -11
@@ -0,0 +1,161 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::CompilerDSLTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_compile
8
+ # TODO implement
9
+ end
10
+
11
+ def test_route
12
+ # TODO implement
13
+ end
14
+
15
+ def test_layout
16
+ # TODO implement
17
+ end
18
+
19
+ def test_passthrough
20
+ # Create site
21
+ Nanoc::CLI.run %w( create_site bar)
22
+ FileUtils.cd('bar') do
23
+ # Create rep
24
+ item = Nanoc::Item.new('foo', { :extension => 'bar' }, '/foo/')
25
+ rep = Nanoc::ItemRep.new(item, :default)
26
+
27
+ # Create other necessary stuff
28
+ site = Nanoc::Site.new('.')
29
+ site.items << item
30
+ compiler = site.compiler
31
+ dsl = site.compiler.rules_collection.dsl
32
+
33
+ # Create rule
34
+ dsl.passthrough '/foo/'
35
+
36
+ # Route and compile
37
+ rule = compiler.rules_collection.routing_rule_for(rep)
38
+ path = rule.apply_to(rep, :compiler => compiler)
39
+ compiler.send :compile_rep, rep
40
+
41
+ # Check result
42
+ assert_equal 'foo', rep.compiled_content
43
+ assert_equal '/foo.bar', path
44
+ end
45
+ end
46
+
47
+ def test_identifier_to_regex_without_wildcards
48
+ # Create compiler DSL
49
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
50
+
51
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo') }
52
+ expected = %r{^/foo/$}
53
+
54
+ assert_equal(expected.to_s, actual.to_s)
55
+ assert_equal(expected.source, actual.source)
56
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
57
+ assert_equal(expected.casefold?, actual.casefold?)
58
+ assert_equal(expected.options, actual.options)
59
+ end
60
+
61
+ def test_identifier_to_regex_with_one_wildcard
62
+ # Create compiler DSL
63
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
64
+
65
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar') }
66
+ expected = %r{^/foo/(.*?)/bar/$}
67
+
68
+ assert_equal(expected.to_s, actual.to_s)
69
+ assert_equal(expected.source, actual.source)
70
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
71
+ assert_equal(expected.casefold?, actual.casefold?)
72
+ assert_equal(expected.options, actual.options)
73
+ end
74
+
75
+ def test_identifier_to_regex_with_two_wildcards
76
+ # Create compiler DSL
77
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
78
+
79
+ actual = compiler_dsl.instance_eval { identifier_to_regex('foo/*/bar/*/qux') }
80
+ expected = %r{^/foo/(.*?)/bar/(.*?)/qux/$}
81
+
82
+ assert_equal(expected.to_s, actual.to_s)
83
+ assert_equal(expected.source, actual.source)
84
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
85
+ assert_equal(expected.casefold?, actual.casefold?)
86
+ assert_equal(expected.options, actual.options)
87
+ end
88
+
89
+ def test_identifier_to_regex_with_just_one_wildcard
90
+ # Create compiler DSL
91
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
92
+
93
+ actual = compiler_dsl.instance_eval { identifier_to_regex('*') }
94
+ expected = %r{^/(.*?)$}
95
+
96
+ assert_equal(expected.to_s, actual.to_s)
97
+ assert_equal(expected.source, actual.source)
98
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
99
+ assert_equal(expected.casefold?, actual.casefold?)
100
+ assert_equal(expected.options, actual.options)
101
+ end
102
+
103
+ def test_identifier_to_regex_with_root
104
+ # Create compiler DSL
105
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
106
+
107
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/') }
108
+ expected = %r{^/$}
109
+
110
+ assert_equal(expected.to_s, actual.to_s)
111
+ assert_equal(expected.source, actual.source)
112
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
113
+ assert_equal(expected.casefold?, actual.casefold?)
114
+ assert_equal(expected.options, actual.options)
115
+ end
116
+
117
+ def test_identifier_to_regex_with_only_children
118
+ # Create compiler DSL
119
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
120
+
121
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/*/') }
122
+ expected = %r{^/foo/(.*?)/$}
123
+
124
+ assert_equal(expected.to_s, actual.to_s)
125
+ assert_equal(expected.source, actual.source)
126
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
127
+ assert_equal(expected.casefold?, actual.casefold?)
128
+ assert_equal(expected.options, actual.options)
129
+ end
130
+
131
+ def test_identifier_to_regex_with_plus_wildcard
132
+ # Create compiler DSL
133
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
134
+
135
+ actual = compiler_dsl.instance_eval { identifier_to_regex('/foo/+') }
136
+ expected = %r{^/foo/(.+?)/$}
137
+
138
+ assert_equal(expected.to_s, actual.to_s)
139
+ assert_equal(expected.source, actual.source)
140
+ assert_equal(expected.kcode, actual.kcode) if expected.respond_to?(:kcode)
141
+ assert_equal(expected.casefold?, actual.casefold?)
142
+ assert_equal(expected.options, actual.options)
143
+ assert('/foo/bar/' =~ actual)
144
+ refute('/foo/' =~ actual)
145
+ end
146
+
147
+ def test_dsl_has_no_access_to_compiler
148
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, {})
149
+ assert_raises(NameError) do
150
+ compiler_dsl.instance_eval { compiler }
151
+ end
152
+ end
153
+
154
+ def test_config
155
+ $venetian = 'unsnares'
156
+ compiler_dsl = Nanoc::CompilerDSL.new(nil, { :venetian => 'snares' })
157
+ compiler_dsl.instance_eval { $venetian = @config[:venetian] }
158
+ assert_equal 'snares', $venetian
159
+ end
160
+
161
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::ContextTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_context_with_instance_variable
8
+ # Create context
9
+ context = Nanoc::Context.new({ :foo => 'bar', :baz => 'quux' })
10
+
11
+ # Ensure correct evaluation
12
+ assert_equal('bar', eval("@foo", context.get_binding))
13
+ end
14
+
15
+ def test_context_with_instance_method
16
+ # Create context
17
+ context = Nanoc::Context.new({ :foo => 'bar', :baz => 'quux' })
18
+
19
+ # Ensure correct evaluation
20
+ assert_equal('bar', eval("foo", context.get_binding))
21
+ end
22
+
23
+ def test_example
24
+ # Parse
25
+ YARD.parse('../lib/nanoc/base/context.rb')
26
+
27
+ # Run
28
+ assert_examples_correct 'Nanoc::Context#initialize'
29
+ end
30
+
31
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::DataSourceTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_loading
8
+ # Create data source
9
+ data_source = Nanoc::DataSource.new(nil, nil, nil, nil)
10
+ data_source.expects(:up).times(1)
11
+ data_source.expects(:down).times(1)
12
+
13
+ # Test nested loading
14
+ assert_equal(0, data_source.instance_eval { @references })
15
+ data_source.loading do
16
+ assert_equal(1, data_source.instance_eval { @references })
17
+ data_source.loading do
18
+ assert_equal(2, data_source.instance_eval { @references })
19
+ end
20
+ assert_equal(1, data_source.instance_eval { @references })
21
+ end
22
+ assert_equal(0, data_source.instance_eval { @references })
23
+ end
24
+
25
+ def test_not_implemented
26
+ # Create data source
27
+ data_source = Nanoc::DataSource.new(nil, nil, nil, nil)
28
+
29
+ # Test optional methods
30
+ data_source.up
31
+ data_source.down
32
+ data_source.update
33
+
34
+ # Test required methods - general
35
+ assert_raises(NotImplementedError) { data_source.setup }
36
+
37
+ # Test methods - loading data
38
+ assert_equal [], data_source.items
39
+ assert_equal [], data_source.layouts
40
+
41
+ # Test required method - creating data
42
+ assert_raises(NotImplementedError) { data_source.create_item(nil, nil, nil) }
43
+ assert_raises(NotImplementedError) { data_source.create_layout(nil, nil, nil) }
44
+ end
45
+
46
+ end
@@ -0,0 +1,262 @@
1
+ # encoding: utf-8
2
+
3
+ class Nanoc::DependencyTrackerTest < MiniTest::Unit::TestCase
4
+
5
+ include Nanoc::TestHelpers
6
+
7
+ def test_initialize
8
+ # Mock items
9
+ items = [ mock, mock ]
10
+
11
+ # Create
12
+ tracker = Nanoc::DependencyTracker.new(items)
13
+
14
+ # Verify no dependencies yet
15
+ assert_empty tracker.objects_causing_outdatedness_of(items[0])
16
+ assert_empty tracker.objects_causing_outdatedness_of(items[1])
17
+ end
18
+
19
+ def test_record_dependency
20
+ # Mock items
21
+ items = [ mock, mock ]
22
+
23
+ # Create
24
+ tracker = Nanoc::DependencyTracker.new(items)
25
+
26
+ # Record some dependencies
27
+ tracker.record_dependency(items[0], items[1])
28
+
29
+ # Verify dependencies
30
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
31
+ end
32
+
33
+ def test_record_dependency_no_self
34
+ # Mock items
35
+ items = [ mock, mock ]
36
+
37
+ # Create
38
+ tracker = Nanoc::DependencyTracker.new(items)
39
+
40
+ # Record some dependencies
41
+ tracker.record_dependency(items[0], items[0])
42
+ tracker.record_dependency(items[0], items[1])
43
+
44
+ # Verify dependencies
45
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
46
+ end
47
+
48
+ def test_record_dependency_no_doubles
49
+ # Mock items
50
+ items = [ mock, mock ]
51
+
52
+ # Create
53
+ tracker = Nanoc::DependencyTracker.new(items)
54
+
55
+ # Record some dependencies
56
+ tracker.record_dependency(items[0], items[1])
57
+ tracker.record_dependency(items[0], items[1])
58
+ tracker.record_dependency(items[0], items[1])
59
+
60
+ # Verify dependencies
61
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
62
+ end
63
+
64
+ def test_objects_causing_outdatedness_of
65
+ # Mock items
66
+ items = [ mock, mock, mock ]
67
+
68
+ # Create
69
+ tracker = Nanoc::DependencyTracker.new(items)
70
+
71
+ # Record some dependencies
72
+ tracker.record_dependency(items[0], items[1])
73
+ tracker.record_dependency(items[1], items[2])
74
+
75
+ # Verify dependencies
76
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
77
+ end
78
+
79
+ def test_objects_outdated_due_to
80
+ # Mock items
81
+ items = [ mock, mock, mock ]
82
+
83
+ # Create
84
+ tracker = Nanoc::DependencyTracker.new(items)
85
+
86
+ # Record some dependencies
87
+ tracker.record_dependency(items[0], items[1])
88
+ tracker.record_dependency(items[1], items[2])
89
+
90
+ # Verify dependencies
91
+ assert_contains_exactly [ items[0] ], tracker.objects_outdated_due_to(items[1])
92
+ end
93
+
94
+ def test_start_and_stop
95
+ # Mock items
96
+ items = [ mock, mock ]
97
+
98
+ # Create
99
+ tracker = Nanoc::DependencyTracker.new(items)
100
+
101
+ # Start, do something and stop
102
+ tracker.start
103
+ Nanoc::NotificationCenter.post(:visit_started, items[0])
104
+ Nanoc::NotificationCenter.post(:visit_started, items[1])
105
+ Nanoc::NotificationCenter.post(:visit_ended, items[1])
106
+ Nanoc::NotificationCenter.post(:visit_ended, items[0])
107
+ tracker.stop
108
+
109
+ # Verify dependencies
110
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
111
+ assert_empty tracker.objects_causing_outdatedness_of(items[1])
112
+ end
113
+
114
+ def test_store_graph_and_load_graph_simple
115
+ # Mock items
116
+ items = [ mock('0'), mock('1'), mock('2'), mock('3') ]
117
+ items.each { |i| i.stubs(:type).returns(:item) }
118
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
119
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
120
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
121
+ items[3].stubs(:reference).returns([ :item, '/ddd/' ])
122
+
123
+ # Create
124
+ tracker = Nanoc::DependencyTracker.new(items)
125
+
126
+ # Record some dependencies
127
+ tracker.record_dependency(items[0], items[1])
128
+ tracker.record_dependency(items[1], items[2])
129
+ tracker.record_dependency(items[1], items[3])
130
+
131
+ # Store
132
+ tracker.store_graph
133
+ assert File.file?(tracker.filename)
134
+
135
+ # Re-create
136
+ tracker = Nanoc::DependencyTracker.new(items)
137
+
138
+ # Load
139
+ tracker.load_graph
140
+
141
+ # Check loaded graph
142
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
143
+ assert_contains_exactly [ items[2], items[3] ], tracker.objects_causing_outdatedness_of(items[1])
144
+ assert_empty tracker.objects_causing_outdatedness_of(items[2])
145
+ assert_empty tracker.objects_causing_outdatedness_of(items[3])
146
+ end
147
+
148
+ def test_store_graph_and_load_graph_with_removed_items
149
+ # Mock items
150
+ items = [ mock('0'), mock('1'), mock('2'), mock('3') ]
151
+ items.each { |i| i.stubs(:type).returns(:item) }
152
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
153
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
154
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
155
+ items[3].stubs(:reference).returns([ :item, '/ddd/' ])
156
+
157
+ # Create new and old lists
158
+ old_items = [ items[0], items[1], items[2], items[3] ]
159
+ new_items = [ items[0], items[1], items[2] ]
160
+
161
+ # Create
162
+ tracker = Nanoc::DependencyTracker.new(old_items)
163
+
164
+ # Record some dependencies
165
+ tracker.record_dependency(old_items[0], old_items[1])
166
+ tracker.record_dependency(old_items[1], old_items[2])
167
+ tracker.record_dependency(old_items[1], old_items[3])
168
+
169
+ # Store
170
+ tracker.store_graph
171
+ assert File.file?(tracker.filename)
172
+
173
+ # Re-create
174
+ tracker = Nanoc::DependencyTracker.new(new_items)
175
+
176
+ # Load
177
+ tracker.load_graph
178
+
179
+ # Check loaded graph
180
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
181
+ assert_contains_exactly [ items[2], nil ], tracker.objects_causing_outdatedness_of(items[1])
182
+ assert_empty tracker.objects_causing_outdatedness_of(items[2])
183
+ end
184
+
185
+ def test_store_graph_with_nils_in_dst
186
+ # Mock items
187
+ items = [ mock('0'), mock('1'), mock('2') ]
188
+ items.each { |i| i.stubs(:type).returns(:item) }
189
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
190
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
191
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
192
+
193
+ # Create
194
+ tracker = Nanoc::DependencyTracker.new(items)
195
+
196
+ # Record some dependencies
197
+ tracker.record_dependency(items[0], items[1])
198
+ tracker.record_dependency(items[1], nil)
199
+
200
+ # Store
201
+ tracker.store_graph
202
+ assert File.file?(tracker.filename)
203
+
204
+ # Re-create
205
+ tracker = Nanoc::DependencyTracker.new(items)
206
+
207
+ # Load
208
+ tracker.load_graph
209
+
210
+ # Check loaded graph
211
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
212
+ assert_contains_exactly [ nil ], tracker.objects_causing_outdatedness_of(items[1])
213
+ end
214
+
215
+ def test_store_graph_with_nils_in_src
216
+ # Mock items
217
+ items = [ mock('0'), mock('1'), mock('2') ]
218
+ items.each { |i| i.stubs(:type).returns(:item) }
219
+ items[0].stubs(:reference).returns([ :item, '/aaa/' ])
220
+ items[1].stubs(:reference).returns([ :item, '/bbb/' ])
221
+ items[2].stubs(:reference).returns([ :item, '/ccc/' ])
222
+
223
+ # Create
224
+ tracker = Nanoc::DependencyTracker.new(items)
225
+
226
+ # Record some dependencies
227
+ tracker.record_dependency(items[0], items[1])
228
+ tracker.record_dependency(nil, items[2])
229
+
230
+ # Store
231
+ tracker.store_graph
232
+ assert File.file?(tracker.filename)
233
+
234
+ # Re-create
235
+ tracker = Nanoc::DependencyTracker.new(items)
236
+
237
+ # Load
238
+ tracker.load_graph
239
+
240
+ # Check loaded graph
241
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
242
+ assert_empty tracker.objects_causing_outdatedness_of(items[1])
243
+ end
244
+
245
+ def test_forget_dependencies_for
246
+ # Mock items
247
+ items = [ mock, mock, mock ]
248
+
249
+ # Create
250
+ tracker = Nanoc::DependencyTracker.new(items)
251
+
252
+ # Record some dependencies
253
+ tracker.record_dependency(items[0], items[1])
254
+ tracker.record_dependency(items[1], items[2])
255
+ assert_contains_exactly [ items[1] ], tracker.objects_causing_outdatedness_of(items[0])
256
+
257
+ # Forget dependencies
258
+ tracker.forget_dependencies_for(items[0])
259
+ assert_empty tracker.objects_causing_outdatedness_of(items[0])
260
+ end
261
+
262
+ end