diff --git a/lib/squib/graphics/cairo_context_wrapper.rb b/lib/squib/graphics/cairo_context_wrapper.rb index 9eac0c5..397503c 100644 --- a/lib/squib/graphics/cairo_context_wrapper.rb +++ b/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) @@ -82,4 +83,4 @@ module Squib end end -end \ No newline at end of file +end diff --git a/spec/graphics/cairo_context_wrapper_spec.rb b/spec/graphics/cairo_context_wrapper_spec.rb index d764dd6..a64fe63 100644 --- a/spec/graphics/cairo_context_wrapper_spec.rb +++ b/spec/graphics/cairo_context_wrapper_spec.rb @@ -6,22 +6,31 @@ 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') - end + context '#set_source_squibcolor' do - 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 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 - 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 dbl = double(Cairo::LinearPattern) @@ -72,4 +81,4 @@ describe Squib::Graphics::CairoContextWrapper do end end -end \ No newline at end of file +end