From b645e22d8cdff81e80b9f081c3f336bc657e3fa8 Mon Sep 17 00:00:00 2001 From: atton Date: Fri, 22 Sep 2017 14:47:36 +0900 Subject: [PATCH] Raise RuntimeError when try convert from unspported class --- lib/rghost/ruby_ghost_engine.rb | 2 ++ spec/color_spec.rb | 4 ++-- spec/convert_spec.rb | 4 ++++ spec/document_spec.rb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/rghost/ruby_ghost_engine.rb b/lib/rghost/ruby_ghost_engine.rb index 54c9c46..13aab11 100755 --- a/lib/rghost/ruby_ghost_engine.rb +++ b/lib/rghost/ruby_ghost_engine.rb @@ -67,6 +67,8 @@ def render(device=nil) #@delete_input=false unless @options[:debug] when String file_in=@document + else + raise RuntimeError.new("Cannot convert #{@document.class}. Supported classes are RGhost::Document or File or String.") end params << shellescape(file_in) diff --git a/spec/color_spec.rb b/spec/color_spec.rb index a105dcc..2c15652 100644 --- a/spec/color_spec.rb +++ b/spec/color_spec.rb @@ -143,7 +143,7 @@ it "should create a color from a hex(html style)" do c = RGhost::RGB.new "#ABBACA" - c.ps.to_s.should == "0.670588235294118 0.729411764705882 0.792156862745098 setrgbcolor" + c.ps.to_s.should == "0.6705882352941176 0.7294117647058823 0.792156862745098 setrgbcolor" c = RGhost::RGB.new "#FFFFFF" c.ps.to_s.should == "1.0 1.0 1.0 setrgbcolor" @@ -158,7 +158,7 @@ c.ps.to_s.should == "1.0 1.0 0.0 setrgbcolor" c = RGhost::RGB.new "#334455" - c.ps.to_s.should == "0.2 0.266666666666667 0.333333333333333 setrgbcolor" + c.ps.to_s.should == "0.2 0.26666666666666666 0.3333333333333333 setrgbcolor" end diff --git a/spec/convert_spec.rb b/spec/convert_spec.rb index 0858790..4e6a30a 100644 --- a/spec/convert_spec.rb +++ b/spec/convert_spec.rb @@ -45,6 +45,10 @@ File.size(file).should_not be(0) end + + it "should raise exception when initialize with not supported file" do + expect{ RGhost::Convert.new(nil).to :jpeg }.to raise_error(/NilClass/) + end diff --git a/spec/document_spec.rb b/spec/document_spec.rb index f0a40f9..0d6637b 100644 --- a/spec/document_spec.rb +++ b/spec/document_spec.rb @@ -6,7 +6,7 @@ doc = RGhost::Document.new r = doc.render :pdf, :filename => RGhost.using_temp_dir("testdoc.pdf") - File.exists?(r.output).should be_true + File.exists?(r.output).should be true end