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,96 @@
1
+ describe Nanoc::ConfigView do
2
+ let(:config) do
3
+ Nanoc::Int::Configuration.new(hash: hash)
4
+ end
5
+
6
+ let(:hash) { { amount: 9000, animal: 'donkey' } }
7
+
8
+ let(:view) { described_class.new(config, nil) }
9
+
10
+ describe '#frozen?' do
11
+ subject { view.frozen? }
12
+
13
+ context 'non-frozen config' do
14
+ it { is_expected.to be(false) }
15
+ end
16
+
17
+ context 'frozen config' do
18
+ before { config.freeze }
19
+ it { is_expected.to be(true) }
20
+ end
21
+ end
22
+
23
+ describe '#[]' do
24
+ subject { view[key] }
25
+
26
+ context 'with existant key' do
27
+ let(:key) { :animal }
28
+ it { is_expected.to eql('donkey') }
29
+ end
30
+
31
+ context 'with non-existant key' do
32
+ let(:key) { :weapon }
33
+ it { is_expected.to eql(nil) }
34
+ end
35
+ end
36
+
37
+ describe '#fetch' do
38
+ context 'with existant key' do
39
+ let(:key) { :animal }
40
+
41
+ subject { view.fetch(key) }
42
+
43
+ it { is_expected.to eql('donkey') }
44
+ end
45
+
46
+ context 'with non-existant key' do
47
+ let(:key) { :weapon }
48
+
49
+ context 'with fallback' do
50
+ subject { view.fetch(key, 'nothing sorry') }
51
+ it { is_expected.to eql('nothing sorry') }
52
+ end
53
+
54
+ context 'with block' do
55
+ subject { view.fetch(key) { 'nothing sorry' } }
56
+ it { is_expected.to eql('nothing sorry') }
57
+ end
58
+
59
+ context 'with no fallback and no block' do
60
+ subject { view.fetch(key) }
61
+
62
+ it 'raises' do
63
+ expect { subject }.to raise_error(KeyError)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#key?' do
70
+ subject { view.key?(key) }
71
+
72
+ context 'with existant key' do
73
+ let(:key) { :animal }
74
+ it { is_expected.to eql(true) }
75
+ end
76
+
77
+ context 'with non-existant key' do
78
+ let(:key) { :weapon }
79
+ it { is_expected.to eql(false) }
80
+ end
81
+ end
82
+
83
+ describe '#each' do
84
+ example do
85
+ res = []
86
+ view.each { |k, v| res << [k, v] }
87
+
88
+ expect(res).to eql([[:amount, 9000], [:animal, 'donkey']])
89
+ end
90
+ end
91
+
92
+ describe '#inspect' do
93
+ subject { view.inspect }
94
+ it { is_expected.to eql('<Nanoc::ConfigView>') }
95
+ end
96
+ end
@@ -0,0 +1,332 @@
1
+ shared_examples 'a document view' do
2
+ let(:view) { described_class.new(document, view_context) }
3
+
4
+ let(:view_context) do
5
+ Nanoc::ViewContext.new(
6
+ reps: double(:reps),
7
+ items: double(:items),
8
+ dependency_tracker: dependency_tracker,
9
+ compilation_context: double(:compilation_context),
10
+ )
11
+ end
12
+
13
+ let(:dependency_tracker) { Nanoc::Int::DependencyTracker.new(dependency_store) }
14
+ let(:dependency_store) { Nanoc::Int::DependencyStore.new([]) }
15
+ let(:base_item) { Nanoc::Int::Item.new('base', {}, '/base.md') }
16
+
17
+ before do
18
+ dependency_tracker.enter(base_item)
19
+ end
20
+
21
+ describe '#frozen?' do
22
+ let(:document) { entity_class.new('content', {}, '/asdf/') }
23
+
24
+ subject { view.frozen? }
25
+
26
+ context 'non-frozen document' do
27
+ it { is_expected.to be(false) }
28
+ end
29
+
30
+ context 'frozen document' do
31
+ before { document.freeze }
32
+ it { is_expected.to be(true) }
33
+ end
34
+ end
35
+
36
+ describe '#== and #eql?' do
37
+ let(:document) { entity_class.new('content', {}, '/asdf/') }
38
+
39
+ context 'comparing with document with same identifier' do
40
+ let(:other) { entity_class.new('content', {}, '/asdf/') }
41
+
42
+ it 'is ==' do
43
+ expect(view).to eq(other)
44
+ end
45
+
46
+ it 'is not eql?' do
47
+ expect(view).not_to eql(other)
48
+ end
49
+ end
50
+
51
+ context 'comparing with document with different identifier' do
52
+ let(:other) { entity_class.new('content', {}, '/fdsa/') }
53
+
54
+ it 'is not ==' do
55
+ expect(view).not_to eq(other)
56
+ end
57
+
58
+ it 'is not eql?' do
59
+ expect(view).not_to eql(other)
60
+ end
61
+ end
62
+
63
+ context 'comparing with document view with same identifier' do
64
+ let(:other) { other_view_class.new(entity_class.new('content', {}, '/asdf/'), nil) }
65
+
66
+ it 'is ==' do
67
+ expect(view).to eq(other)
68
+ end
69
+
70
+ it 'is not eql?' do
71
+ expect(view).not_to eql(other)
72
+ end
73
+ end
74
+
75
+ context 'comparing with document view with different identifier' do
76
+ let(:other) { other_view_class.new(entity_class.new('content', {}, '/fdsa/'), nil) }
77
+
78
+ it 'is not ==' do
79
+ expect(view).not_to eq(other)
80
+ end
81
+
82
+ it 'is not eql?' do
83
+ expect(view).not_to eql(other)
84
+ end
85
+ end
86
+
87
+ context 'comparing with other object' do
88
+ let(:other) { nil }
89
+
90
+ it 'is not ==' do
91
+ expect(view).not_to eq(other)
92
+ end
93
+
94
+ it 'is not eql?' do
95
+ expect(view).not_to eql(other)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe '#[]' do
101
+ let(:document) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
102
+
103
+ subject { view[key] }
104
+
105
+ context 'with existant key' do
106
+ let(:key) { :animal }
107
+
108
+ it { is_expected.to eql('donkey') }
109
+
110
+ it 'creates a dependency' do
111
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
112
+ end
113
+
114
+ it 'creates a dependency with the right props' do
115
+ subject
116
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
117
+
118
+ expect(dep.props.attributes?).to eq(true)
119
+
120
+ expect(dep.props.raw_content?).to eq(false)
121
+ expect(dep.props.compiled_content?).to eq(false)
122
+ expect(dep.props.path?).to eq(false)
123
+ end
124
+ end
125
+
126
+ context 'with non-existant key' do
127
+ let(:key) { :weapon }
128
+
129
+ it { is_expected.to eql(nil) }
130
+
131
+ it 'creates a dependency' do
132
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
133
+ end
134
+
135
+ it 'creates a dependency with the right props' do
136
+ subject
137
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
138
+
139
+ expect(dep.props.attributes?).to eq(true)
140
+
141
+ expect(dep.props.raw_content?).to eq(false)
142
+ expect(dep.props.compiled_content?).to eq(false)
143
+ expect(dep.props.path?).to eq(false)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe '#attributes' do
149
+ let(:document) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
150
+
151
+ subject { view.attributes }
152
+
153
+ it 'creates a dependency' do
154
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
155
+ end
156
+
157
+ it 'creates a dependency with the right props' do
158
+ subject
159
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
160
+
161
+ expect(dep.props.attributes?).to eq(true)
162
+
163
+ expect(dep.props.raw_content?).to eq(false)
164
+ expect(dep.props.compiled_content?).to eq(false)
165
+ expect(dep.props.path?).to eq(false)
166
+ end
167
+
168
+ it 'returns attributes' do
169
+ expect(subject).to eql(animal: 'donkey')
170
+ end
171
+ end
172
+
173
+ describe '#fetch' do
174
+ let(:document) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
175
+
176
+ context 'with existant key' do
177
+ let(:key) { :animal }
178
+
179
+ subject { view.fetch(key) }
180
+
181
+ it { is_expected.to eql('donkey') }
182
+
183
+ it 'creates a dependency' do
184
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
185
+ end
186
+
187
+ it 'creates a dependency with the right props' do
188
+ subject
189
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
190
+
191
+ expect(dep.props.attributes?).to eq(true)
192
+
193
+ expect(dep.props.raw_content?).to eq(false)
194
+ expect(dep.props.compiled_content?).to eq(false)
195
+ expect(dep.props.path?).to eq(false)
196
+ end
197
+ end
198
+
199
+ context 'with non-existant key' do
200
+ let(:key) { :weapon }
201
+
202
+ context 'with fallback' do
203
+ subject { view.fetch(key, 'nothing sorry') }
204
+
205
+ it { is_expected.to eql('nothing sorry') }
206
+
207
+ it 'creates a dependency' do
208
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
209
+ end
210
+
211
+ it 'creates a dependency with the right props' do
212
+ subject
213
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
214
+
215
+ expect(dep.props.attributes?).to eq(true)
216
+
217
+ expect(dep.props.raw_content?).to eq(false)
218
+ expect(dep.props.compiled_content?).to eq(false)
219
+ expect(dep.props.path?).to eq(false)
220
+ end
221
+ end
222
+
223
+ context 'with block' do
224
+ subject { view.fetch(key) { 'nothing sorry' } }
225
+
226
+ it { is_expected.to eql('nothing sorry') }
227
+
228
+ it 'creates a dependency' do
229
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
230
+ end
231
+
232
+ it 'creates a dependency with the right props' do
233
+ subject
234
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
235
+
236
+ expect(dep.props.attributes?).to eq(true)
237
+
238
+ expect(dep.props.raw_content?).to eq(false)
239
+ expect(dep.props.compiled_content?).to eq(false)
240
+ expect(dep.props.path?).to eq(false)
241
+ end
242
+ end
243
+
244
+ context 'with no fallback and no block' do
245
+ subject { view.fetch(key) }
246
+
247
+ it 'raises' do
248
+ expect { subject }.to raise_error(KeyError)
249
+ end
250
+ end
251
+ end
252
+ end
253
+
254
+ describe '#key?' do
255
+ let(:document) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
256
+
257
+ subject { view.key?(key) }
258
+
259
+ context 'with existant key' do
260
+ let(:key) { :animal }
261
+
262
+ it { is_expected.to eql(true) }
263
+
264
+ it 'creates a dependency' do
265
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
266
+ end
267
+
268
+ it 'creates a dependency with the right props' do
269
+ subject
270
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
271
+
272
+ expect(dep.props.attributes?).to eq(true)
273
+
274
+ expect(dep.props.raw_content?).to eq(false)
275
+ expect(dep.props.compiled_content?).to eq(false)
276
+ expect(dep.props.path?).to eq(false)
277
+ end
278
+ end
279
+
280
+ context 'with non-existant key' do
281
+ let(:key) { :weapon }
282
+
283
+ it { is_expected.to eql(false) }
284
+
285
+ it 'creates a dependency' do
286
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
287
+ end
288
+
289
+ it 'creates a dependency with the right props' do
290
+ subject
291
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
292
+
293
+ expect(dep.props.attributes?).to eq(true)
294
+
295
+ expect(dep.props.raw_content?).to eq(false)
296
+ expect(dep.props.compiled_content?).to eq(false)
297
+ expect(dep.props.path?).to eq(false)
298
+ end
299
+ end
300
+ end
301
+
302
+ describe '#hash' do
303
+ let(:document) { double(:document, identifier: '/foo/') }
304
+
305
+ subject { view.hash }
306
+
307
+ it { should == described_class.hash ^ '/foo/'.hash }
308
+ end
309
+
310
+ describe '#raw_content' do
311
+ let(:document) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
312
+
313
+ subject { view.raw_content }
314
+
315
+ it { is_expected.to eql('stuff') }
316
+
317
+ it 'creates a dependency' do
318
+ expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([document])
319
+ end
320
+
321
+ it 'creates a dependency with the right props' do
322
+ subject
323
+ dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]
324
+
325
+ expect(dep.props.raw_content?).to eq(true)
326
+
327
+ expect(dep.props.attributes?).to eq(false)
328
+ expect(dep.props.compiled_content?).to eq(false)
329
+ expect(dep.props.path?).to eq(false)
330
+ end
331
+ end
332
+ end
@@ -0,0 +1,190 @@
1
+ # Needs :view_class
2
+ shared_examples 'an identifiable collection' do
3
+ let(:view) { described_class.new(wrapped, view_context) }
4
+
5
+ let(:view_context) { double(:view_context) }
6
+
7
+ let(:config) do
8
+ { string_pattern_type: 'glob' }
9
+ end
10
+
11
+ describe '#frozen?' do
12
+ let(:wrapped) do
13
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
14
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/foo'))
15
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/bar'))
16
+ end
17
+ end
18
+
19
+ subject { view.frozen? }
20
+
21
+ context 'non-frozen collection' do
22
+ it { is_expected.to be(false) }
23
+ end
24
+
25
+ context 'frozen collection' do
26
+ before do
27
+ wrapped.each { |o| expect(o).to receive(:freeze) }
28
+ wrapped.freeze
29
+ end
30
+
31
+ it { is_expected.to be(true) }
32
+ end
33
+ end
34
+
35
+ describe '#unwrap' do
36
+ let(:wrapped) do
37
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
38
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/foo'))
39
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/bar'))
40
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/baz'))
41
+ end
42
+ end
43
+
44
+ subject { view.unwrap }
45
+
46
+ it { should equal(wrapped) }
47
+ end
48
+
49
+ describe '#each' do
50
+ let(:wrapped) do
51
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
52
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/foo'))
53
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/bar'))
54
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/baz'))
55
+ end
56
+ end
57
+
58
+ it 'returns self' do
59
+ expect(view.each { |_i| }).to equal(view)
60
+ end
61
+
62
+ it 'yields elements with the right context' do
63
+ view.each { |v| expect(v._context).to equal(view_context) }
64
+ end
65
+ end
66
+
67
+ describe '#size' do
68
+ let(:wrapped) do
69
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
70
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/foo'))
71
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/bar'))
72
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/baz'))
73
+ end
74
+ end
75
+
76
+ subject { view.size }
77
+
78
+ it { should == 3 }
79
+ end
80
+
81
+ describe '#[]' do
82
+ let(:page_object) do
83
+ double(:identifiable, identifier: Nanoc::Identifier.new('/page.erb'))
84
+ end
85
+
86
+ let(:home_object) do
87
+ double(:identifiable, identifier: Nanoc::Identifier.new('/home.erb'))
88
+ end
89
+
90
+ let(:wrapped) do
91
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
92
+ arr << page_object
93
+ arr << home_object
94
+ end
95
+ end
96
+
97
+ subject { view[arg] }
98
+
99
+ context 'no objects found' do
100
+ let(:arg) { '/donkey.*' }
101
+ it { is_expected.to equal(nil) }
102
+ end
103
+
104
+ context 'string' do
105
+ let(:arg) { '/home.erb' }
106
+
107
+ it 'returns wrapped object' do
108
+ expect(subject.class).to equal(view_class)
109
+ expect(subject.unwrap).to equal(home_object)
110
+ end
111
+
112
+ it 'returns objects with right context' do
113
+ expect(subject._context).to equal(view_context)
114
+ end
115
+ end
116
+
117
+ context 'identifier' do
118
+ let(:arg) { Nanoc::Identifier.new('/home.erb') }
119
+
120
+ it 'returns wrapped object' do
121
+ expect(subject.class).to equal(view_class)
122
+ expect(subject.unwrap).to equal(home_object)
123
+ end
124
+ end
125
+
126
+ context 'glob' do
127
+ let(:arg) { '/home.*' }
128
+
129
+ context 'globs not enabled' do
130
+ let(:config) { { string_pattern_type: 'legacy' } }
131
+
132
+ it 'returns nil' do
133
+ expect(subject).to be_nil
134
+ end
135
+ end
136
+
137
+ context 'globs enabled' do
138
+ it 'returns wrapped object' do
139
+ expect(subject.class).to equal(view_class)
140
+ expect(subject.unwrap).to equal(home_object)
141
+ end
142
+ end
143
+ end
144
+
145
+ context 'regex' do
146
+ let(:arg) { %r{\A/home} }
147
+
148
+ it 'returns wrapped object' do
149
+ expect(subject.class).to equal(view_class)
150
+ expect(subject.unwrap).to equal(home_object)
151
+ end
152
+ end
153
+ end
154
+
155
+ describe '#find_all' do
156
+ let(:wrapped) do
157
+ Nanoc::Int::IdentifiableCollection.new(config).tap do |arr|
158
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/about.css'))
159
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/about.md'))
160
+ arr << double(:identifiable, identifier: Nanoc::Identifier.new('/style.css'))
161
+ end
162
+ end
163
+
164
+ subject { view.find_all(arg) }
165
+
166
+ context 'with string' do
167
+ let(:arg) { '/*.css' }
168
+
169
+ it 'contains views' do
170
+ expect(subject.size).to eql(2)
171
+ about_css = subject.find { |iv| iv.identifier == '/about.css' }
172
+ style_css = subject.find { |iv| iv.identifier == '/style.css' }
173
+ expect(about_css.class).to equal(view_class)
174
+ expect(style_css.class).to equal(view_class)
175
+ end
176
+ end
177
+
178
+ context 'with regex' do
179
+ let(:arg) { %r{\.css\z} }
180
+
181
+ it 'contains views' do
182
+ expect(subject.size).to eql(2)
183
+ about_css = subject.find { |iv| iv.identifier == '/about.css' }
184
+ style_css = subject.find { |iv| iv.identifier == '/style.css' }
185
+ expect(about_css.class).to equal(view_class)
186
+ expect(style_css.class).to equal(view_class)
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,18 @@
1
+ describe Nanoc::ItemCollectionWithRepsView do
2
+ let(:view_class) { Nanoc::ItemWithRepsView }
3
+ it_behaves_like 'an identifiable collection'
4
+
5
+ describe '#inspect' do
6
+ let(:wrapped) do
7
+ Nanoc::Int::IdentifiableCollection.new(config)
8
+ end
9
+
10
+ let(:view) { described_class.new(wrapped, view_context) }
11
+ let(:view_context) { double(:view_context) }
12
+ let(:config) { { string_pattern_type: 'glob' } }
13
+
14
+ subject { view.inspect }
15
+
16
+ it { is_expected.to eql('<Nanoc::ItemCollectionWithRepsView>') }
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ describe Nanoc::ItemCollectionWithoutRepsView do
2
+ let(:view_class) { Nanoc::ItemWithoutRepsView }
3
+ it_behaves_like 'an identifiable collection'
4
+
5
+ describe '#inspect' do
6
+ let(:wrapped) do
7
+ Nanoc::Int::IdentifiableCollection.new(config)
8
+ end
9
+
10
+ let(:view) { described_class.new(wrapped, view_context) }
11
+ let(:view_context) { double(:view_context) }
12
+ let(:config) { { string_pattern_type: 'glob' } }
13
+
14
+ subject { view.inspect }
15
+
16
+ it { is_expected.to eql('<Nanoc::ItemCollectionWithoutRepsView>') }
17
+ end
18
+ end