Add nil check for colors, just in case
Probably not possible, but provides a more descriptive error than before anyway. Fixes #84.dev
parent
f21e9448e1
commit
70a5f48bda
|
|
@ -30,6 +30,7 @@ module Squib
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
# @api private
|
# @api private
|
||||||
def set_source_squibcolor(arg)
|
def set_source_squibcolor(arg)
|
||||||
|
raise 'nil is not a valid color' if arg.nil?
|
||||||
if match = arg.match(LINEAR_GRADIENT)
|
if match = arg.match(LINEAR_GRADIENT)
|
||||||
x1, y1, x2, y2 = match.captures
|
x1, y1, x2, y2 = match.captures
|
||||||
linear = Cairo::LinearPattern.new(x1.to_f, y1.to_f, x2.to_f, y2.to_f)
|
linear = Cairo::LinearPattern.new(x1.to_f, y1.to_f, x2.to_f, y2.to_f)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
let(:cairo) { double(Cairo::Context) }
|
let(:cairo) { double(Cairo::Context) }
|
||||||
subject { Squib::Graphics::CairoContextWrapper.new(cairo) }
|
subject { Squib::Graphics::CairoContextWrapper.new(cairo) }
|
||||||
|
|
||||||
|
context '#set_source_squibcolor' do
|
||||||
|
|
||||||
it 'passes on colors as normal' do
|
it 'passes on colors as normal' do
|
||||||
expect(cairo).to receive(:set_source_color).with('blue')
|
expect(cairo).to receive(:set_source_color).with('blue')
|
||||||
subject.set_source_squibcolor('blue')
|
subject.set_source_squibcolor('blue')
|
||||||
|
|
@ -22,6 +24,13 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
subject.set_source_squibcolor('#aabbccdd')
|
subject.set_source_squibcolor('#aabbccdd')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'raises on nil' do
|
||||||
|
expect { subject.set_source_squibcolor(nil) }.to raise_error('nil is not a valid color')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'regex variations for linear gradients' do
|
context 'regex variations for linear gradients' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
dbl = double(Cairo::LinearPattern)
|
dbl = double(Cairo::LinearPattern)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue