@@ -3,10 +3,12 @@ require 'squib'
|
||||
|
||||
describe Squib::Deck, '#text' do
|
||||
|
||||
context "when working with fonts" do
|
||||
it"should use the default font when #text and #set_font don't specify" do
|
||||
context "fonts" do
|
||||
it "should use the default font when #text and #set_font don't specify" do
|
||||
card = instance_double(Squib::Card)
|
||||
expect(card).to receive(:text).with('a', 'Arial 36', anything, anything, anything, anything).once
|
||||
expect(card).to receive(:text).with('a', 'Arial 36',
|
||||
anything, anything, anything, anything,anything, anything, anything, anything,anything, anything, anything, anything, anything
|
||||
).once
|
||||
Squib::Deck.new do
|
||||
@cards = [card]
|
||||
text str: 'a'
|
||||
@@ -15,7 +17,9 @@ describe Squib::Deck, '#text' do
|
||||
|
||||
it "should use the #set_font when #text doesn't specify" do
|
||||
card = instance_double(Squib::Card)
|
||||
expect(card).to receive(:text).with('a', 'Times New Roman 16', anything, anything, anything, anything).once
|
||||
expect(card).to receive(:text).with('a', 'Times New Roman 16',
|
||||
anything, anything, anything, anything,anything, anything, anything, anything,anything, anything, anything, anything, anything
|
||||
).once
|
||||
Squib::Deck.new do
|
||||
@cards = [card]
|
||||
set font: 'Times New Roman 16'
|
||||
@@ -25,7 +29,9 @@ describe Squib::Deck, '#text' do
|
||||
|
||||
it "should use the specified font no matter what" do
|
||||
card = instance_double(Squib::Card)
|
||||
expect(card).to receive(:text).with('a', 'Arial 18', anything, anything, anything, anything).once
|
||||
expect(card).to receive(:text).with('a', 'Arial 18',
|
||||
anything, anything, anything, anything,anything, anything, anything, anything,anything, anything, anything, anything, anything
|
||||
).once
|
||||
Squib::Deck.new do
|
||||
@cards = [card]
|
||||
set font: 'Times New Roman 16'
|
||||
|
||||
+22
-17
@@ -27,27 +27,31 @@ describe Squib::InputHelpers do
|
||||
it "should warn on the logger when the layout doesn't exist" do
|
||||
@old_logger = Squib.logger
|
||||
Squib.logger = instance_double(Logger)
|
||||
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.")
|
||||
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: :foo})
|
||||
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
||||
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
|
||||
Squib.logger = @old_logger
|
||||
end
|
||||
|
||||
it "should apply the layout in a normal situation" do
|
||||
expect(@deck.send(:layoutify, {layout: :blah})).to eq({layout: :blah, x: 25})
|
||||
expect(@deck.send(:layoutify, {layout: :blah})).to \
|
||||
eq({layout: [:blah, :blah], x: 25})
|
||||
end
|
||||
|
||||
it "also look up based on strings" do
|
||||
expect(@deck.send(:layoutify, {layout: 'blah'})).to eq({layout: 'blah', x: 25})
|
||||
expect(@deck.send(:layoutify, {layout: 'blah'})).to \
|
||||
eq({layout: ['blah','blah'], x: 25})
|
||||
end
|
||||
end
|
||||
|
||||
context '#rangeify' do
|
||||
it "must be within the card size range" do
|
||||
expect{@deck.send(:rangeify, {range: 2..3})}.to raise_error(ArgumentError, '2..3 is outside of deck range of 0..1')
|
||||
expect{@deck.send(:rangeify, {range: 2..3})}.to \
|
||||
raise_error(ArgumentError, '2..3 is outside of deck range of 0..1')
|
||||
end
|
||||
|
||||
it "cannot be nil" do
|
||||
expect{@deck.send(:rangeify, {range: nil})}.to raise_error(RuntimeError, 'Range cannot be nil')
|
||||
expect{@deck.send(:rangeify, {range: nil})}.to \
|
||||
raise_error(RuntimeError, 'Range cannot be nil')
|
||||
end
|
||||
|
||||
it "defaults to a range of all cards if :all" do
|
||||
@@ -57,38 +61,39 @@ describe Squib::InputHelpers do
|
||||
|
||||
context "#fileify" do
|
||||
it "should throw an error if the file doesn't exist" do
|
||||
expect{@deck.send(:fileify, {file: 'nonexist.txt'}, false, true)}.to raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
|
||||
end
|
||||
|
||||
it "should expand singletons when asked" do
|
||||
expect(@deck.send(:fileify, {file: 'foo.txt'}, true, false)).to eq({file: ['foo.txt', 'foo.txt']})
|
||||
expect{@deck.send(:fileify, {file: 'nonexist.txt'}, true)}.to \
|
||||
raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
|
||||
end
|
||||
end
|
||||
|
||||
context "#dir" do
|
||||
it "should raise an error if the directory does not exist" do
|
||||
expect{@deck.send(:dirify, {dir: 'nonexist'}, false)}.to raise_error(RuntimeError,"'nonexist' does not exist!")
|
||||
expect{@deck.send(:dirify, {dir: 'nonexist'}, false)}.to \
|
||||
raise_error(RuntimeError,"'nonexist' does not exist!")
|
||||
end
|
||||
end
|
||||
|
||||
context "#colorify" do
|
||||
it "should parse if nillable" do
|
||||
color = @deck.send(:colorify, {color: '#fff'}, true)[:color]
|
||||
expect(color.to_a).to eq([1.0, 1.0, 1.0, 1.0])
|
||||
color = @deck.send(:colorify, {color: ['#fff']}, true)[:color]
|
||||
expect(color.to_a[0].to_a).to eq([1.0, 1.0, 1.0, 1.0])
|
||||
end
|
||||
|
||||
it "raises and error if the color doesn't exist" do
|
||||
expect{ @deck.send(:colorify, {color: :nonexist}, false) }.to raise_error(ArgumentError, "unknown color name: nonexist")
|
||||
expect{ @deck.send(:colorify, {color: [:nonexist]}, false) }.to \
|
||||
raise_error(ArgumentError, "unknown color name: nonexist")
|
||||
end
|
||||
|
||||
it "pulls from config's custom colors" do
|
||||
@deck.custom_colors['foo'] = "#abc"
|
||||
expect(@deck.send(:colorify, {color: :foo}, false)[:color].to_s).to eq('#AABBCCFF')
|
||||
expect(@deck.send(:colorify, {color: [:foo]}, false)[:color][0].to_s).to \
|
||||
eq('#AABBCCFF')
|
||||
end
|
||||
|
||||
it "pulls from config's custom colors even when a string" do
|
||||
@deck.custom_colors['foo'] = "#abc"
|
||||
expect(@deck.send(:colorify, {color: 'foo'}, false)[:color].to_s).to eq('#AABBCCFF')
|
||||
expect(@deck.send(:colorify, {color: ['foo']}, false)[:color][0].to_s).to \
|
||||
eq('#AABBCCFF')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user