nanoc 4.4.5 → 4.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -2
  3. data/Gemfile.lock +37 -18
  4. data/NEWS.md +6 -0
  5. data/Rakefile +8 -20
  6. data/lib/nanoc/base/entities/code_snippet.rb +0 -2
  7. data/lib/nanoc/base/entities/item_rep.rb +4 -22
  8. data/lib/nanoc/base/entities/processing_actions/snapshot.rb +9 -7
  9. data/lib/nanoc/base/entities/rule_memory.rb +15 -7
  10. data/lib/nanoc/base/entities/snapshot_def.rb +2 -8
  11. data/lib/nanoc/base/repos/store.rb +2 -28
  12. data/lib/nanoc/base/services/checksummer.rb +9 -10
  13. data/lib/nanoc/base/services/compiler.rb +14 -16
  14. data/lib/nanoc/base/services/executor.rb +2 -13
  15. data/lib/nanoc/base/views/mixins/with_reps_view_mixin.rb +1 -1
  16. data/lib/nanoc/checking/checks/external_links.rb +2 -1
  17. data/lib/nanoc/cli/commands/compile.rb +8 -14
  18. data/lib/nanoc/extra/parallel_collection.rb +57 -0
  19. data/lib/nanoc/extra.rb +1 -0
  20. data/lib/nanoc/filters/mustache.rb +1 -1
  21. data/lib/nanoc/rule_dsl/recording_executor.rb +6 -34
  22. data/lib/nanoc/rule_dsl/rule_memory_calculator.rb +42 -12
  23. data/lib/nanoc/spec.rb +1 -1
  24. data/lib/nanoc/version.rb +1 -1
  25. data/nanoc.gemspec +1 -2
  26. data/spec/contributors_spec.rb +18 -0
  27. data/spec/nanoc/base/checksummer_spec.rb +381 -0
  28. data/spec/nanoc/base/compiler_spec.rb +181 -0
  29. data/spec/nanoc/base/entities/configuration_spec.rb +49 -0
  30. data/spec/nanoc/base/entities/content_spec.rb +193 -0
  31. data/spec/nanoc/base/entities/document_spec.rb +206 -0
  32. data/spec/nanoc/base/entities/identifier_spec.rb +460 -0
  33. data/spec/nanoc/base/entities/item_rep_spec.rb +226 -0
  34. data/spec/nanoc/base/entities/item_spec.rb +3 -0
  35. data/spec/nanoc/base/entities/layout_spec.rb +3 -0
  36. data/spec/nanoc/base/entities/lazy_value_spec.rb +106 -0
  37. data/spec/nanoc/base/entities/outdatedness_status_spec.rb +113 -0
  38. data/spec/nanoc/base/entities/pattern_spec.rb +125 -0
  39. data/spec/nanoc/base/entities/processing_action_spec.rb +9 -0
  40. data/spec/nanoc/base/entities/processing_actions/filter_spec.rb +18 -0
  41. data/spec/nanoc/base/entities/processing_actions/layout_spec.rb +18 -0
  42. data/spec/nanoc/base/entities/processing_actions/snapshot_spec.rb +32 -0
  43. data/spec/nanoc/base/entities/props_spec.rb +195 -0
  44. data/spec/nanoc/base/entities/rule_memory_spec.rb +131 -0
  45. data/spec/nanoc/base/entities/site_spec.rb +73 -0
  46. data/spec/nanoc/base/feature_spec.rb +107 -0
  47. data/spec/nanoc/base/filter_spec.rb +99 -0
  48. data/spec/nanoc/base/item_rep_writer_spec.rb +131 -0
  49. data/spec/nanoc/base/plugin_registry_spec.rb +29 -0
  50. data/spec/nanoc/base/repos/checksum_store_spec.rb +133 -0
  51. data/spec/nanoc/base/repos/compiled_content_cache_spec.rb +55 -0
  52. data/spec/nanoc/base/repos/config_loader_spec.rb +243 -0
  53. data/spec/nanoc/base/repos/dependency_store_spec.rb +195 -0
  54. data/spec/nanoc/base/repos/site_loader_spec.rb +214 -0
  55. data/spec/nanoc/base/services/dependency_tracker_spec.rb +238 -0
  56. data/spec/nanoc/base/services/executor_spec.rb +495 -0
  57. data/spec/nanoc/base/services/item_rep_router_spec.rb +134 -0
  58. data/spec/nanoc/base/services/item_rep_selector_spec.rb +169 -0
  59. data/spec/nanoc/base/services/outdatedness_checker_spec.rb +370 -0
  60. data/spec/nanoc/base/services/outdatedness_rules_spec.rb +432 -0
  61. data/spec/nanoc/base/services/pruner_spec.rb +105 -0
  62. data/spec/nanoc/base/services/temp_filename_factory_spec.rb +87 -0
  63. data/spec/nanoc/base/views/config_view_spec.rb +96 -0
  64. data/spec/nanoc/base/views/document_view_spec.rb +332 -0
  65. data/spec/nanoc/base/views/identifiable_collection_view_spec.rb +190 -0
  66. data/spec/nanoc/base/views/item_collection_with_reps_view_spec.rb +18 -0
  67. data/spec/nanoc/base/views/item_collection_without_reps_view_spec.rb +18 -0
  68. data/spec/nanoc/base/views/item_rep_collection_view_spec.rb +143 -0
  69. data/spec/nanoc/base/views/item_rep_view_spec.rb +265 -0
  70. data/spec/nanoc/base/views/item_view_spec.rb +341 -0
  71. data/spec/nanoc/base/views/layout_collection_view_spec.rb +18 -0
  72. data/spec/nanoc/base/views/layout_view_spec.rb +14 -0
  73. data/spec/nanoc/base/views/mutable_config_view_spec.rb +16 -0
  74. data/spec/nanoc/base/views/mutable_document_view_spec.rb +92 -0
  75. data/spec/nanoc/base/views/mutable_identifiable_collection_view_spec.rb +36 -0
  76. data/spec/nanoc/base/views/mutable_item_collection_view_spec.rb +49 -0
  77. data/spec/nanoc/base/views/mutable_item_view_spec.rb +22 -0
  78. data/spec/nanoc/base/views/mutable_layout_collection_view_spec.rb +49 -0
  79. data/spec/nanoc/base/views/mutable_layout_view_spec.rb +13 -0
  80. data/spec/nanoc/base/views/post_compile_item_rep_collection_view_spec.rb +4 -0
  81. data/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb +137 -0
  82. data/spec/nanoc/base/views/post_compile_item_view_spec.rb +56 -0
  83. data/spec/nanoc/cli/commands/compile/file_action_printer_spec.rb +76 -0
  84. data/spec/nanoc/cli/commands/compile/timing_recorder_spec.rb +66 -0
  85. data/spec/nanoc/cli/commands/compile_spec.rb +64 -0
  86. data/spec/nanoc/cli/commands/deploy_spec.rb +327 -0
  87. data/spec/nanoc/cli/commands/shell_spec.rb +54 -0
  88. data/spec/nanoc/cli/commands/show_data_spec.rb +126 -0
  89. data/spec/nanoc/cli/commands/show_rules_spec.rb +112 -0
  90. data/spec/nanoc/cli/commands/view_spec.rb +58 -0
  91. data/spec/nanoc/data_sources/filesystem_spec.rb +56 -0
  92. data/spec/nanoc/deploying/fog_spec.rb +193 -0
  93. data/spec/nanoc/extra/parallel_collection_spec.rb +108 -0
  94. data/spec/nanoc/filters/colorize_syntax/rouge_spec.rb +195 -0
  95. data/spec/nanoc/filters/less_spec.rb +120 -0
  96. data/spec/nanoc/helpers/blogging_spec.rb +216 -0
  97. data/spec/nanoc/helpers/breadcrumbs_spec.rb +133 -0
  98. data/spec/nanoc/helpers/capturing_spec.rb +181 -0
  99. data/spec/nanoc/helpers/child_parent_spec.rb +105 -0
  100. data/spec/nanoc/helpers/filtering_spec.rb +72 -0
  101. data/spec/nanoc/helpers/html_escape_spec.rb +35 -0
  102. data/spec/nanoc/helpers/link_to_spec.rb +275 -0
  103. data/spec/nanoc/helpers/rendering_spec.rb +141 -0
  104. data/spec/nanoc/helpers/tagging_spec.rb +104 -0
  105. data/spec/nanoc/helpers/text_spec.rb +58 -0
  106. data/spec/nanoc/integration/outdatedness_integration_spec.rb +208 -0
  107. data/spec/nanoc/regressions/gh_1015_spec.rb +17 -0
  108. data/spec/nanoc/regressions/gh_1031_spec.rb +54 -0
  109. data/spec/nanoc/regressions/gh_1035_spec.rb +33 -0
  110. data/spec/nanoc/regressions/gh_1040_spec.rb +22 -0
  111. data/spec/nanoc/regressions/gh_761_spec.rb +23 -0
  112. data/spec/nanoc/regressions/gh_767_spec.rb +19 -0
  113. data/spec/nanoc/regressions/gh_769_spec.rb +30 -0
  114. data/spec/nanoc/regressions/gh_776_spec.rb +43 -0
  115. data/spec/nanoc/regressions/gh_787_spec.rb +19 -0
  116. data/spec/nanoc/regressions/gh_795_spec.rb +19 -0
  117. data/spec/nanoc/regressions/gh_804_spec.rb +26 -0
  118. data/spec/nanoc/regressions/gh_807_spec.rb +17 -0
  119. data/spec/nanoc/regressions/gh_809_spec.rb +17 -0
  120. data/spec/nanoc/regressions/gh_813_spec.rb +22 -0
  121. data/spec/nanoc/regressions/gh_815_spec.rb +18 -0
  122. data/spec/nanoc/regressions/gh_828_spec.rb +23 -0
  123. data/spec/nanoc/regressions/gh_833_spec.rb +14 -0
  124. data/spec/nanoc/regressions/gh_841_spec.rb +15 -0
  125. data/spec/nanoc/regressions/gh_867_spec.rb +15 -0
  126. data/spec/nanoc/regressions/gh_882_spec.rb +29 -0
  127. data/spec/nanoc/regressions/gh_885_spec.rb +30 -0
  128. data/spec/nanoc/regressions/gh_891_spec.rb +26 -0
  129. data/spec/nanoc/regressions/gh_913_spec.rb +24 -0
  130. data/spec/nanoc/regressions/gh_928_spec.rb +5 -0
  131. data/spec/nanoc/regressions/gh_937_spec.rb +25 -0
  132. data/spec/nanoc/regressions/gh_942_spec.rb +21 -0
  133. data/spec/nanoc/regressions/gh_947_spec.rb +21 -0
  134. data/spec/nanoc/regressions/gh_948_spec.rb +16 -0
  135. data/spec/nanoc/regressions/gh_951_spec.rb +19 -0
  136. data/spec/nanoc/regressions/gh_954_spec.rb +33 -0
  137. data/spec/nanoc/regressions/gh_970a_spec.rb +17 -0
  138. data/spec/nanoc/regressions/gh_970b_spec.rb +50 -0
  139. data/spec/nanoc/regressions/gh_974_spec.rb +17 -0
  140. data/spec/nanoc/regressions/gh_981_spec.rb +21 -0
  141. data/spec/nanoc/rule_dsl/recording_executor_spec.rb +142 -0
  142. data/spec/nanoc/rule_dsl/rule_context_spec.rb +177 -0
  143. data/spec/nanoc/rule_dsl/rule_memory_calculator_spec.rb +233 -0
  144. data/spec/nanoc/rule_dsl/rules_collection_spec.rb +299 -0
  145. data/spec/regression_filenames_spec.rb +16 -0
  146. data/spec/spec_helper.rb +173 -0
  147. data/test/base/core_ext/array_spec.rb +2 -0
  148. data/test/base/core_ext/hash_spec.rb +2 -0
  149. data/test/base/core_ext/string_spec.rb +2 -0
  150. data/test/base/test_code_snippet.rb +2 -0
  151. data/test/base/test_compiler.rb +2 -0
  152. data/test/base/test_context.rb +4 -2
  153. data/test/base/test_data_source.rb +2 -0
  154. data/test/base/test_dependency_tracker.rb +2 -0
  155. data/test/base/test_directed_graph.rb +2 -0
  156. data/test/base/test_filter.rb +7 -5
  157. data/test/base/test_item.rb +2 -0
  158. data/test/base/test_item_array.rb +3 -1
  159. data/test/base/test_layout.rb +2 -0
  160. data/test/base/test_memoization.rb +2 -0
  161. data/test/base/test_notification_center.rb +2 -0
  162. data/test/base/test_outdatedness_checker.rb +2 -0
  163. data/test/base/test_plugin.rb +2 -0
  164. data/test/base/test_site.rb +2 -0
  165. data/test/base/test_store.rb +2 -0
  166. data/test/checking/checks/test_css.rb +2 -0
  167. data/test/checking/checks/test_external_links.rb +4 -2
  168. data/test/checking/checks/test_html.rb +2 -0
  169. data/test/checking/checks/test_internal_links.rb +5 -3
  170. data/test/checking/checks/test_mixed_content.rb +2 -0
  171. data/test/checking/checks/test_stale.rb +2 -0
  172. data/test/checking/test_check.rb +2 -0
  173. data/test/checking/test_dsl.rb +2 -0
  174. data/test/checking/test_runner.rb +2 -0
  175. data/test/cli/commands/test_check.rb +2 -0
  176. data/test/cli/commands/test_compile.rb +2 -0
  177. data/test/cli/commands/test_create_site.rb +2 -0
  178. data/test/cli/commands/test_help.rb +2 -0
  179. data/test/cli/commands/test_info.rb +2 -0
  180. data/test/cli/commands/test_prune.rb +2 -0
  181. data/test/cli/test_cleaning_stream.rb +2 -0
  182. data/test/cli/test_cli.rb +11 -9
  183. data/test/cli/test_error_handler.rb +2 -0
  184. data/test/cli/test_logger.rb +2 -0
  185. data/test/data_sources/test_filesystem.rb +8 -6
  186. data/test/data_sources/test_filesystem_tools.rb +2 -0
  187. data/test/deploying/test_fog.rb +2 -0
  188. data/test/deploying/test_rsync.rb +4 -2
  189. data/test/extra/core_ext/test_pathname.rb +2 -0
  190. data/test/extra/core_ext/test_time.rb +2 -0
  191. data/test/extra/test_link_collector.rb +2 -0
  192. data/test/extra/test_piper.rb +2 -0
  193. data/test/filters/colorize_syntax/test_coderay.rb +2 -0
  194. data/test/filters/colorize_syntax/test_common.rb +2 -0
  195. data/test/filters/colorize_syntax/test_pygmentize.rb +2 -0
  196. data/test/filters/colorize_syntax/test_pygments.rb +2 -0
  197. data/test/filters/colorize_syntax/test_simon.rb +2 -0
  198. data/test/filters/test_asciidoc.rb +2 -0
  199. data/test/filters/test_bluecloth.rb +2 -0
  200. data/test/filters/test_coffeescript.rb +2 -0
  201. data/test/filters/test_erb.rb +7 -5
  202. data/test/filters/test_erubis.rb +6 -4
  203. data/test/filters/test_haml.rb +7 -5
  204. data/test/filters/test_handlebars.rb +2 -0
  205. data/test/filters/test_kramdown.rb +2 -0
  206. data/test/filters/test_markaby.rb +2 -0
  207. data/test/filters/test_maruku.rb +2 -0
  208. data/test/filters/test_mustache.rb +4 -2
  209. data/test/filters/test_pandoc.rb +2 -0
  210. data/test/filters/test_rainpress.rb +2 -0
  211. data/test/filters/test_rdiscount.rb +2 -0
  212. data/test/filters/test_rdoc.rb +2 -0
  213. data/test/filters/test_redcarpet.rb +2 -0
  214. data/test/filters/test_redcloth.rb +2 -0
  215. data/test/filters/test_relativize_paths.rb +2 -0
  216. data/test/filters/test_rubypants.rb +2 -0
  217. data/test/filters/test_sass.rb +4 -2
  218. data/test/filters/test_slim.rb +4 -2
  219. data/test/filters/test_typogruby.rb +2 -0
  220. data/test/filters/test_uglify_js.rb +2 -0
  221. data/test/filters/test_xsl.rb +2 -0
  222. data/test/filters/test_yui_compressor.rb +5 -3
  223. data/test/helpers/test_blogging.rb +2 -0
  224. data/test/helpers/test_capturing.rb +2 -0
  225. data/test/helpers/test_link_to.rb +2 -0
  226. data/test/helpers/test_xml_sitemap.rb +2 -0
  227. data/test/rule_dsl/test_action_provider.rb +2 -0
  228. data/test/rule_dsl/test_compiler_dsl.rb +6 -4
  229. data/test/rule_dsl/test_rule.rb +2 -0
  230. data/test/rule_dsl/test_rules_collection.rb +2 -0
  231. data/test/test_gem.rb +2 -0
  232. metadata +124 -17
  233. data/test/base/test_item_rep.rb +0 -156
