nanoc 4.7.7 → 4.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -5
  3. data/NEWS.md +12 -0
  4. data/lib/nanoc/base/entities.rb +1 -0
  5. data/lib/nanoc/base/entities/action_sequence.rb +8 -36
  6. data/lib/nanoc/base/entities/checksum_collection.rb +31 -0
  7. data/lib/nanoc/base/entities/directed_graph.rb +35 -11
  8. data/lib/nanoc/base/errors.rb +3 -1
  9. data/lib/nanoc/base/repos/checksum_store.rb +1 -0
  10. data/lib/nanoc/base/services.rb +1 -0
  11. data/lib/nanoc/base/services/action_sequence_builder.rb +45 -0
  12. data/lib/nanoc/base/services/compiler.rb +34 -14
  13. data/lib/nanoc/base/services/compiler/stages.rb +1 -0
  14. data/lib/nanoc/base/services/compiler/stages/calculate_checksums.rb +31 -0
  15. data/lib/nanoc/base/services/compiler/stages/store_pre_compilation_state.rb +6 -13
  16. data/lib/nanoc/base/services/outdatedness_checker.rb +4 -2
  17. data/lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb +1 -1
  18. data/lib/nanoc/base/services/outdatedness_rules/code_snippets_modified.rb +1 -1
  19. data/lib/nanoc/base/services/outdatedness_rules/configuration_modified.rb +1 -1
  20. data/lib/nanoc/base/services/outdatedness_rules/content_modified.rb +1 -1
  21. data/lib/nanoc/cli/cleaning_stream.rb +1 -1
  22. data/lib/nanoc/cli/commands/show-data.rb +1 -0
  23. data/lib/nanoc/rule_dsl/action_sequence_calculator.rb +7 -14
  24. data/lib/nanoc/rule_dsl/recording_executor.rb +40 -7
  25. data/lib/nanoc/version.rb +1 -1
  26. data/spec/nanoc/base/compiler_spec.rb +5 -5
  27. data/spec/nanoc/base/directed_graph_spec.rb +12 -0
  28. data/spec/nanoc/base/entities/action_sequence_spec.rb +132 -79
  29. data/spec/nanoc/base/errors/dependency_cycle_spec.rb +4 -4
  30. data/spec/nanoc/base/services/compiler/stages/calculate_checksums_spec.rb +69 -0
  31. data/spec/nanoc/base/services/executor_spec.rb +2 -2
  32. data/spec/nanoc/base/services/item_rep_router_spec.rb +4 -4
  33. data/spec/nanoc/base/services/outdatedness_checker_spec.rb +40 -24
  34. data/spec/nanoc/base/services/outdatedness_rules_spec.rb +27 -15
  35. data/spec/nanoc/cli/commands/show_data_spec.rb +2 -0
  36. data/spec/nanoc/rule_dsl/action_sequence_calculator_spec.rb +15 -13
  37. data/spec/nanoc/rule_dsl/recording_executor_spec.rb +4 -3
  38. data/test/cli/test_cleaning_stream.rb +8 -0
  39. metadata +6 -2
@@ -2,32 +2,25 @@ module Nanoc::Int::Compiler::Stages
2
2
  class StorePreCompilationState
3
3
  include Nanoc::Int::ContractsSupport
4
4
 
5
- def initialize(reps:, layouts:, items:, code_snippets:, config:, checksum_store:, action_sequence_store:, action_sequences:)
5
+ def initialize(reps:, layouts:, checksum_store:, action_sequence_store:, action_sequences:)
6
6
  @reps = reps
7
7
  @layouts = layouts
8
- @items = items
9
- @code_snippets = code_snippets
10
- @config = config
11
8
  @checksum_store = checksum_store
12
9
  @action_sequence_store = action_sequence_store
13
10
  @action_sequences = action_sequences
14
11
  end
15
12
 
16
- contract C::None => C::Any
17
- def run
13
+ contract Nanoc::Int::ChecksumCollection => C::Any
14
+ def run(checksums)
18
15
  # Calculate action sequence
19
16
  (@reps.to_a + @layouts.to_a).each do |obj|
20
17
  @action_sequence_store[obj] = @action_sequences[obj].serialize
21
18
  end
19
+ @action_sequence_store.store
22
20
 
23
- # Calculate checksums
24
- objects_to_checksum =
25
- @items.to_a + @layouts.to_a + @code_snippets + [@config]
26
- objects_to_checksum.each { |obj| @checksum_store.add(obj) }
27
-
28
- # Store
21
+ # Set checksums
22
+ @checksum_store.checksums = checksums.to_h
29
23
  @checksum_store.store
30
- @action_sequence_store.store
31
24
  end
32
25
  end
33
26
  end
@@ -78,6 +78,7 @@ module Nanoc::Int
78
78
  include Nanoc::Int::ContractsSupport
79
79
 
80
80
  attr_reader :checksum_store
81
+ attr_reader :checksums
81
82
  attr_reader :dependency_store
82
83
  attr_reader :action_sequence_store
83
84
  attr_reader :action_sequences
@@ -88,10 +89,11 @@ module Nanoc::Int
88
89
  C_OBJ = C::Or[Nanoc::Int::Item, Nanoc::Int::ItemRep, Nanoc::Int::Layout]
89
90
  C_ACTION_SEQUENCES = C::HashOf[C_OBJ => Nanoc::Int::ActionSequence]
90
91
 
91
- contract C::KeywordArgs[site: Nanoc::Int::Site, checksum_store: Nanoc::Int::ChecksumStore, dependency_store: Nanoc::Int::DependencyStore, action_sequence_store: Nanoc::Int::ActionSequenceStore, action_sequences: C_ACTION_SEQUENCES, reps: Nanoc::Int::ItemRepRepo] => C::Any
92
- def initialize(site:, checksum_store:, dependency_store:, action_sequence_store:, action_sequences:, reps:)
92
+ contract C::KeywordArgs[site: Nanoc::Int::Site, checksum_store: Nanoc::Int::ChecksumStore, checksums: Nanoc::Int::ChecksumCollection, dependency_store: Nanoc::Int::DependencyStore, action_sequence_store: Nanoc::Int::ActionSequenceStore, action_sequences: C_ACTION_SEQUENCES, reps: Nanoc::Int::ItemRepRepo] => C::Any
93
+ def initialize(site:, checksum_store:, checksums:, dependency_store:, action_sequence_store:, action_sequences:, reps:)
93
94
  @site = site
94
95
  @checksum_store = checksum_store
96
+ @checksums = checksums
95
97
  @dependency_store = dependency_store
96
98
  @action_sequence_store = action_sequence_store
97
99
  @action_sequences = action_sequences
@@ -17,7 +17,7 @@ module Nanoc::Int::OutdatednessRules
17
17
  return Nanoc::Int::OutdatednessReasons::AttributesModified.new(true)
18
18
  end
19
19
 
20
- new_checksums = Nanoc::Int::Checksummer.calc_for_each_attribute_of(obj)
20
+ new_checksums = outdatedness_checker.checksums.attributes_checksum_for(obj)
21
21
 
22
22
  attributes = Set.new(old_checksums.keys) + Set.new(new_checksums.keys)
23
23
  changed_attributes = attributes.reject { |a| old_checksums[a] == new_checksums[a] }
@@ -17,7 +17,7 @@ module Nanoc::Int::OutdatednessRules
17
17
  memoized def any_snippets_modified?(outdatedness_checker)
18
18
  outdatedness_checker.site.code_snippets.any? do |cs|
19
19
  ch_old = outdatedness_checker.checksum_store[cs]
20
- ch_new = Nanoc::Int::Checksummer.calc(cs)
20
+ ch_new = outdatedness_checker.checksums.checksum_for(cs)
21
21
  ch_old != ch_new
22
22
  end
23
23
  end
@@ -15,7 +15,7 @@ module Nanoc::Int::OutdatednessRules
15
15
  memoized def config_modified?(outdatedness_checker)
