From 5e2ea072ca5d4eff66e7a419249e95fb67b9e3d0 Mon Sep 17 00:00:00 2001 From: Tim Woodbury Date: Thu, 13 Oct 2016 15:42:39 -0400 Subject: [PATCH] Raise exception for unrecognized join styles --- lib/prawn/errors.rb | 3 +++ lib/prawn/graphics/join_style.rb | 5 +++++ spec/stroke_styles_spec.rb | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/lib/prawn/errors.rb b/lib/prawn/errors.rb index aafff5e52..8e8aed5c5 100644 --- a/lib/prawn/errors.rb +++ b/lib/prawn/errors.rb @@ -75,5 +75,8 @@ module Errors # Raised when unrecognized content is provided for a table cell. # UnrecognizedTableContent = Class.new(StandardError) + + # This error is raised when an incompatible join style is specified + InvalidJoinStyle = Class.new(StandardError) end end diff --git a/lib/prawn/graphics/join_style.rb b/lib/prawn/graphics/join_style.rb index a5d098c24..467a4bbd7 100644 --- a/lib/prawn/graphics/join_style.rb +++ b/lib/prawn/graphics/join_style.rb @@ -25,6 +25,11 @@ def join_style(style = nil) self.current_join_style = style + unless JOIN_STYLES.has_key?(current_join_style) + raise Prawn::Errors::InvalidJoinStyle, + "#{style} is not a recognized join style. Valid styles are #{JOIN_STYLES.keys.join(", ")}" + end + write_stroke_join_style end diff --git a/spec/stroke_styles_spec.rb b/spec/stroke_styles_spec.rb index c2c54ed98..079ab5239 100644 --- a/spec/stroke_styles_spec.rb +++ b/spec/stroke_styles_spec.rb @@ -97,6 +97,12 @@ expect(join_styles.join_style_count).to eq(2) expect(join_styles.join_style).to eq(1) end + + context "with invalid arguments" do + it "should raise an exception" do + expect{ @pdf.join_style(:mitre) }.to raise_error(Prawn::Errors::InvalidJoinStyle) + end + end end describe "Dashes" do