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,106 @@
1
+ describe Nanoc::Int::LazyValue do
2
+ describe '#value' do
3
+ let(:value_arg) { 'Hello world' }
4
+ let(:lazy_value) { described_class.new(value_arg) }
5
+
6
+ subject { lazy_value.value }
7
+
8
+ context 'object' do
9
+ it { is_expected.to equal(value_arg) }
10
+ end
11
+
12
+ context 'proc' do
13
+ it 'does not call the proc immediately' do
14
+ expect(value_arg).not_to receive(:call)
15
+
16
+ lazy_value
17
+ end
18
+
19
+ it 'returns proc return value' do
20
+ expect(value_arg).to receive(:call).once.and_return('Hello proc')
21
+
22
+ expect(subject).to eql('Hello proc')
23
+ end
24
+
25
+ it 'only calls the proc once' do
26
+ expect(value_arg).to receive(:call).once.and_return('Hello proc')
27
+
28
+ expect(subject).to eql('Hello proc')
29
+ expect(subject).to eql('Hello proc')
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#map' do
35
+ let(:value_arg) { -> { 'Hello world' } }
36
+ let(:lazy_value) { described_class.new(value_arg) }
37
+
38
+ subject { lazy_value.map(&:upcase) }
39
+
40
+ it 'does not call the proc immediately' do
41
+ expect(value_arg).not_to receive(:call)
42
+
43
+ subject
44
+ end
45
+
46
+ it 'returns proc return value' do
47
+ expect(value_arg).to receive(:call).once.and_return('Hello proc')
48
+
49
+ expect(subject.value).to eql('HELLO PROC')
50
+ end
51
+
52
+ it 'only calls the proc once' do
53
+ expect(value_arg).to receive(:call).once.and_return('Hello proc')
54
+
55
+ expect(subject.value).to eql('HELLO PROC')
56
+ expect(subject.value).to eql('HELLO PROC')
57
+ end
58
+ end
59
+
60
+ describe '#freeze' do
61
+ let(:value_arg) { 'Hello world' }
62
+
63
+ subject { described_class.new(value_arg) }
64
+
65
+ before do
66
+ subject.freeze
67
+ end
68
+
69
+ context 'object' do
70
+ it 'returns value' do
71
+ expect(subject.value).to equal(value_arg)
72
+ end
73
+
74
+ it 'freezes value' do
75
+ expect(subject.value).to be_frozen
76
+ end
77
+ end
78
+
79
+ context 'proc' do
80
+ call_count = 0
81
+ let(:value_arg) do
82
+ proc do
83
+ call_count += 1
84
+ 'Hello proc'
85
+ end
86
+ end
87
+
88
+ before do
89
+ call_count = 0
90
+ subject.freeze
91
+ end
92
+
93
+ it 'does not call the proc immediately' do
94
+ expect(call_count).to eql(0)
95
+ end
96
+
97
+ it 'returns proc return value' do
98
+ expect(subject.value).to eq('Hello proc')
99
+ end
100
+
101
+ it 'freezes upon access' do
102
+ expect(subject.value).to be_frozen
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,113 @@
1
+ describe Nanoc::Int::OutdatednessStatus do
2
+ let(:status) { described_class.new }
3
+
4
+ describe '#reasons' do
5
+ subject { status.reasons }
6
+
7
+ context 'default' do
8
+ it { is_expected.to eql([]) }
9
+ end
10
+
11
+ context 'one passed in' do
12
+ let(:reasons) do
13
+ [
14
+ Nanoc::Int::OutdatednessReasons::CodeSnippetsModified,
15
+ ]
16
+ end
17
+
18
+ let(:status) { described_class.new(reasons: reasons) }
19
+
20
+ it { is_expected.to eql(reasons) }
21
+ end
22
+
23
+ context 'two passed in' do
24
+ let(:reasons) do
25
+ [
26
+ Nanoc::Int::OutdatednessReasons::CodeSnippetsModified,
27
+ Nanoc::Int::OutdatednessReasons::ContentModified,
28
+ ]
29
+ end
30
+
31
+ let(:status) { described_class.new(reasons: reasons) }
32
+
33
+ it { is_expected.to eql(reasons) }
34
+ end
35
+ end
36
+
37
+ describe '#props' do
38
+ subject { status.props.active }
39
+
40
+ context 'default' do
41
+ it { is_expected.to eql(Set.new) }
42
+ end
43
+
44
+ context 'specific one passed in' do
45
+ let(:props) do
46
+ Nanoc::Int::Props.new(attributes: true)
47
+ end
48
+
49
+ let(:status) { described_class.new(props: props) }
50
+
51
+ it { is_expected.to eql(Set.new([:attributes])) }
52
+ end
53
+ end
54
+
55
+ describe '#useful_to_apply' do
56
+ subject { status.useful_to_apply?(rule) }
57
+
58
+ let(:status) { described_class.new(props: props) }
59
+ let(:props) { Nanoc::Int::Props.new }
60
+ let(:rule) { Nanoc::Int::OutdatednessRules::RulesModified }
61
+
62
+ context 'no props' do
63
+ it { is_expected.to be }
64
+ end
65
+
66
+ context 'some props' do
67
+ context 'same props' do
68
+ let(:props) { Nanoc::Int::Props.new(compiled_content: true, path: true) }
69
+ it { is_expected.not_to be }
70
+ end
71
+
72
+ context 'different props' do
73
+ let(:props) { Nanoc::Int::Props.new(attributes: true) }
74
+ it { is_expected.to be }
75
+ end
76
+ end
77
+
78
+ context 'all props' do
79
+ let(:props) { Nanoc::Int::Props.new(raw_content: true, attributes: true, compiled_content: true, path: true) }
80
+ it { is_expected.not_to be }
81
+ end
82
+ end
83
+
84
+ describe '#update' do
85
+ subject { status.update(reason) }
86
+
87
+ let(:reason) { Nanoc::Int::OutdatednessReasons::ContentModified }
88
+
89
+ context 'no existing reason or props' do
90
+ it 'adds a reason' do
91
+ expect(subject.reasons).to eql([reason])
92
+ end
93
+ end
94
+
95
+ context 'existing reason' do
96
+ let(:status) { described_class.new(reasons: [old_reason]) }
97
+
98
+ let(:old_reason) { Nanoc::Int::OutdatednessReasons::NotWritten }
99
+
100
+ it 'adds a reason' do
101
+ expect(subject.reasons).to eql([old_reason, reason])
102
+ end
103
+ end
104
+
105
+ context 'existing props' do
106
+ let(:status) { described_class.new(props: Nanoc::Int::Props.new(attributes: true)) }
107
+
108
+ it 'updates props' do
109
+ expect(subject.props.active).to eql(Set.new([:raw_content, :attributes, :compiled_content]))
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,125 @@
1
+ describe Nanoc::Int::Pattern do
2
+ describe '.from' do
3
+ it 'converts from string' do
4
+ pattern = described_class.from('/foo/x[ab]z/bar.*')
5
+ expect(pattern.match?('/foo/xaz/bar.html')).to eql(true)
6
+ expect(pattern.match?('/foo/xyz/bar.html')).to eql(false)
7
+ end
8
+
9
+ it 'converts from regex' do
10
+ pattern = described_class.from(%r{\A/foo/x[ab]z/bar\..*\z})
11
+ expect(pattern.match?('/foo/xaz/bar.html')).to eql(true)
12
+ expect(pattern.match?('/foo/xyz/bar.html')).to eql(false)
13
+ end
14
+
15
+ it 'converts from pattern' do
16
+ pattern = described_class.from('/foo/x[ab]z/bar.*')
17
+ pattern = described_class.from(pattern)
18
+ expect(pattern.match?('/foo/xaz/bar.html')).to eql(true)
19
+ expect(pattern.match?('/foo/xyz/bar.html')).to eql(false)
20
+ end
21
+
22
+ it 'errors on other inputs' do
23
+ expect { described_class.from(123) }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it 'errors with a proper error message on other inputs' do
27
+ expect { described_class.from(nil) }
28
+ .to raise_error(ArgumentError, 'Do not know how to convert `nil` into a Nanoc::Pattern')
29
+ end
30
+ end
31
+
32
+ describe '#initialize' do
33
+ it 'errors' do
34
+ expect { described_class.new('/stuff') }
35
+ .to raise_error(NotImplementedError)
36
+ end
37
+ end
38
+
39
+ describe '#match?' do
40
+ it 'errors' do
41
+ expect { described_class.allocate.match?('/foo.md') }
42
+ .to raise_error(NotImplementedError)
43
+ end
44
+ end
45
+
46
+ describe '#captures' do
47
+ it 'errors' do
48
+ expect { described_class.allocate.captures('/foo.md') }
49
+ .to raise_error(NotImplementedError)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe Nanoc::Int::RegexpPattern do
55
+ let(:pattern) { described_class.new(/the answer is (\d+)/) }
56
+
57
+ describe '#match?' do
58
+ it 'matches' do
59
+ expect(pattern.match?('the answer is 42')).to eql(true)
60
+ expect(pattern.match?('the answer is donkey')).to eql(false)
61
+ end
62
+ end
63
+
64
+ describe '#captures' do
65
+ it 'returns nil if it does not match' do
66
+ expect(pattern.captures('the answer is donkey')).to be_nil
67
+ end
68
+
69
+ it 'returns array if it matches' do
70
+ expect(pattern.captures('the answer is 42')).to eql(['42'])
71
+ end
72
+ end
73
+
74
+ describe '#to_s' do
75
+ subject { pattern.to_s }
76
+
77
+ it 'returns the regex' do
78
+ expect(subject).to eq('(?-mix:the answer is (\d+))')
79
+ end
80
+ end
81
+ end
82
+
83
+ describe Nanoc::Int::StringPattern do
84
+ describe '#match?' do
85
+ it 'matches simple strings' do
86
+ pattern = described_class.new('d*key')
87
+
88
+ expect(pattern.match?('donkey')).to eql(true)
89
+ expect(pattern.match?('giraffe')).to eql(false)
90
+ end
91
+
92
+ it 'matches with pathname option' do
93
+ pattern = described_class.new('/foo/*/bar/**/*.animal')
94
+
95
+ expect(pattern.match?('/foo/x/bar/a/b/donkey.animal')).to eql(true)
96
+ expect(pattern.match?('/foo/x/bar/donkey.animal')).to eql(true)
97
+ expect(pattern.match?('/foo/x/railroad/donkey.animal')).to eql(false)
98
+ end
99
+
100
+ it 'matches with extglob option' do
101
+ pattern = described_class.new('{b,gl}oat')
102
+
103
+ expect(pattern.match?('boat')).to eql(true)
104
+ expect(pattern.match?('gloat')).to eql(true)
105
+ expect(pattern.match?('stoat')).to eql(false)
106
+ end
107
+ end
108
+
109
+ describe '#captures' do
110
+ it 'returns nil' do
111
+ pattern = described_class.new('d*key')
112
+ expect(pattern.captures('donkey')).to be_nil
113
+ end
114
+ end
115
+
116
+ describe '#to_s' do
117
+ let(:pattern) { described_class.new('/foo/*/bar/**/*.animal') }
118
+
119
+ subject { pattern.to_s }
120
+
121
+ it 'returns the regex' do
122
+ expect(subject).to eq('/foo/*/bar/**/*.animal')
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,9 @@
1
+ describe Nanoc::Int::ProcessingAction do
2
+ let(:action) { described_class.new }
3
+
4
+ it 'is abstract' do
5
+ expect { action.serialize }.to raise_error(NotImplementedError)
6
+ expect { action.to_s }.to raise_error(NotImplementedError)
7
+ expect { action.inspect }.to raise_error(NotImplementedError)
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ describe Nanoc::Int::ProcessingActions::Filter do
2
+ let(:action) { described_class.new(:foo, awesome: true) }
3
+
4
+ describe '#serialize' do
5
+ subject { action.serialize }
6
+ it { is_expected.to eql([:filter, :foo, 'sJYzLjHGo1e4ytuDfnOLkqrt9QE=']) }
7
+ end
8
+
9
+ describe '#to_s' do
10
+ subject { action.to_s }
11
+ it { is_expected.to eql('filter :foo, {:awesome=>true}') }
12
+ end
13
+
14
+ describe '#inspect' do
15
+ subject { action.inspect }
16
+ it { is_expected.to eql('<Nanoc::Int::ProcessingActions::Filter :foo, "sJYzLjHGo1e4ytuDfnOLkqrt9QE=">') }
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ describe Nanoc::Int::ProcessingActions::Layout do
2
+ let(:action) { described_class.new('/foo.erb', awesome: true) }
3
+
4
+ describe '#serialize' do
5
+ subject { action.serialize }
6
+ it { is_expected.to eql([:layout, '/foo.erb', 'sJYzLjHGo1e4ytuDfnOLkqrt9QE=']) }
7
+ end
8
+
9
+ describe '#to_s' do
10
+ subject { action.to_s }
11
+ it { is_expected.to eql('layout "/foo.erb", {:awesome=>true}') }
12
+ end
13
+
14
+ describe '#inspect' do
15
+ subject { action.inspect }
16
+ it { is_expected.to eql('<Nanoc::Int::ProcessingActions::Layout "/foo.erb", "sJYzLjHGo1e4ytuDfnOLkqrt9QE=">') }
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ describe Nanoc::Int::ProcessingActions::Snapshot do
2
+ let(:action) { described_class.new(:before_layout, '/foo.md') }
3
+
4
+ describe '#serialize' do
5
+ subject { action.serialize }
6
+ it { is_expected.to eql([:snapshot, :before_layout, true, '/foo.md']) }
7
+ end
8
+
9
+ describe '#to_s' do
10
+ subject { action.to_s }
11
+ it { is_expected.to eql('snapshot :before_layout, path: "/foo.md"') }
12
+ end
13
+
14
+ describe '#inspect' do
15
+ subject { action.inspect }
16
+ it { is_expected.to eql('<Nanoc::Int::ProcessingActions::Snapshot :before_layout, true, "/foo.md">') }
17
+ end
18
+
19
+ describe '#copy' do
20
+ context 'without path' do
21
+ subject { action.copy }
22
+ its(:snapshot_name) { is_expected.to eql(:before_layout) }
23
+ its(:path) { is_expected.to eql('/foo.md') }
24
+ end
25
+
26
+ context 'with path' do
27
+ subject { action.copy(path: '/donkey.md') }
28
+ its(:snapshot_name) { is_expected.to eql(:before_layout) }
29
+ its(:path) { is_expected.to eql('/donkey.md') }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,195 @@
1
+ describe Nanoc::Int::Props do
2
+ let(:props) { described_class.new }
3
+
4
+ let(:props_all) do
5
+ described_class.new(raw_content: true, attributes: true, compiled_content: true, path: true)
6
+ end
7
+
8
+ describe '#inspect' do
9
+ subject { props.inspect }
10
+
11
+ context 'nothing active' do
12
+ it { is_expected.to eql('Props(____)') }
13
+ end
14
+
15
+ context 'attributes active' do
16
+ let(:props) { described_class.new(attributes: true) }
17
+ it { is_expected.to eql('Props(_a__)') }
18
+ end
19
+
20
+ context 'attributes and compiled_content active' do
21
+ let(:props) { described_class.new(attributes: true, compiled_content: true) }
22
+ it { is_expected.to eql('Props(_ac_)') }
23
+ end
24
+
25
+ context 'compiled_content active' do
26
+ let(:props) { described_class.new(compiled_content: true) }
27
+ it { is_expected.to eql('Props(__c_)') }
28
+ end
29
+ end
30
+
31
+ describe '#raw_content?' do
32
+ # …
33
+ end
34
+
35
+ describe '#attributes?' do
36
+ subject { props.attributes? }
37
+
38
+ context 'nothing active' do
39
+ it { is_expected.not_to be }
40
+ end
41
+
42
+ context 'attributes active' do
43
+ let(:props) { described_class.new(attributes: true) }
44
+ it { is_expected.to be }
45
+ end
46
+
47
+ context 'attributes and compiled_content active' do
48
+ let(:props) { described_class.new(attributes: true, compiled_content: true) }
49
+ it { is_expected.to be }
50
+ end
51
+
52
+ context 'compiled_content active' do
53
+ let(:props) { described_class.new(compiled_content: true) }
54
+ it { is_expected.not_to be }
55
+ end
56
+
57
+ context 'all active' do
58
+ let(:props) { described_class.new(raw_content: true, attributes: true, compiled_content: true, path: true) }
59
+ it { is_expected.to be }
60
+ end
61
+ end
62
+
63
+ describe '#compiled_content?' do
64
+ # …
65
+ end
66
+
67
+ describe '#path?' do
68
+ # …
69
+ end
70
+
71
+ describe '#merge' do
72
+ subject { props.merge(other_props).active }
73
+
74
+ context 'nothing + nothing' do
75
+ let(:props) { described_class.new }
76
+ let(:other_props) { described_class.new }
77
+
78
+ it { is_expected.to eql(Set.new) }
79
+ end
80
+
81
+ context 'nothing + some' do
82
+ let(:props) { described_class.new }
83
+ let(:other_props) { described_class.new(raw_content: true) }
84
+
85
+ it { is_expected.to eql(Set.new([:raw_content])) }
86
+ end
87
+
88
+ context 'nothing + all' do
89
+ let(:props) { described_class.new }
90
+ let(:other_props) { props_all }
91
+
92
+ it { is_expected.to eql(Set.new([:raw_content, :attributes, :compiled_content, :path])) }
93
+ end
94
+
95
+ context 'some + nothing' do
96
+ let(:props) { described_class.new(compiled_content: true) }
97
+ let(:other_props) { described_class.new }
98
+
99
+ it { is_expected.to eql(Set.new([:compiled_content])) }
100
+ end
101
+
102
+ context 'some + others' do
103
+ let(:props) { described_class.new(compiled_content: true) }
104
+ let(:other_props) { described_class.new(raw_content: true) }
105
+
106
+ it { is_expected.to eql(Set.new([:raw_content, :compiled_content])) }
107
+ end
108
+
109
+ context 'some + all' do
110
+ let(:props) { described_class.new(compiled_content: true) }
111
+ let(:other_props) { props_all }
112
+
113
+ it { is_expected.to eql(Set.new([:raw_content, :attributes, :compiled_content, :path])) }
114
+ end
115
+
116
+ context 'all + nothing' do
117
+ let(:props) { props_all }
118
+ let(:other_props) { described_class.new }
119
+
120
+ it { is_expected.to eql(Set.new([:raw_content, :attributes, :compiled_content, :path])) }
121
+ end
122
+
123
+ context 'some + all' do
124
+ let(:props) { props_all }
125
+ let(:other_props) { described_class.new(compiled_content: true) }
126
+
127
+ it { is_expected.to eql(Set.new([:raw_content, :attributes, :compiled_content, :path])) }
128
+ end
129
+
130
+ context 'all + all' do
131
+ let(:props) { props_all }
132
+ let(:other_props) { props_all }
133
+
134
+ it { is_expected.to eql(Set.new([:raw_content, :attributes, :compiled_content, :path])) }
135
+ end
136
+ end
137
+
138
+ describe '#active' do
139
+ subject { props.active }
140
+
141
+ context 'nothing active' do
142
+ let(:props) { described_class.new }
143
+ it { is_expected.to eql(Set.new) }
144
+ end
145
+
146
+ context 'raw_content active' do
147
+ let(:props) { described_class.new(raw_content: true) }
148
+ it { is_expected.to eql(Set.new([:raw_content])) }
149
+ end
150
+
151
+ context 'attributes active' do
152
+ let(:props) { described_class.new(attributes: true) }
153
+ it { is_expected.to eql(Set.new([:attributes])) }
154
+ end
155
+
156
+ context 'compiled_content active' do
157
+ let(:props) { described_class.new(compiled_content: true) }
158
+ it { is_expected.to eql(Set.new([:compiled_content])) }
159
+ end
160
+
161
+ context 'path active' do
162
+ let(:props) { described_class.new(path: true) }
163
+ it { is_expected.to eql(Set.new([:path])) }
164
+ end
165
+
166
+ context 'attributes and compiled_content active' do
167
+ let(:props) { described_class.new(attributes: true, compiled_content: true) }
168
+ it { is_expected.to eql(Set.new([:attributes, :compiled_content])) }
169
+ end
170
+
171
+ context 'all active' do
172
+ let(:props) { described_class.new(raw_content: true, attributes: true, compiled_content: true, path: true) }
173
+ it { is_expected.to eql(Set.new([:raw_content, :attributes, :compiled_content, :path])) }
174
+ end
175
+ end
176
+
177
+ describe '#to_h' do
178
+ subject { props.to_h }
179
+
180
+ context 'nothing' do
181
+ let(:props) { described_class.new }
182
+ it { is_expected.to eql(raw_content: false, attributes: false, compiled_content: false, path: false) }
183
+ end
184
+
185
+ context 'some' do
186
+ let(:props) { described_class.new(attributes: true, compiled_content: true) }
187
+ it { is_expected.to eql(raw_content: false, attributes: true, compiled_content: true, path: false) }
188
+ end
189
+
190
+ context 'all' do
191
+ let(:props) { props_all }
192
+ it { is_expected.to eql(raw_content: true, attributes: true, compiled_content: true, path: true) }
193
+ end
194
+ end
195
+ end