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:
|
||||
# @api private
|
||||
def set_source_squibcolor(arg)
|
||||
raise 'nil is not a valid color' if arg.nil?
|
||||
if match = arg.match(LINEAR_GRADIENT)
|
||||
x1, y1, x2, y2 = match.captures
|
||||
linear = Cairo::LinearPattern.new(x1.to_f, y1.to_f, x2.to_f, y2.to_f)
|
||||
|
|
|
|||
|
|
@ -6,21 +6,30 @@ describe Squib::Graphics::CairoContextWrapper do
|
|||
let(:cairo) { double(Cairo::Context) }
|
||||
subject { Squib::Graphics::CairoContextWrapper.new(cairo) }
|
||||
|
||||
it 'passes on colors as normal' do
|
||||
expect(cairo).to receive(:set_source_color).with('blue')
|
||||
subject.set_source_squibcolor('blue')
|
||||
context '#set_source_squibcolor' do
|
||||
|
||||
it 'passes on colors as normal' do
|
||||
expect(cairo).to receive(:set_source_color).with('blue')
|
||||
subject.set_source_squibcolor('blue')
|
||||
end
|
||||
|
||||
it 'passes on color symbols as normal' do
|
||||
expect(cairo).to receive(:set_source_color).with(:blue)
|
||||
subject.set_source_squibcolor(:blue)
|
||||
end
|
||||
|
||||
it 'passes on color hashes' do
|
||||
expect(cairo).to receive(:set_source_color)
|
||||
.with('#aabbccdd')
|
||||
subject.set_source_squibcolor('#aabbccdd')
|
||||
end
|
||||
|
||||
it 'raises on nil' do
|
||||
expect { subject.set_source_squibcolor(nil) }.to raise_error('nil is not a valid color')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'passes on color symbols as normal' do
|
||||
expect(cairo).to receive(:set_source_color).with(:blue)
|
||||
subject.set_source_squibcolor(:blue)
|
||||
end
|
||||
|
||||
it 'passes on color hashes' do
|
||||
expect(cairo).to receive(:set_source_color)
|
||||
.with('#aabbccdd')
|
||||
subject.set_source_squibcolor('#aabbccdd')
|
||||
end
|
||||
|
||||
context 'regex variations for linear gradients' do
|
||||
before(:each) do
|
||||
|
|
|
|||
Loading…
Reference in New Issue