16
16
  obj = outdatedness_checker.site.config
17
17
  ch_old = outdatedness_checker.checksum_store[obj]
18
- ch_new = Nanoc::Int::Checksummer.calc(obj)
18
+ ch_new = outdatedness_checker.checksums.checksum_for(obj)
19
19
  ch_old != ch_new
20
20
  end
21
21
  end
@@ -6,7 +6,7 @@ module Nanoc::Int::OutdatednessRules
6
6
  obj = obj.item if obj.is_a?(Nanoc::Int::ItemRep)
7
7
 
8
8
  ch_old = outdatedness_checker.checksum_store.content_checksum_for(obj)
9
- ch_new = Nanoc::Int::Checksummer.calc_for_content_of(obj)
9
+ ch_new = outdatedness_checker.checksums.content_checksum_for(obj)
10
10
  if ch_old != ch_new
11
11
  Nanoc::Int::OutdatednessReasons::ContentModified
12
12
  end
@@ -147,7 +147,7 @@ module Nanoc::CLI
147
147
  protected
148
148
 
149
149
  def _nanoc_clean(s)
150
- @stream_cleaners.reduce(s.to_s) { |acc, elem| elem.clean(acc) }
150
+ @stream_cleaners.reduce(s.to_s.scrub) { |acc, elem| elem.clean(acc) }
151
151
  end
152
152
 
153
153
  def _nanoc_swallow_broken_pipe_errors_while
@@ -144,6 +144,7 @@ module Nanoc::CLI::Commands
144
144
  end
145
145
 
146
146
  def print_outdatedness_reasons_for(obj, compiler)
147
+ compiler.calculate_checksums
147
148
  outdatedness_checker = compiler.create_outdatedness_checker
148
149
  reasons = outdatedness_checker.outdatedness_reasons_for(obj)
149
150
  if reasons.any?
@@ -58,8 +58,7 @@ module Nanoc::RuleDSL
58
58
  dependency_tracker = Nanoc::Int::DependencyTracker::Null.new
59
59
  view_context = @site.compiler.compilation_context.create_view_context(dependency_tracker)
60
60
 
61
- action_sequence = Nanoc::Int::ActionSequence.new(rep)
62
- executor = Nanoc::RuleDSL::RecordingExecutor.new(action_sequence)
61
+ executor = Nanoc::RuleDSL::RecordingExecutor.new(rep)
63
62
  rule = @rules_collection.compilation_rule_for(rep)
64
63
 
65
64
  unless rule
@@ -68,17 +67,11 @@ module Nanoc::RuleDSL
68
67
 
69
68
  executor.snapshot(:raw)
70
69
  rule.apply_to(rep, executor: executor, site: @site, view_context: view_context)
71
- if action_sequence.any_layouts?
72
- executor.snapshot(:post)
73
- end
74
- unless action_sequence.snapshot_actions.any? { |sa| sa.snapshot_names.include?(:last) }
75
- executor.snapshot(:last)
76
- end
77
- unless action_sequence.snapshot_actions.any? { |sa| sa.snapshot_names.include?(:pre) }
78
- executor.snapshot(:pre)
79
- end
70
+ executor.snapshot(:post) if executor.any_layouts?
71
+ executor.snapshot(:last) unless executor.last_snapshot?
72
+ executor.snapshot(:pre) unless executor.pre_snapshot?
80
73
 
81
- copy_paths_from_routing_rules(compact_snapshots(action_sequence), rep: rep)
74
+ copy_paths_from_routing_rules(compact_snapshots(executor.action_sequence), rep: rep)
82
75
  end
83
76
 
84
77
  # @param [Nanoc::Int::Layout] layout
@@ -91,8 +84,8 @@ module Nanoc::RuleDSL
91
84
  raise NoActionSequenceForLayoutException.new(layout)
92
85
  end
93
86
 
94
- Nanoc::Int::ActionSequence.new(layout).tap do |rm|
95
- rm.add_filter(res[0], res[1])
87
+ Nanoc::Int::ActionSequence.build(layout) do |b|
88
+ b.add_filter(res[0], res[1])
96
89
  end
