Skip to content
Permalink
Browse files

Remove final arg from RuleMemory#add_snapshot

  • Loading branch information...
ddfreyne committed Dec 25, 2016
1 parent 6a0b927 commit ef5cfd03e162e767ccc96e104c6e9771d9aa5141
@@ -30,10 +30,10 @@ def add_layout(layout_identifier, params)
self
end

contract Symbol, C::Bool, C::Maybe[String] => self
def add_snapshot(snapshot_name, final, path)
will_add_snapshot(snapshot_name) if final
@actions << Nanoc::Int::ProcessingActions::Snapshot.new(snapshot_name, final, path)
contract Symbol, C::Maybe[String] => self
def add_snapshot(snapshot_name, path)
will_add_snapshot(snapshot_name)
@actions << Nanoc::Int::ProcessingActions::Snapshot.new(snapshot_name, true, path)
self
end

@@ -17,7 +17,7 @@ def layout(layout_identifier, extra_filter_args = {})
end

unless @rule_memory.any_layouts?
@rule_memory.add_snapshot(:pre, true, nil)
@rule_memory.add_snapshot(:pre, nil)
end

@rule_memory.add_layout(layout_identifier, extra_filter_args)
@@ -26,7 +26,7 @@ def layout(layout_identifier, extra_filter_args = {})
Pathlike = C::Maybe[C::Or[String, Nanoc::Identifier]]
contract Symbol, C::KeywordArgs[path: C::Optional[Pathlike]] => nil
def snapshot(snapshot_name, path: nil)
@rule_memory.add_snapshot(snapshot_name, true, path && path.to_s)
@rule_memory.add_snapshot(snapshot_name, path && path.to_s)
nil
end
end
@@ -60,33 +60,23 @@
describe '#add_snapshot' do
context 'snapshot does not yet exist' do
example do
rule_memory.add_snapshot(:before_layout, false, '/foo.md')
rule_memory.add_snapshot(:before_layout, '/foo.md')

expect(rule_memory.size).to eql(1)
expect(rule_memory[0]).to be_a(Nanoc::Int::ProcessingActions::Snapshot)
expect(rule_memory[0].snapshot_name).to eql(:before_layout)
expect(rule_memory[0].path).to eql('/foo.md')
expect(rule_memory[0]).not_to be_final
expect(rule_memory[0]).to be_final
end
end

context 'non-final snapshot already exist' do
context 'snapshot already exist' do
before do
rule_memory.add_snapshot(:before_layout, false, '/bar.md')
end

it 'does not raise' do
rule_memory.add_snapshot(:before_layout, true, '/foo.md')
end
end

context 'final snapshot already exist' do
before do
rule_memory.add_snapshot(:before_layout, true, '/bar.md')
rule_memory.add_snapshot(:before_layout, '/bar.md')
end

it 'raises' do
expect { rule_memory.add_snapshot(:before_layout, true, '/foo.md') }
expect { rule_memory.add_snapshot(:before_layout, '/foo.md') }
.to raise_error(Nanoc::Int::Errors::CannotCreateMultipleSnapshotsWithSameName)
end
end
@@ -95,7 +85,7 @@
describe '#each' do
before do
rule_memory.add_filter(:erb, { awesomeness: 'high' })
rule_memory.add_snapshot(:bar, true, '/foo.md')
rule_memory.add_snapshot(:bar, '/foo.md')
rule_memory.add_layout('/default.erb', { somelayoutparam: 'yes' })
end

@@ -109,7 +99,7 @@
describe '#map' do
before do
rule_memory.add_filter(:erb, { awesomeness: 'high' })
rule_memory.add_snapshot(:bar, true, '/foo.md')
rule_memory.add_snapshot(:bar, '/foo.md')
rule_memory.add_layout('/default.erb', { somelayoutparam: 'yes' })
end

@@ -125,7 +115,7 @@

before do
rule_memory.add_filter(:erb, { awesomeness: 'high' })
rule_memory.add_snapshot(:bar, true, '/foo.md')
rule_memory.add_snapshot(:bar, '/foo.md')
rule_memory.add_layout('/default.erb', { somelayoutparam: 'yes' })
end

@@ -234,7 +234,7 @@
let(:new_memory_for_other_item_rep) do
Nanoc::Int::RuleMemory.new(other_item_rep).tap do |mem|
mem.add_filter(:erb, {})
mem.add_snapshot(:donkey, true, '/giraffe.txt')
mem.add_snapshot(:donkey, '/giraffe.txt')
end
end

@@ -267,7 +267,7 @@
let(:new_memory_for_other_item_rep) do
Nanoc::Int::RuleMemory.new(other_item_rep).tap do |mem|
mem.add_filter(:erb, {})
mem.add_snapshot(:donkey, true, '/giraffe.txt')
mem.add_snapshot(:donkey, '/giraffe.txt')
end
end

@@ -294,7 +294,7 @@
let(:new_memory_for_other_item_rep) do
Nanoc::Int::RuleMemory.new(other_item_rep).tap do |mem|
mem.add_filter(:erb, {})
mem.add_snapshot(:donkey, true, '/giraffe.txt')
mem.add_snapshot(:donkey, '/giraffe.txt')
end
end

@@ -263,7 +263,7 @@
context 'old mem does not exist' do
let(:new_mem) do
Nanoc::Int::RuleMemory.new(item_rep).tap do |mem|
mem.add_snapshot(:donkey, true, '/foo.md')
mem.add_snapshot(:donkey, '/foo.md')
mem.add_filter(:asdf, {})
end
end
@@ -275,7 +275,7 @@
let(:old_mem) do
Nanoc::Int::RuleMemory.new(item_rep).tap do |mem|
mem.add_filter(:erb, {})
mem.add_snapshot(:donkey, true, '/foo.md')
mem.add_snapshot(:donkey, '/foo.md')
end
end

@@ -286,7 +286,7 @@
context 'paths in memory are the same' do
let(:new_mem) do
Nanoc::Int::RuleMemory.new(item_rep).tap do |mem|
mem.add_snapshot(:donkey, true, '/foo.md')
mem.add_snapshot(:donkey, '/foo.md')
mem.add_filter(:asdf, {})
end
end
@@ -298,9 +298,9 @@
let(:new_mem) do
Nanoc::Int::RuleMemory.new(item_rep).tap do |mem|
mem.add_filter(:erb, {})
mem.add_snapshot(:donkey, true, '/foo.md')
mem.add_snapshot(:donkey, '/foo.md')
mem.add_filter(:donkey, {})
mem.add_snapshot(:giraffe, true, '/bar.md')
mem.add_snapshot(:giraffe, '/bar.md')
end
end

0 comments on commit ef5cfd0

Please sign in to comment.
You can’t perform that action at this time.