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,137 @@
1
+ describe Nanoc::PostCompileItemRepView do
2
+ let(:item_rep) { Nanoc::Int::ItemRep.new(item, :jacques) }
3
+ let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo/') }
4
+ let(:view) { described_class.new(item_rep, view_context) }
5
+
6
+ let(:view_context) do
7
+ Nanoc::ViewContext.new(
8
+ reps: reps,
9
+ items: items,
10
+ dependency_tracker: dependency_tracker,
11
+ compilation_context: compilation_context,
12
+ )
13
+ end
14
+
15
+ let(:reps) { double(:reps) }
16
+ let(:items) { Nanoc::Int::IdentifiableCollection.new(config) }
17
+ let(:config) { Nanoc::Int::Configuration.new }
18
+ let(:dependency_tracker) { Nanoc::Int::DependencyTracker.new(double(:dependency_store)) }
19
+ let(:compilation_context) { double(:compilation_context, compiled_content_cache: compiled_content_cache) }
20
+
21
+ let(:snapshot_contents) do
22
+ {
23
+ last: Nanoc::Int::TextualContent.new('content-last'),
24
+ pre: Nanoc::Int::TextualContent.new('content-pre'),
25
+ donkey: Nanoc::Int::TextualContent.new('content-donkey'),
26
+ }
27
+ end
28
+
29
+ let(:compiled_content_cache) do
30
+ Nanoc::Int::CompiledContentCache.new(items: items).tap do |ccc|
31
+ ccc[item_rep] = snapshot_contents
32
+ end
33
+ end
34
+
35
+ describe '#compiled_content' do
36
+ subject { view.compiled_content }
37
+
38
+ context 'binary' do
39
+ let(:item) do
40
+ content = Nanoc::Int::Content.create('/foo.dat', binary: true)
41
+ Nanoc::Int::Item.new(content, {}, '/foo.dat')
42
+ end
43
+
44
+ it 'raises error' do
45
+ err = Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem
46
+ expect { subject }.to raise_error(err)
47
+ end
48
+ end
49
+
50
+ shared_examples 'returns pre content' do
51
+ example { expect(subject).to eq('content-pre') }
52
+ end
53
+
54
+ shared_examples 'returns last content' do
55
+ example { expect(subject).to eq('content-last') }
56
+ end
57
+
58
+ shared_examples 'returns donkey content' do
59
+ example { expect(subject).to eq('content-donkey') }
60
+ end
61
+
62
+ shared_examples 'raises no-such-snapshot error' do
63
+ it 'raises error' do
64
+ err = Nanoc::Int::Errors::NoSuchSnapshot
65
+ expect { subject }.to raise_error(err)
66
+ end
67
+ end
68
+
69
+ context 'textual' do
70
+ context 'snapshot provided' do
71
+ subject { view.compiled_content(snapshot: :donkey) }
72
+ let(:expected_snapshot) { :donkey }
73
+
74
+ context 'snapshot exists' do
75
+ include_examples 'returns donkey content'
76
+ end
77
+
78
+ context 'snapshot does not exist' do
79
+ let(:snapshot_contents) do
80
+ {
81
+ last: Nanoc::Int::TextualContent.new('content-last'),
82
+ pre: Nanoc::Int::TextualContent.new('content-pre'),
83
+ }
84
+ end
85
+
86
+ include_examples 'raises no-such-snapshot error'
87
+ end
88
+ end
89
+
90
+ context 'no snapshot provided' do
91
+ context 'pre and last snapshots exist' do
92
+ let(:snapshot_contents) do
93
+ {
94
+ last: Nanoc::Int::TextualContent.new('content-last'),
95
+ pre: Nanoc::Int::TextualContent.new('content-pre'),
96
+ donkey: Nanoc::Int::TextualContent.new('content-donkey'),
97
+ }
98
+ end
99
+
100
+ include_examples 'returns pre content'
101
+ end
102
+
103
+ context 'pre snapshot exists' do
104
+ let(:snapshot_contents) do
105
+ {
106
+ pre: Nanoc::Int::TextualContent.new('content-pre'),
107
+ donkey: Nanoc::Int::TextualContent.new('content-donkey'),
108
+ }
109
+ end
110
+
111
+ include_examples 'returns pre content'
112
+ end
113
+
114
+ context 'last snapshot exists' do
115
+ let(:snapshot_contents) do
116
+ {
117
+ last: Nanoc::Int::TextualContent.new('content-last'),
118
+ donkey: Nanoc::Int::TextualContent.new('content-donkey'),
119
+ }
120
+ end
121
+
122
+ include_examples 'returns last content'
123
+ end
124
+
125
+ context 'neither pre nor last snapshot exists' do
126
+ let(:snapshot_contents) do
127
+ {
128
+ donkey: Nanoc::Int::TextualContent.new('content-donkey'),
129
+ }
130
+ end
131
+
132
+ include_examples 'raises no-such-snapshot error'
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,56 @@
1
+ describe Nanoc::PostCompileItemView do
2
+ let(:item) { Nanoc::Int::Item.new('blah', {}, '/foo.md') }
3
+ let(:rep_a) { Nanoc::Int::ItemRep.new(item, :no_mod) }
4
+ let(:rep_b) { Nanoc::Int::ItemRep.new(item, :modded).tap { |r| r.modified = true } }
5
+
6
+ let(:reps) do
7
+ Nanoc::Int::ItemRepRepo.new.tap do |reps|
8
+ reps << rep_a
9
+ reps << rep_b
10
+ end
11
+ end
12
+
13
+ let(:view_context) { double(:view_context, reps: reps) }
14
+ let(:view) { described_class.new(item, view_context) }
15
+
16
+ shared_examples 'a method that returns modified reps only' do
17
+ it 'returns only modified items' do
18
+ expect(subject.size).to eq(1)
19
+ expect(subject.map(&:name)).to eq(%i(modded))
20
+ end
21
+
22
+ it 'returns an array' do
23
+ expect(subject.class).to eql(Array)
24
+ end
25
+ end
26
+
27
+ shared_examples 'a method that returns PostCompileItemRepViews' do
28
+ it 'returns PostCompileItemRepViews' do
29
+ expect(subject).to all(be_a(Nanoc::PostCompileItemRepView))
30
+ end
31
+ end
32
+
33
+ describe '#modified_reps' do
34
+ subject { view.modified_reps }
35
+
36
+ it_behaves_like 'a method that returns modified reps only'
37
+ it_behaves_like 'a method that returns PostCompileItemRepViews'
38
+ end
39
+
40
+ describe '#modified' do
41
+ subject { view.modified }
42
+
43
+ it_behaves_like 'a method that returns modified reps only'
44
+ it_behaves_like 'a method that returns PostCompileItemRepViews'
45
+ end
46
+
47
+ describe '#reps' do
48
+ subject { view.reps }
49
+
50
+ it_behaves_like 'a method that returns PostCompileItemRepViews'
51
+
52
+ it 'returns a PostCompileItemRepCollectionView' do
53
+ expect(subject).to be_a(Nanoc::PostCompileItemRepCollectionView)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,76 @@
1
+ describe Nanoc::CLI::Commands::Compile::FileActionPrinter, stdio: true do
2
+ let(:listener) { described_class.new(reps: reps) }
3
+
4
+ before { Timecop.freeze(Time.local(2008, 1, 2, 14, 5, 0)) }
5
+ after { Timecop.return }
6
+
7
+ let(:reps) do
8
+ Nanoc::Int::ItemRepRepo.new.tap do |reps|
9
+ reps << rep
10
+ end
11
+ end
12
+
13
+ let(:item) { Nanoc::Int::Item.new('<%= 1 + 2 %>', {}, '/hi.md') }
14
+
15
+ let(:rep) do
16
+ Nanoc::Int::ItemRep.new(item, :default).tap do |rep|
17
+ rep.raw_paths = { default: '/hi.html' }
18
+ end
19
+ end
20
+
21
+ it 'records from compilation_started to rep_written' do
22
+ listener.start
23
+
24
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
25
+ Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
26
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
27
+
28
+ expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, '/foo.html', true, true) }
29
+ .to output(/create.*\[1\.00s\]/).to_stdout
30
+ end
31
+
32
+ it 'stops listening after #stop' do
33
+ listener.start
34
+ listener.stop
35
+
36
+ Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
37
+
38
+ expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, '/foo.html', true, true) }
39
+ .not_to output(/create/).to_stdout
40
+ end
41
+
42
+ it 'records from compilation_started over compilation_suspended to rep_written' do
43
+ listener.start
44
+
45
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
46
+ Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
47
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
48
+ Nanoc::Int::NotificationCenter.post(:compilation_suspended, rep, :__irrelevant__)
49
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 3))
50
+ Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
51
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 6))
52
+
53
+ expect { Nanoc::Int::NotificationCenter.post(:rep_written, rep, '/foo.html', true, true) }
54
+ .to output(/create.*\[4\.00s\]/).to_stdout
55
+ end
56
+
57
+ context 'log level = high' do
58
+ before { listener.start }
59
+ before { Nanoc::CLI::Logger.instance.level = :high }
60
+
61
+ it 'prints skipped (uncompiled) reps' do
62
+ expect { listener.stop }
63
+ .not_to output(/skip/).to_stdout
64
+ end
65
+ end
66
+
67
+ context 'log level = low' do
68
+ before { listener.start }
69
+ before { Nanoc::CLI::Logger.instance.level = :low }
70
+
71
+ it 'prints nothing' do
72
+ expect { listener.stop }
73
+ .to output(/skip.*\/hi\.html/).to_stdout
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,66 @@
1
+ describe Nanoc::CLI::Commands::Compile::TimingRecorder, stdio: true do
2
+ let(:listener) { described_class.new(reps: reps) }
3
+
4
+ before { Timecop.freeze(Time.local(2008, 1, 2, 14, 5, 0)) }
5
+ after { Timecop.return }
6
+
7
+ let(:reps) do
8
+ Nanoc::Int::ItemRepRepo.new.tap do |reps|
9
+ reps << rep
10
+ end
11
+ end
12
+
13
+ let(:item) { Nanoc::Int::Item.new('<%= 1 + 2 %>', {}, '/hi.md') }
14
+
15
+ let(:rep) do
16
+ Nanoc::Int::ItemRep.new(item, :default).tap do |rep|
17
+ rep.raw_paths = { default: '/hi.html' }
18
+ end
19
+ end
20
+
21
+ it 'records single from filtering_started to filtering_ended' do
22
+ listener.start
23
+
24
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
25
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :erb)
26
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
27
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
28
+
29
+ expect { listener.stop }
30
+ .to output(/^erb \| 1 1\.00s 1\.00s 1\.00s 1\.00s$/).to_stdout
31
+ end
32
+
33
+ it 'records multiple from filtering_started to filtering_ended' do
34
+ listener.start
35
+
36
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
37
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :erb)
38
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
39
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
40
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 14, 1))
41
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :erb)
42
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 14, 3))
43
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
44
+
45
+ expect { listener.stop }
46
+ .to output(/^erb \| 2 1\.00s 1\.50s 2\.00s 3\.00s$/).to_stdout
47
+ end
48
+
49
+ it 'records single from filtering_started over compilation_{suspended,started} to filtering_ended' do
50
+ listener.start
51
+
52
+ Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
53
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 0))
54
+ Nanoc::Int::NotificationCenter.post(:filtering_started, rep, :erb)
55
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 1))
56
+ Nanoc::Int::NotificationCenter.post(:compilation_suspended, rep, :__anything__)
57
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 3))
58
+ Nanoc::Int::NotificationCenter.post(:compilation_started, rep)
59
+ Timecop.freeze(Time.local(2008, 9, 1, 10, 5, 7))
60
+ Nanoc::Int::NotificationCenter.post(:filtering_ended, rep, :erb)
61
+
62
+ # FIXME: wrong count (should be 1, not 2)
63
+ expect { listener.stop }
64
+ .to output(/^erb \| 2 1\.00s 2\.50s 4\.00s 5\.00s$/).to_stdout
65
+ end
66
+ end
@@ -0,0 +1,64 @@
1
+ describe Nanoc::CLI::Commands::Compile::Listener do
2
+ let(:klass) do
3
+ Class.new(described_class) do
4
+ attr_reader :started
5
+ attr_reader :stopped
6
+
7
+ def initialize
8
+ @started = false
9
+ @stopped = false
10
+ end
11
+
12
+ def start
13
+ @started = true
14
+ end
15
+
16
+ def stop
17
+ @stopped = true
18
+ end
19
+ end
20
+ end
21
+
22
+ subject { klass.new }
23
+
24
+ it 'starts' do
25
+ subject.start
26
+ expect(subject.started).to be
27
+ end
28
+
29
+ it 'stops' do
30
+ subject.start
31
+ subject.stop
32
+ expect(subject.stopped).to be
33
+ end
34
+
35
+ it 'starts safely' do
36
+ subject.start_safely
37
+ expect(subject.started).to be
38
+ end
39
+
40
+ it 'stops safely' do
41
+ subject.start_safely
42
+ subject.stop_safely
43
+ expect(subject.stopped).to be
44
+ end
45
+
46
+ context 'listener that does not start or stop properly' do
47
+ let(:klass) do
48
+ Class.new(described_class) do
49
+ def start
50
+ raise 'boom'
51
+ end
52
+
53
+ def stop
54
+ raise 'boom'
55
+ end
56
+ end
57
+ end
58
+
59
+ it 'raises on start, but not stop' do
60
+ expect { subject.start_safely }.to raise_error(RuntimeError)
61
+ expect { subject.stop_safely }.not_to raise_error
62
+ end
63
+ end
64
+ end