97
90
  end
98
91
 
@@ -3,12 +3,17 @@ module Nanoc
3
3
  class RecordingExecutor
4
4
  include Nanoc::Int::ContractsSupport
5
5
 
6
- def initialize(action_sequence)
7
- @action_sequence = action_sequence
6
+ contract Nanoc::Int::ItemRep => C::Any
7
+ def initialize(rep)
8
+ @action_sequence_builder = Nanoc::Int::ActionSequenceBuilder.new(rep)
9
+
10
+ @any_layouts = false
11
+ @last_snapshot = false
12
+ @pre_snapshot = false
8
13
  end
9
14
 
10
15
  def filter(filter_name, filter_args = {})
11
- @action_sequence.add_filter(filter_name, filter_args)
16
+ @action_sequence_builder.add_filter(filter_name, filter_args)
12
17
  end
13
18
 
14
19
  def layout(layout_identifier, extra_filter_args = {})
@@ -16,19 +21,47 @@ module Nanoc
16
21
  raise ArgumentError.new('The layout passed to #layout must be a string')
17
22
  end
18
23
 
19
- unless @action_sequence.any_layouts?
20
- @action_sequence.add_snapshot(:pre, nil)
24
+ unless any_layouts?
25
+ @pre_snapshot = true
26
+ @action_sequence_builder.add_snapshot(:pre, nil)
21
27
  end
22
28
 
23
- @action_sequence.add_layout(layout_identifier, extra_filter_args)
29
+ @action_sequence_builder.add_layout(layout_identifier, extra_filter_args)
30
+ @any_layouts = true
24
31
  end
25
32
 
26
33
  Pathlike = C::Maybe[C::Or[String, Nanoc::Identifier]]
27
34
  contract Symbol, C::KeywordArgs[path: C::Optional[Pathlike]] => nil
28
35
  def snapshot(snapshot_name, path: nil)
29
- @action_sequence.add_snapshot(snapshot_name, path && path.to_s)
36
+ @action_sequence_builder.add_snapshot(snapshot_name, path && path.to_s)
37
+ case snapshot_name
38
+ when :last
39
+ @last_snapshot = true
40
+ when :pre
41
+ @pre_snapshot = true
42
+ end
30
43
  nil
31
44
  end
45
+
46
+ contract C::None => Nanoc::Int::ActionSequence
47
+ def action_sequence
48
+ @action_sequence_builder.action_sequence
49
+ end
50
+
51
+ contract C::None => C::Bool
52
+ def any_layouts?
53
+ @any_layouts
54
+ end
55
+
56
+ contract C::None => C::Bool
57
+ def last_snapshot?
58
+ @last_snapshot
59
+ end
60
+
61
+ contract C::None => C::Bool
62
+ def pre_snapshot?
63
+ @pre_snapshot
64
+ end
32
65
  end
33
66
  end
34
67
  end
data/lib/nanoc/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Nanoc
2
2
  # The current Nanoc version.
3
- VERSION = '4.7.7'.freeze
3
+ VERSION = '4.7.8'.freeze
4
4
  end
@@ -58,6 +58,10 @@ describe Nanoc::Int::Compiler do
58
58
  Nanoc::Int::ActionSequence.new(nil, actions: actions)
59
59
  end
60
60
 
61
+ let(:action_sequences) do
62
+ { rep => memory, other_rep => memory }
63
+ end
64
+
61
65
  before do
62
66
  reps << rep
63
67
  reps << other_rep
@@ -66,15 +70,11 @@ describe Nanoc::Int::Compiler do
66
70
  rep.snapshot_defs << Nanoc::Int::SnapshotDef.new(:last, binary: false)
67
71
  end
68
72
 
69
- # FIXME: eww
70
- action_sequences = { rep => memory, other_rep => memory }
71
- compiler.instance_variable_set(:@action_sequences, action_sequences)
72
-
73
73
  allow(Nanoc::Int::NotificationCenter).to receive(:post)
