Browse Source

Add nil check for colors, just in case

Probably not possible, but provides a more descriptive error than before anyway.

Fixes #84.
dev
Andy Meneely 11 years ago
parent
commit
70a5f48bda
  1. 1
      lib/squib/graphics/cairo_context_wrapper.rb
  2. 9
      spec/graphics/cairo_context_wrapper_spec.rb

1
lib/squib/graphics/cairo_context_wrapper.rb

@ -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)

9
spec/graphics/cairo_context_wrapper_spec.rb

@ -6,6 +6,8 @@ describe Squib::Graphics::CairoContextWrapper do
let(:cairo) { double(Cairo::Context) }
subject { Squib::Graphics::CairoContextWrapper.new(cairo) }
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')
@ -22,6 +24,13 @@ describe Squib::Graphics::CairoContextWrapper do
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
context 'regex variations for linear gradients' do
before(:each) do
dbl = double(Cairo::LinearPattern)

Loading…
Cancel
Save