@@ -0,0 +1,381 @@
1
+ require 'tempfile'
2
+
3
+ describe Nanoc::Int::Checksummer::VerboseDigest do
4
+ let(:digest) { described_class.new }
5
+
6
+ it 'concatenates' do
7
+ digest.update('foo')
8
+ digest.update('bar')
9
+ expect(digest.to_s).to eql('foobar')
10
+ end
11
+ end
12
+
13
+ describe Nanoc::Int::Checksummer::CompactDigest do
14
+ let(:digest) { described_class.new }
15
+
16
+ it 'uses SHA1 and Base64' do
17
+ digest.update('foo')
18
+ digest.update('bar')
19
+ expect(digest.to_s).to eql(Digest::SHA1.base64digest('foobar'))
20
+ end
21
+ end
22
+
23
+ describe Nanoc::Int::Checksummer do
24
+ subject { described_class.calc(obj, Nanoc::Int::Checksummer::VerboseDigest) }
25
+
26
+ context 'String' do
27
+ let(:obj) { 'hello' }
28
+ it { is_expected.to eql('String<hello>') }
29
+ end
30
+
31
+ context 'Symbol' do
32
+ let(:obj) { :hello }
33
+ it { is_expected.to eql('Symbol<hello>') }
34
+ end
35
+
36
+ context 'nil' do
37
+ let(:obj) { nil }
38
+ it { is_expected.to eql('NilClass<>') }
39
+ end
40
+
41
+ context 'true' do
42
+ let(:obj) { true }
43
+ it { is_expected.to eql('TrueClass<>') }
44
+ end
45
+
46
+ context 'false' do
47
+ let(:obj) { false }
48
+ it { is_expected.to eql('FalseClass<>') }
49
+ end
50
+
51
+ context 'Array' do
52
+ let(:obj) { %w(hello goodbye) }
53
+ it { is_expected.to eql('Array<String<hello>,String<goodbye>,>') }
54
+
55
+ context 'different order' do
56
+ let(:obj) { %w(goodbye hello) }
57
+ it { is_expected.to eql('Array<String<goodbye>,String<hello>,>') }
58
+ end
59
+
60
+ context 'recursive' do
61
+ let(:obj) { [].tap { |arr| arr << ['hello', arr] } }
62
+ it { is_expected.to eql('Array<Array<String<hello>,Array<recur>,>,>') }
63
+ end
64
+
65
+ context 'non-serializable' do
66
+ let(:obj) { [-> {}] }
67
+ it { is_expected.to match(/\AArray<Proc<#<Proc:0x.*@.*:\d+.*>>,>\z/) }
68
+ end
69
+ end
70
+
71
+ context 'Hash' do
72
+ let(:obj) { { 'a' => 'foo', 'b' => 'bar' } }
73
+ it { is_expected.to eql('Hash<String<a>=String<foo>,String<b>=String<bar>,>') }
74
+
75
+ context 'different order' do
76
+ let(:obj) { { 'b' => 'bar', 'a' => 'foo' } }
77
+ it { is_expected.to eql('Hash<String<b>=String<bar>,String<a>=String<foo>,>') }
78
+ end
79
+
80
+ context 'non-serializable' do
81
+ let(:obj) { { 'a' => -> {} } }
82
+ it { is_expected.to match(/\AHash<String<a>=Proc<#<Proc:0x.*@.*:\d+.*>>,>\z/) }
83
+ end
84
+
85
+ context 'recursive values' do
86
+ let(:obj) { {}.tap { |hash| hash['a'] = hash } }
87
+ it { is_expected.to eql('Hash<String<a>=Hash<recur>,>') }
88
+ end
89
+
90
+ context 'recursive keys' do
91
+ let(:obj) { {}.tap { |hash| hash[hash] = 'hello' } }
92
+ it { is_expected.to eql('Hash<Hash<recur>=String<hello>,>') }
93
+ end
94
+ end
95
+
96
+ context 'Pathname' do
97
+ let(:obj) { ::Pathname.new(filename) }
98
+
99
+ let(:filename) { '/tmp/whatever' }
100
+ let(:mtime) { 200 }
101
+ let(:data) { 'stuffs' }
102
+
103
+ before do
104
+ FileUtils.mkdir_p(File.dirname(filename))
105
+ File.write(filename, data)
106
+ File.utime(mtime, mtime, filename)
107
+ end
108
+
109
+ it { is_expected.to eql('Pathname<6-200>') }
110
+
111
+ context 'does not exist' do
112
+ before do
113
+ FileUtils.rm_rf(filename)
114
+ end
115
+
116
+ it { is_expected.to eql('Pathname<???>') }
117
+ end
118
+
119
+ context 'different data' do
120
+ let(:data) { 'other stuffs :o' }
121
+ it { is_expected.to eql('Pathname<15-200>') }
122
+ end
123
+ end
124
+
125
+ context 'Time' do
126
+ let(:obj) { Time.at(111_223) }
127
+ it { is_expected.to eql('Time<111223>') }
128
+ end
129
+
130
+ context 'Float' do
131
+ let(:obj) { 3.14 }
132
+ it { is_expected.to eql('Float<3.14>') }
133
+ end
134
+
135
+ context 'Fixnum/Integer' do
136
+ let(:obj) { 3 }
137
+ it { is_expected.to match(/\A(Integer|Fixnum)<3>\z/) }
138
+ end
139
+
140
+ context 'Nanoc::Identifier' do
141
+ let(:obj) { Nanoc::Identifier.new('/foo.md') }
142
+ it { is_expected.to eql('Nanoc::Identifier<String</foo.md>>') }
143
+ end
144
+
145
+ context 'Nanoc::RuleDSL::RulesCollection' do
146
+ let(:obj) do
147
+ Nanoc::RuleDSL::RulesCollection.new.tap { |rc| rc.data = data }
148
+ end
149
+
150
+ let(:data) { 'STUFF!' }
151
+
152
+ it { is_expected.to eql('Nanoc::RuleDSL::RulesCollection<String<STUFF!>>') }
153
+ end
154
+
155
+ context 'Nanoc::Int::CodeSnippet' do
156
+ let(:obj) { Nanoc::Int::CodeSnippet.new('asdf', '/bob.rb') }
157
+ it { is_expected.to eql('Nanoc::Int::CodeSnippet<String<asdf>>') }
158
+ end
159
+
160
+ context 'Nanoc::Int::Configuration' do
161
+ let(:obj) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
162
+ it { is_expected.to eql('Nanoc::Int::Configuration<Symbol<foo>=String<bar>,>') }
163
+ end
164
+
165
+ context 'Nanoc::Int::Item' do
166
+ let(:obj) { Nanoc::Int::Item.new('asdf', { 'foo' => 'bar' }, '/foo.md') }
167
+
168
+ it { is_expected.to eql('Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<Symbol<foo>=String<bar>,>,identifier=Nanoc::Identifier<String</foo.md>>>') }
169
+
170
+ context 'binary' do
171
+ let(:filename) { File.expand_path('foo.dat') }
172
+ let(:content) { Nanoc::Int::BinaryContent.new(filename) }
173
+ let(:obj) { Nanoc::Int::Item.new(content, { 'foo' => 'bar' }, '/foo.md') }
174
+
175
+ let(:mtime) { 200 }
176
+ let(:data) { 'stuffs' }
177
+
178
+ before do
179
+ File.write(content.filename, data)
180
+ File.utime(mtime, mtime, content.filename)
181
+ end
182
+
183
+ it { is_expected.to eql('Nanoc::Int::Item<content=Nanoc::Int::BinaryContent<Pathname<6-200>>,attributes=Hash<Symbol<foo>=String<bar>,>,identifier=Nanoc::Identifier<String</foo.md>>>') }
184
+ end
185
+
186
+ context 'recursive attributes' do
187
+ before do
188
+ obj.attributes[:foo] = obj
189
+ end
190
+
191
+ it { is_expected.to eql('Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<Symbol<foo>=Nanoc::Int::Item<recur>,>,identifier=Nanoc::Identifier<String</foo.md>>>') }
192
+ end
193
+
194
+ context 'with checksum' do
195
+ let(:obj) { Nanoc::Int::Item.new('asdf', { 'foo' => 'bar' }, '/foo.md', checksum_data: 'abcdef') }
196
+
197
+ it { is_expected.to eql('Nanoc::Int::Item<checksum_data=abcdef>') }
198
+ end
199
+
200
+ context 'with content checksum' do
201
+ let(:obj) { Nanoc::Int::Item.new('asdf', { 'foo' => 'bar' }, '/foo.md', content_checksum_data: 'con-cs') }
202
+
203
+ it { is_expected.to eql('Nanoc::Int::Item<content_checksum_data=con-cs,attributes=Hash<Symbol<foo>=String<bar>,>,identifier=Nanoc::Identifier<String</foo.md>>>') }
204
+ end
205
+
206
+ context 'with attributes checksum' do
207
+ let(:obj) { Nanoc::Int::Item.new('asdf', { 'foo' => 'bar' }, '/foo.md', attributes_checksum_data: 'attr-cs') }
208
+
209
+ it { is_expected.to eql('Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes_checksum_data=attr-cs,identifier=Nanoc::Identifier<String</foo.md>>>') }
210
+ end
211
+ end
212
+
213
+ context 'Nanoc::Int::Layout' do
214
+ let(:obj) { Nanoc::Int::Layout.new('asdf', { 'foo' => 'bar' }, '/foo.md') }
215
+
216
+ it { is_expected.to eql('Nanoc::Int::Layout<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<Symbol<foo>=String<bar>,>,identifier=Nanoc::Identifier<String</foo.md>>>') }
217
+
218
+ context 'recursive attributes' do
219
+ before do
220
+ obj.attributes[:foo] = obj
221
+ end
222
+
223
+ it { is_expected.to eql('Nanoc::Int::Layout<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<Symbol<foo>=Nanoc::Int::Layout<recur>,>,identifier=Nanoc::Identifier<String</foo.md>>>') }
224
+ end
225
+
226
+ context 'with checksum' do
227
+ let(:obj) { Nanoc::Int::Layout.new('asdf', { 'foo' => 'bar' }, '/foo.md', checksum_data: 'abcdef') }
228
+
229
+ it { is_expected.to eql('Nanoc::Int::Layout<checksum_data=abcdef>') }
230
+ end
231
+ end
232
+
233
+ context 'Nanoc::ItemWithRepsView' do
234
+ let(:obj) { Nanoc::ItemWithRepsView.new(item, nil) }
235
+ let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
236
+
237
+ it { is_expected.to eql('Nanoc::ItemWithRepsView<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>>') }
238
+ end
239
+
240
+ context 'Nanoc::Int::ItemRep' do
241
+ let(:obj) { Nanoc::Int::ItemRep.new(item, :pdf) }
242
+ let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
243
+
244
+ it { is_expected.to eql('Nanoc::Int::ItemRep<item=Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,name=Symbol<pdf>>') }
245
+ end
246
+
247
+ context 'Nanoc::ItemRepView' do
248
+ let(:obj) { Nanoc::ItemRepView.new(rep, :_unused_context) }
249
+ let(:rep) { Nanoc::Int::ItemRep.new(item, :pdf) }
250
+ let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
251
+
252
+ it { is_expected.to eql('Nanoc::ItemRepView<Nanoc::Int::ItemRep<item=Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,name=Symbol<pdf>>>') }
253
+ end
254
+
255
+ context 'Nanoc::ItemWithoutRepsView' do
256
+ let(:obj) { Nanoc::ItemWithoutRepsView.new(item, nil) }
257
+ let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
258
+
259
+ it { is_expected.to eql('Nanoc::ItemWithoutRepsView<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>>') }
260
+ end
261
+
262
+ context 'Nanoc::LayoutView' do
263
+ let(:obj) { Nanoc::LayoutView.new(layout, nil) }
264
+ let(:layout) { Nanoc::Int::Layout.new('asdf', {}, '/foo.md') }
265
+
266
+ it { is_expected.to eql('Nanoc::LayoutView<Nanoc::Int::Layout<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>>') }
267
+ end
268
+
269
+ context 'Nanoc::ConfigView' do
270
+ let(:obj) { Nanoc::ConfigView.new(config, nil) }
271
+ let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
272
+
273
+ it { is_expected.to eql('Nanoc::ConfigView<Nanoc::Int::Configuration<Symbol<foo>=String<bar>,>>') }
274
+ end
275
+
276
+ context 'Nanoc::ItemCollectionWithRepsView' do
277
+ let(:obj) { Nanoc::ItemCollectionWithRepsView.new(wrapped, nil) }
278
+
279
+ let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
280
+
281
+ let(:wrapped) do
282
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
283
+ arr << Nanoc::Int::Item.new('foo', {}, '/foo.md')
284
+ arr << Nanoc::Int::Item.new('bar', {}, '/foo.md')
285
+ end
286
+ end
287
+
288
+ it { is_expected.to eql('Nanoc::ItemCollectionWithRepsView<Nanoc::Int::IdentifiableCollection<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<foo>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<bar>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,>>') }
289
+ end
290
+
291
+ context 'Nanoc::ItemCollectionWithoutRepsView' do
292
+ let(:obj) { Nanoc::ItemCollectionWithoutRepsView.new(wrapped, nil) }
293
+
294
+ let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
295
+
296
+ let(:wrapped) do
297
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
298
+ arr << Nanoc::Int::Item.new('foo', {}, '/foo.md')
299
+ arr << Nanoc::Int::Item.new('bar', {}, '/foo.md')
300
+ end
301
+ end
302
+
303
+ it { is_expected.to eql('Nanoc::ItemCollectionWithoutRepsView<Nanoc::Int::IdentifiableCollection<Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<foo>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<bar>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>,>>') }
304
+ end
305
+
306
+ context 'Nanoc::RuleDSL::RuleContext' do
307
+ let(:obj) { Nanoc::RuleDSL::RuleContext.new(rep: rep, site: site, executor: executor, view_context: view_context) }
308
+
309
+ let(:rep) { Nanoc::Int::ItemRep.new(item, :pdf) }
310
+ let(:item) { Nanoc::Int::Item.new('stuff', {}, '/stuff.md') }
311
+
312
+ let(:site) do
313
+ Nanoc::Int::Site.new(config: config, code_snippets: code_snippets, items: items, layouts: layouts)
314
+ end
315
+
316
+ let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
317
+ let(:code_snippets) { [Nanoc::Int::CodeSnippet.new('asdf', '/bob.rb')] }
318
+ let(:items) { [item] }
319
+ let(:layouts) { [Nanoc::Int::Layout.new('asdf', {}, '/foo.md')] }
320
+
321
+ let(:executor) { :_unused_ }
322
+ let(:view_context) { :_unused_ }
323
+
324
+ let(:expected_item_checksum) { 'Nanoc::Int::Item<content=Nanoc::Int::TextualContent<String<stuff>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</stuff.md>>>' }
325
+ let(:expected_item_rep_checksum) { 'Nanoc::Int::ItemRep<item=' + expected_item_checksum + ',name=Symbol<pdf>>' }
326
+ let(:expected_layout_checksum) { 'Nanoc::Int::Layout<content=Nanoc::Int::TextualContent<String<asdf>>,attributes=Hash<>,identifier=Nanoc::Identifier<String</foo.md>>>' }
327
+ let(:expected_config_checksum) { 'Nanoc::Int::Configuration<Symbol<foo>=String<bar>,>' }
328
+
329
+ let(:expected_checksum) do
330
+ [
331
+ 'Nanoc::RuleDSL::RuleContext<',
332
+ 'item=',
333
+ 'Nanoc::ItemWithoutRepsView<' + expected_item_checksum + '>',
334
+ ',rep=',
335
+ 'Nanoc::ItemRepView<' + expected_item_rep_checksum + '>',
336
+ ',items=',
337
+ 'Nanoc::ItemCollectionWithoutRepsView<Array<' + expected_item_checksum + ',>>',
338
+ ',layouts=',
339
+ 'Nanoc::LayoutCollectionView<Array<' + expected_layout_checksum + ',>>',
340
+ ',config=',
341
+ 'Nanoc::ConfigView<' + expected_config_checksum + '>',
342
+ '>',
343
+ ].join('')
344
+ end
345
+
346
+ it { is_expected.to eql(expected_checksum) }
347
+ end
348
+
349
+ context 'Nanoc::Int::Context' do
350
+ let(:obj) { Nanoc::Int::Context.new(foo: 123) }
351
+
352
+ it { is_expected.to match(/\ANanoc::Int::Context<@foo=(Fixnum|Integer)<123>,>\z/) }
353
+ end
354
+
355
+ context 'Sass::Importers::Filesystem' do
356
+ let(:obj) { Sass::Importers::Filesystem.new('/foo') }
357
+
358
+ before { require 'sass' }
359
+
360
+ it { is_expected.to eql('Sass::Importers::Filesystem<root=/foo>') }
361
+ end
362
+
363
+ context 'other marshal-able classes' do
364
+ let(:obj) { klass.new('hello') }
365
+
366
+ let(:klass) do
367
+ Class.new do
368
+ def initialize(a)
369
+ @a = a
370
+ end
371
+ end
372
+ end
373
+
374
+ it { is_expected.to match(/\A#<Class:0x[0-9a-f]+><.*>\z/) }
375
+ end
376
+
377
+ context 'other non-marshal-able classes' do
378
+ let(:obj) { proc {} }
379
+ it { is_expected.to match(/\AProc<#<Proc:0x.*@.*:\d+.*>>\z/) }
380
+ end
381
+ end
@@ -0,0 +1,181 @@
1
+ describe Nanoc::Int::Compiler do
2
+ let(:compiler) do
3
+ described_class.new(
4
+ site,
5
+ compiled_content_cache: compiled_content_cache,
6
+ checksum_store: checksum_store,
7
+ rule_memory_store: rule_memory_store,
8
+ action_provider: action_provider,
9
+ dependency_store: dependency_store,
10
+ outdatedness_checker: outdatedness_checker,
11
+ reps: reps,
12
+ )
13
+ end
14
+
15
+ let(:checksum_store) { :__irrelevant_checksum_store }
16
+ let(:rule_memory_store) { :__irrelevant_rule_memory_store }
17
+
18
+ let(:dependency_store) { Nanoc::Int::DependencyStore.new(items.to_a) }
19
+ let(:reps) { Nanoc::Int::ItemRepRepo.new }
20
+
21
+ let(:outdatedness_checker) { double(:outdatedness_checker) }
22
+ let(:action_provider) { double(:action_provider) }
23
+
24
+ let(:compiled_content_cache) { Nanoc::Int::CompiledContentCache.new(items: items) }
25
+
26
+ let(:rep) { Nanoc::Int::ItemRep.new(item, :default) }
27
+ let(:item) { Nanoc::Int::Item.new('<%= 1 + 2 %>', {}, '/hi.md') }
28
+
29
+ let(:other_rep) { Nanoc::Int::ItemRep.new(other_item, :default) }
30
+ let(:other_item) { Nanoc::Int::Item.new('other content', {}, '/other.md') }
31
+
32
+ let(:site) do
33
+ Nanoc::Int::Site.new(
34
+ config: config,
35
+ code_snippets: code_snippets,
36
+ items: items,
37
+ layouts: layouts,
38
+ )
39
+ end
40
+
41
+ let(:config) { Nanoc::Int::Configuration.new.with_defaults }
42
+ let(:layouts) { [] }
43
+ let(:code_snippets) { [] }
44
+
45
+ let(:items) do
46
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |col|
47
+ col << item
48
+ col << other_item
49
+ end
50
+ end
51
+
52
+ let(:memory) do
53
+ [
54
+ Nanoc::Int::ProcessingActions::Filter.new(:erb, {}),
55
+ Nanoc::Int::ProcessingActions::Snapshot.new(:last, nil),
56
+ ]
57
+ end
58
+
59
+ before do
60
+ reps << rep
61
+ reps << other_rep
62
+
63
+ reps.each do |rep|
64
+ rep.snapshot_defs << Nanoc::Int::SnapshotDef.new(:last)
65
+ end
66
+
67
+ allow(outdatedness_checker).to receive(:outdated?).with(rep).and_return(true)
68
+ allow(outdatedness_checker).to receive(:outdated?).with(other_rep).and_return(true)
69
+
70
+ allow(action_provider).to receive(:memory_for).with(rep).and_return(memory)
71
+ allow(action_provider).to receive(:memory_for).with(other_rep).and_return(memory)
72
+ end
73
+
74
+ describe '#compile_reps' do
75
+ subject { compiler.send(:compile_reps) }
76
+
77
+ before do
78
+ allow(action_provider).to receive(:snapshots_defs_for).with(rep).and_return(snapshot_defs_for_rep)
79
+ allow(action_provider).to receive(:snapshots_defs_for).with(other_rep).and_return(snapshot_defs_for_rep)
80
+ end
81
+
82
+ let(:snapshot_defs_for_rep) do
83
+ [Nanoc::Int::SnapshotDef.new(:last)]
84
+ end
85
+
86
+ let(:snapshot_defs_for_other_rep) do
87
+ [Nanoc::Int::SnapshotDef.new(:last)]
88
+ end
89
+
90
+ it 'compiles individual reps' do
91
+ expect { subject }.to change { rep.snapshot_contents[:last].string }
92
+ .from('<%= 1 + 2 %>')
93
+ .to('3')
94
+ end
95
+
96
+ context 'exception' do
97
+ let(:item) { Nanoc::Int::Item.new('<%= raise "lol" %>', {}, '/hi.md') }
98
+
99
+ it 'wraps exception' do
100
+ expect { subject }.to raise_error(Nanoc::Int::Errors::CompilationError)
101
+ end
102
+
103
+ it 'contains the right item rep in the wrapped exception' do
104
+ expect { subject }.to raise_error do |err|
105
+ expect(err.item_rep).to eql(rep)
106
+ end
107
+ end
108
+
109
+ it 'contains the right wrapped exception' do
110
+ expect { subject }.to raise_error do |err|
111
+ expect(err.unwrap).to be_a(RuntimeError)
112
+ expect(err.unwrap.message).to eq('lol')
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe '#compile_rep' do
119
+ subject { compiler.send(:compile_rep, rep, is_outdated: is_outdated) }
120
+
121
+ let(:is_outdated) { true }
122
+
123
+ it 'generates expected output' do
124
+ expect(rep.snapshot_contents[:last].string).to eql(item.content.string)
125
+ subject
126
+ expect(rep.snapshot_contents[:last].string).to eql('3')
127
+ end
128
+
129
+ it 'generates notifications in the proper order' do
130
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_started, rep).ordered
131
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:filtering_started, rep, :erb).ordered
132
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:filtering_ended, rep, :erb).ordered
133
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_ended, rep).ordered
134
+
135
+ subject
136
+ end
137
+
138
+ context 'interrupted compilation' do
139
+ let(:item) { Nanoc::Int::Item.new('other=<%= @items["/other.*"].compiled_content %>', {}, '/hi.md') }
140
+
141
+ before do
142
+ expect(action_provider).to receive(:memory_for).with(other_rep).and_return(memory)
143
+ end
144
+
145
+ it 'generates expected output' do
146
+ expect(rep.snapshot_contents[:last].string).to eql(item.content.string)
147
+
148
+ expect { compiler.send(:compile_rep, rep, is_outdated: true) }
149
+ .to raise_error(Nanoc::Int::Errors::UnmetDependency)
150
+ compiler.send(:compile_rep, other_rep, is_outdated: true)
151
+ compiler.send(:compile_rep, rep, is_outdated: true)
152
+
153
+ expect(rep.snapshot_contents[:last].string).to eql('other=other content')
154
+ end
155
+
156
+ it 'generates notifications in the proper order' do
157
+ # rep 1
158
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_started, rep).ordered
159
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:filtering_started, rep, :erb).ordered
160
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:dependency_created, item, other_item).ordered
161
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_suspended, rep, anything).ordered
162
+
163
+ # rep 2
164
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_started, other_rep).ordered
165
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:filtering_started, other_rep, :erb).ordered
166
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:filtering_ended, other_rep, :erb).ordered
167
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_ended, other_rep).ordered
168
+
169
+ # rep 1 (again)
170
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_started, rep).ordered
171
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:filtering_ended, rep, :erb).ordered
172
+ expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:compilation_ended, rep).ordered
173
+
174
+ expect { compiler.send(:compile_rep, rep, is_outdated: true) }
175
+ .to raise_error(Nanoc::Int::Errors::UnmetDependency)
176
+ compiler.send(:compile_rep, other_rep, is_outdated: true)
177
+ compiler.send(:compile_rep, rep, is_outdated: true)
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,49 @@
1
+ describe Nanoc::Int::Configuration do
2
+ let(:hash) { { foo: 'bar' } }
3
+ let(:config) { described_class.new(hash: hash) }
4
+
5
+ describe '#key?' do
6
+ subject { config.key?(key) }
7
+
8
+ context 'non-existent key' do
9
+ let(:key) { :donkey }
10
+ it { is_expected.not_to be }
11
+ end
12
+
13
+ context 'existent key' do
14
+ let(:key) { :foo }
15
+ it { is_expected.to be }
16
+ end
17
+ end
18
+
19
+ context 'with environments defined' do
20
+ let(:hash) { { foo: 'bar', environments: { test: { foo: 'test-bar' }, default: { foo: 'default-bar' } } } }
21
+ let(:config) { described_class.new(hash: hash, env_name: env_name).with_environment }
22
+
23
+ subject { config }
24
+
25
+ context 'with existing environment' do
26
+ let(:env_name) { 'test' }
27
+
28
+ it 'inherits options from given environment' do
29
+ expect(subject[:foo]).to eq('test-bar')
30
+ end
31
+ end
32
+
33
+ context 'with unknown environment' do
34
+ let(:env_name) { 'wtf' }
35
+
36
+ it 'does not inherits options from any environment' do
37
+ expect(subject[:foo]).to eq('bar')
38
+ end
39
+ end
40
+
41
+ context 'without given environment' do
42
+ let(:env_name) { nil }
43
+
44
+ it 'inherits options from default environment' do
45
+ expect(subject[:foo]).to eq('default-bar')
46
+ end
47
+ end
48
+ end
49
+ end