74
74
  end
75
75
 
76
76
  describe '#compile_rep' do
77
- let(:stage) { compiler.send(:compile_reps_stage) }
77
+ let(:stage) { compiler.send(:compile_reps_stage, action_sequences) }
78
78
 
79
79
  subject { stage.send(:compile_rep, rep, is_outdated: is_outdated) }
80
80
 
@@ -27,6 +27,18 @@ describe Nanoc::Int::DirectedGraph do
27
27
  it { is_expected.to eq([2, 3]) }
28
28
  end
29
29
 
30
+ context 'one cycle with tail' do
31
+ before do
32
+ graph.add_edge(1, 2)
33
+ graph.add_edge(2, 20)
34
+ graph.add_edge(20, 21)
35
+ graph.add_edge(2, 3)
36
+ graph.add_edge(3, 1)
37
+ end
38
+
39
+ it { is_expected.to eq([1, 2, 3]) }
40
+ end
41
+
30
42
  context 'large cycle' do
31
43
  before do
32
44
  graph.add_edge(1, 2)
@@ -1,17 +1,26 @@
1
1
  describe Nanoc::Int::ActionSequence do
2
- let(:action_sequence) { described_class.new(rep) }
3
- let(:rep) { double(:rep) }
2
+ let(:action_sequence) { raise 'override me' }
3
+
4
+ let(:item) { Nanoc::Int::Item.new('foo', {}, '/foo.md') }
5
+ let(:rep) { Nanoc::Int::ItemRep.new(item, :default) }
4
6
 
5
7
  describe '#size' do
6
8
  subject { action_sequence.size }
7
9
 
8
10
  context 'no actions' do
11
+ let(:action_sequence) do
12
+ described_class.build(rep) do |b|
13
+ end
14
+ end
15
+
9
16
  it { is_expected.to eql(0) }
10
17
  end
11
18
 
12
19
  context 'some actions' do
13
- before do
14
- action_sequence.add_filter(:foo, {})
20
+ let(:action_sequence) do
21
+ described_class.build(rep) do |b|
22
+ b.add_filter(:foo, {})
23
+ end
15
24
  end
16
25
 
17
26
  it { is_expected.to eql(1) }
@@ -23,12 +32,19 @@ describe Nanoc::Int::ActionSequence do
23
32
  let(:index) { 0 }
24
33
 
25
34
  context 'no actions' do
35
+ let(:action_sequence) do
36
+ described_class.build(rep) do |b|
37
+ end
38
+ end
39
+
26
40
  it { is_expected.to be_nil }
27
41
  end
28
42
 
29
43
  context 'some actions' do
30
- before do
31
- action_sequence.add_filter(:foo, {})
44
+ let(:action_sequence) do
45
+ described_class.build(rep) do |b|
46
+ b.add_filter(:foo, {})
47
+ end
32
48
  end
33
49
 
34
50
  it { is_expected.to be_a(Nanoc::Int::ProcessingActions::Filter) }
@@ -36,9 +52,13 @@ describe Nanoc::Int::ActionSequence do
36
52
  end
37
53
 
38
54
  describe '#add_filter' do
39
- example do
40
- action_sequence.add_filter(:foo, donkey: 123)
55
+ let(:action_sequence) do
56
+ described_class.build(rep) do |b|
57
+ b.add_filter(:foo, donkey: 123)
58
+ end
59
+ end
41
60
 
61
+ example do
42
62
  expect(action_sequence.size).to eql(1)
43
63
  expect(action_sequence[0]).to be_a(Nanoc::Int::ProcessingActions::Filter)
44
64
  expect(action_sequence[0].filter_name).to eql(:foo)
@@ -47,9 +67,13 @@ describe Nanoc::Int::ActionSequence do
47
67
  end
48
68
 
49
69
  describe '#add_layout' do
50
- example do
51
- action_sequence.add_layout('/foo.*', donkey: 123)
70
+ let(:action_sequence) do
71
+ described_class.build(rep) do |b|
72
+ b.add_layout('/foo.*', donkey: 123)
73
+ end
74
+ end
52
75
 
