Refactoring specs, now with less leakage!
parent
578c3cb6a0
commit
a9d6ffda75
|
|
@ -24,7 +24,6 @@ describe Squib::Deck, '#save_pdf' do
|
||||||
num_cards = 9
|
num_cards = 9
|
||||||
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||||
mock_squib_logger(@old_logger) do
|
|
||||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||||
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(num_cards + 1).times
|
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(num_cards + 1).times
|
||||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||||
|
|
@ -42,13 +41,11 @@ describe Squib::Deck, '#save_pdf' do
|
||||||
|
|
||||||
deck.save_pdf(args)
|
deck.save_pdf(args)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it 'only does the three cards on a limited range' do
|
it 'only does the three cards on a limited range' do
|
||||||
num_cards = 9
|
num_cards = 9
|
||||||
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||||
mock_squib_logger(@old_logger) do
|
|
||||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||||
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(4).times
|
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(4).times
|
||||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||||
|
|
@ -59,7 +56,6 @@ describe Squib::Deck, '#save_pdf' do
|
||||||
|
|
||||||
deck.save_pdf(args)
|
deck.save_pdf(args)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,10 @@ describe Squib::InputHelpers do
|
||||||
|
|
||||||
context '#layoutify' do
|
context '#layoutify' do
|
||||||
it 'warns on the logger when the layout does not exist' do
|
it 'warns on the logger when the layout does not exist' do
|
||||||
mock_squib_logger(@old_logger) do
|
|
||||||
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
||||||
expect(Squib.logger).to receive(:debug)
|
expect(Squib.logger).to receive(:debug)
|
||||||
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
|
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it 'applies the layout in a normal situation' do
|
it 'applies the layout in a normal situation' do
|
||||||
expect(@deck.send(:layoutify, {layout: :blah})).to \
|
expect(@deck.send(:layoutify, {layout: :blah})).to \
|
||||||
|
|
@ -88,13 +86,11 @@ describe Squib::InputHelpers do
|
||||||
opts = {dir: 'tocreate'}
|
opts = {dir: 'tocreate'}
|
||||||
Dir.chdir(output_dir) do
|
Dir.chdir(output_dir) do
|
||||||
FileUtils.rm_rf('tocreate', secure: true)
|
FileUtils.rm_rf('tocreate', secure: true)
|
||||||
mock_squib_logger(@old_logger) do
|
|
||||||
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
|
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
|
||||||
expect(@deck.send(:dirify, opts, :dir, true)).to eq(opts)
|
expect(@deck.send(:dirify, opts, :dir, true)).to eq(opts)
|
||||||
expect(Dir.exists? 'tocreate').to be true
|
expect(Dir.exists? 'tocreate').to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,20 +98,13 @@ module Squib
|
||||||
def logger=(l)
|
def logger=(l)
|
||||||
@logger = l
|
@logger = l
|
||||||
end
|
end
|
||||||
module_function 'logger='
|
module_function :logger=
|
||||||
|
|
||||||
class Deck
|
class Deck
|
||||||
attr_accessor :progress_bar
|
attr_accessor :progress_bar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_squib_logger(old_logger)
|
|
||||||
old_logger = Squib.logger
|
|
||||||
Squib.logger = instance_double(Logger)
|
|
||||||
yield
|
|
||||||
Squib.logger = old_logger
|
|
||||||
end
|
|
||||||
|
|
||||||
def output_dir
|
def output_dir
|
||||||
File.expand_path('../samples/_output', File.dirname(__FILE__))
|
File.expand_path('../samples/_output', File.dirname(__FILE__))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue