|
|
|
|
@ -28,7 +28,7 @@ describe Squib::InputHelpers do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context '#layoutify' do |
|
|
|
|
it "warns on the logger when the layout doesn't exist" do |
|
|
|
|
it 'warns on the logger when the layout does not exist' do |
|
|
|
|
@old_logger = Squib.logger |
|
|
|
|
Squib.logger = instance_double(Logger) |
|
|
|
|
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice |
|
|
|
|
@ -37,23 +37,23 @@ describe Squib::InputHelpers do
|
|
|
|
|
Squib.logger = @old_logger |
|
|
|
|
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 \ |
|
|
|
|
eq({layout: [:blah, :blah], x: [25, 25]}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "applies two different layouts for two different situations" do |
|
|
|
|
it 'applies two different layouts for two different situations' do |
|
|
|
|
expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \ |
|
|
|
|
eq({layout: ['blah','apples'], x: [25, 35]}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "still has nils when not applied two different layouts differ in structure" do |
|
|
|
|
it 'still has nils when not applied two different layouts differ in structure' do |
|
|
|
|
expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \ |
|
|
|
|
eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]}) |
|
|
|
|
#...this might behavior that is hard to debug for users. Trying to come up with a warning or something... |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "also looks up based on strings" do |
|
|
|
|
it 'also looks up based on strings' do |
|
|
|
|
expect(@deck.send(:layoutify, {layout: 'blah'})).to \ |
|
|
|
|
eq({layout: ['blah','blah'], x: [25, 25]}) |
|
|
|
|
end |
|
|
|
|
@ -61,54 +61,54 @@ describe Squib::InputHelpers do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context '#rangeify' do |
|
|
|
|
it "must be within the card size range" 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') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "cannot be nil" do |
|
|
|
|
it 'cannot be nil' do |
|
|
|
|
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 |
|
|
|
|
it 'defaults to a range of all cards if :all' do |
|
|
|
|
expect(@deck.send(:rangeify, {range: :all})).to eq({range: 0..1}) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "#fileify" do |
|
|
|
|
it "should throw an error if the file doesn't exist" do |
|
|
|
|
context '#fileify' do |
|
|
|
|
it 'should throw an error if the file does not exist' do |
|
|
|
|
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 |
|
|
|
|
context '#dir' do |
|
|
|
|
it 'should raise an error if the directory does not exist' do |
|
|
|
|
expect{@deck.send(:dirify, {dir: 'nonexist'}, :dir, false)}.to \ |
|
|
|
|
raise_error(RuntimeError,"'nonexist' does not exist!") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "#colorify" do |
|
|
|
|
it "should parse if nillable" do |
|
|
|
|
context '#colorify' do |
|
|
|
|
it 'should parse if nillable' do |
|
|
|
|
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 |
|
|
|
|
it 'raises and error if the color does not exist' do |
|
|
|
|
expect{ @deck.send(:colorify, {color: [:nonexist]}, false) }.to \ |
|
|
|
|
raise_error(ArgumentError, "unknown color name: nonexist") |
|
|
|
|
raise_error(ArgumentError, 'unknown color name: nonexist') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "pulls from config's custom colors" do |
|
|
|
|
@deck.custom_colors['foo'] = "#abc" |
|
|
|
|
it 'pulls from custom colors in the config' do |
|
|
|
|
@deck.custom_colors['foo'] = '#abc' |
|
|
|
|
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" |
|
|
|
|
it 'pulls custom colors even when a string' do |
|
|
|
|
@deck.custom_colors['foo'] = '#abc' |
|
|
|
|
expect(@deck.send(:colorify, {color: ['foo']}, false)[:color][0].to_s).to \ |
|
|
|
|
eq('#AABBCCFF') |
|
|
|
|
end |
|
|
|
|
|