76
+ example do
53
77
  expect(action_sequence.size).to eql(1)
54
78
  expect(action_sequence[0]).to be_a(Nanoc::Int::ProcessingActions::Layout)
55
79
  expect(action_sequence[0].layout_identifier).to eql('/foo.*')
@@ -59,9 +83,13 @@ describe Nanoc::Int::ActionSequence do
59
83
 
60
84
  describe '#add_snapshot' do
61
85
  context 'snapshot does not yet exist' do
62
- example do
63
- action_sequence.add_snapshot(:before_layout, '/foo.md')
86
+ let(:action_sequence) do
87
+ described_class.build(rep) do |b|
88
+ b.add_snapshot(:before_layout, '/foo.md')
89
+ end
90
+ end
64
91
 
92
+ example do
65
93
  expect(action_sequence.size).to eql(1)
66
94
  expect(action_sequence[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
67
95
  expect(action_sequence[0].snapshot_names).to eql([:before_layout])
@@ -70,22 +98,23 @@ describe Nanoc::Int::ActionSequence do
70
98
  end
71
99
 
72
100
  context 'snapshot already exist' do
73
- before do
74
- action_sequence.add_snapshot(:before_layout, '/bar.md')
75
- end
76
-
77
101
  it 'raises' do
78
- expect { action_sequence.add_snapshot(:before_layout, '/foo.md') }
79
- .to raise_error(Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName)
102
+ described_class.build(rep) do |b|
103
+ b.add_snapshot(:before_layout, '/bar.md')
104
+ expect { b.add_snapshot(:before_layout, '/foo.md') }
105
+ .to raise_error(Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName)
106
+ end
80
107
  end
81
108
  end
82
109
  end
83
110
 
84
111
  describe '#each' do
85
- before do
86
- action_sequence.add_filter(:erb, awesomeness: 'high')
87
- action_sequence.add_snapshot(:bar, '/foo.md')
88
- action_sequence.add_layout('/default.erb', somelayoutparam: 'yes')
112
+ let(:action_sequence) do
113
+ described_class.build(rep) do |b|
114
+ b.add_filter(:erb, awesomeness: 'high')
115
+ b.add_snapshot(:bar, '/foo.md')
116
+ b.add_layout('/default.erb', somelayoutparam: 'yes')
117
+ end
89
118
  end
90
119
 
91
120
  example do
@@ -96,10 +125,12 @@ describe Nanoc::Int::ActionSequence do
96
125
  end
97
126
 
98
127
  describe '#map' do
99
- before do
100
- action_sequence.add_filter(:erb, awesomeness: 'high')
101
- action_sequence.add_snapshot(:bar, '/foo.md')
102
- action_sequence.add_layout('/default.erb', somelayoutparam: 'yes')
128
+ let(:action_sequence) do
129
+ described_class.build(rep) do |b|
130
+ b.add_filter(:erb, awesomeness: 'high')
131
+ b.add_snapshot(:bar, '/foo.md')
132
+ b.add_layout('/default.erb', somelayoutparam: 'yes')
133
+ end
103
134
  end
104
135
 
105
136
  example do
@@ -112,10 +143,12 @@ describe Nanoc::Int::ActionSequence do
112
143
  describe '#serialize' do
113
144
  subject { action_sequence.serialize }
114
145
 
115
- before do
116
- action_sequence.add_filter(:erb, awesomeness: 'high')
117
- action_sequence.add_snapshot(:bar, '/foo.md')
118
- action_sequence.add_layout('/default.erb', somelayoutparam: 'yes')
146
+ let(:action_sequence) do
147
+ described_class.build(rep) do |b|
148
+ b.add_filter(:erb, awesomeness: 'high')
149
+ b.add_snapshot(:bar, '/foo.md')
150
+ b.add_layout('/default.erb', somelayoutparam: 'yes')
151
+ end
119
152
  end
120
153
 
121
154
  example do
@@ -130,8 +163,6 @@ describe Nanoc::Int::ActionSequence do
130
163
  end
131
164
 
132
165
  describe '#snapshots_defs' do
133
- subject { action_sequence.snapshots_defs }
134
-
135
166
  let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
136
167
  let(:rep) { Nanoc::Int::ItemRep.new(item, :default) }
137
168
 
@@ -164,42 +195,55 @@ describe Nanoc::Int::ActionSequence do
164
195
  end
165
196
 
166
197
  it 'has no snapshot defs by default' do
167
- expect(subject).to be_empty
198
+ action_sequence =
199
+ described_class.build(rep) do |b|
200
+ end
201
+
202
+ expect(action_sequence.snapshots_defs).to be_empty
168
203
  end
169
204
 
170
205
  context 'textual item' do
171
206
  let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
172
207
 
173
208
  it 'generates initial textual snapshot def' do
174
- action_sequence.add_snapshot(:giraffe, nil)
175
-
176
- expect(subject.size).to eq(1)
177
- expect(subject[0].name).to eq(:giraffe)
178
- expect(subject[0]).not_to be_binary
209
+ action_sequence =
210
+ described_class.build(rep) do |b|
211
+ b.add_snapshot(:giraffe, nil)
212
+ end
213
+
214
+ expect(action_sequence.snapshots_defs.size).to eq(1)
215
+ expect(action_sequence.snapshots_defs[0].name).to eq(:giraffe)
216
+ expect(action_sequence.snapshots_defs[0]).not_to be_binary
179
217
  end
180
218
 
181
219
  it 'generated follow-up textual snapshot def if previous filter is textual' do
182
- action_sequence.add_snapshot(:giraffe, nil)
183
- action_sequence.add_filter(:RuleMemSpec_filter_t2t, arguments: 'irrelevant')
184
- action_sequence.add_snapshot(:zebra, nil)
185
-
186
- expect(subject.size).to eq(2)
187
- expect(subject[0].name).to eq(:giraffe)
188
- expect(subject[0]).not_to be_binary
189
- expect(subject[1].name).to eq(:zebra)
190
- expect(subject[1]).not_to be_binary
220
+ action_sequence =
221
+ described_class.build(rep) do |b|
222
+ b.add_snapshot(:giraffe, nil)
223
+ b.add_filter(:RuleMemSpec_filter_t2t, arguments: 'irrelevant')
224
+ b.add_snapshot(:zebra, nil)
225
+ end
226
+
227
+ expect(action_sequence.snapshots_defs.size).to eq(2)
228
+ expect(action_sequence.snapshots_defs[0].name).to eq(:giraffe)
229
+ expect(action_sequence.snapshots_defs[0]).not_to be_binary
230
+ expect(action_sequence.snapshots_defs[1].name).to eq(:zebra)
231
+ expect(action_sequence.snapshots_defs[1]).not_to be_binary
191
232
  end
192
233
 
193
234
  it 'generated follow-up binary snapshot def if previous filter is text-to-bianry' do
194
- action_sequence.add_snapshot(:giraffe, nil)
195
- action_sequence.add_filter(:RuleMemSpec_filter_t2b, arguments: 'irrelevant')
196
- action_sequence.add_snapshot(:zebra, nil)
197
-
198
- expect(subject.size).to eq(2)
199
- expect(subject[0].name).to eq(:giraffe)
200
- expect(subject[0]).not_to be_binary
201
- expect(subject[1].name).to eq(:zebra)
202
- expect(subject[1]).to be_binary
235
+ action_sequence =
236
+ described_class.build(rep) do |b|
237
+ b.add_snapshot(:giraffe, nil)
238
+ b.add_filter(:RuleMemSpec_filter_t2b, arguments: 'irrelevant')
239
+ b.add_snapshot(:zebra, nil)
240
+ end
241
+
242
+ expect(action_sequence.snapshots_defs.size).to eq(2)
243
+ expect(action_sequence.snapshots_defs[0].name).to eq(:giraffe)
244
+ expect(action_sequence.snapshots_defs[0]).not_to be_binary
245
+ expect(action_sequence.snapshots_defs[1].name).to eq(:zebra)
246
+ expect(action_sequence.snapshots_defs[1]).to be_binary
203
247
  end
204
248
  end
205
249
 
@@ -207,35 +251,44 @@ describe Nanoc::Int::ActionSequence do
207
251
  let(:item) { Nanoc::Int::Item.new(Nanoc::Int::BinaryContent.new('/asdf.dat'), {}, '/foo.md') }
208
252
 
209
253
  it 'generates initial binary snapshot def' do
210
- action_sequence.add_snapshot(:giraffe, nil)
211
-
212
- expect(subject.size).to eq(1)
213
- expect(subject[0].name).to eq(:giraffe)
214
- expect(subject[0]).to be_binary
254
+ action_sequence =
255
+ described_class.build(rep) do |b|
256
+ b.add_snapshot(:giraffe, nil)
257
+ end
258
+
259
+ expect(action_sequence.snapshots_defs.size).to eq(1)
260
+ expect(action_sequence.snapshots_defs[0].name).to eq(:giraffe)
261
+ expect(action_sequence.snapshots_defs[0]).to be_binary
215
262
  end
216
263
 
217
264
  it 'generated follow-up binary snapshot def if previous filter is binary' do
218
- action_sequence.add_snapshot(:giraffe, nil)
219
- action_sequence.add_filter(:RuleMemSpec_filter_b2b, arguments: 'irrelevant')
220
- action_sequence.add_snapshot(:zebra, nil)
221
-
222
- expect(subject.size).to eq(2)
223
- expect(subject[0].name).to eq(:giraffe)
224
- expect(subject[0]).to be_binary
225
- expect(subject[1].name).to eq(:zebra)
226
- expect(subject[1]).to be_binary
265
+ action_sequence =
266
+ described_class.build(rep) do |b|
267
+ b.add_snapshot(:giraffe, nil)
268
+ b.add_filter(:RuleMemSpec_filter_b2b, arguments: 'irrelevant')
269
+ b.add_snapshot(:zebra, nil)
270
+ end
271
+
272
+ expect(action_sequence.snapshots_defs.size).to eq(2)
273
+ expect(action_sequence.snapshots_defs[0].name).to eq(:giraffe)
274
+ expect(action_sequence.snapshots_defs[0]).to be_binary
275
+ expect(action_sequence.snapshots_defs[1].name).to eq(:zebra)
276
+ expect(action_sequence.snapshots_defs[1]).to be_binary
227
277
  end
228
278
 
229
279
  it 'generated follow-up textual snapshot def if previous filter is binary-to-text' do
230
- action_sequence.add_snapshot(:giraffe, nil)
231
- action_sequence.add_filter(:RuleMemSpec_filter_b2t, arguments: 'irrelevant')
232
- action_sequence.add_snapshot(:zebra, nil)
233
-
234
- expect(subject.size).to eq(2)
235
- expect(subject[0].name).to eq(:giraffe)
236
- expect(subject[0]).to be_binary
237
- expect(subject[1].name).to eq(:zebra)
238
- expect(subject[1]).not_to be_binary
280
+ action_sequence =
281
+ described_class.build(rep) do |b|
282
+ b.add_snapshot(:giraffe, nil)
283
+ b.add_filter(:RuleMemSpec_filter_b2t, arguments: 'irrelevant')
284
+ b.add_snapshot(:zebra, nil)
285
+ end
286
+
287
+ expect(action_sequence.snapshots_defs.size).to eq(2)
288
+ expect(action_sequence.snapshots_defs[0].name).to eq(:giraffe)
289
+ expect(action_sequence.snapshots_defs[0]).to be_binary
290
+ expect(action_sequence.snapshots_defs[1].name).to eq(:zebra)
291
+ expect(action_sequence.snapshots_defs[1]).not_to be_binary
239
292
  end
240
293
  end
241
294
  end