spec/rtesseract_spec.rb in rtesseract-1.2.0 vs spec/rtesseract_spec.rb in rtesseract-1.2.1

- old
+ new

@@ -1,8 +1,13 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') # encoding: UTF-8 require 'pathname' +class MakeStringError + def to_s + raise "error" + end +end describe "Rtesseract" do before do @path = Pathname.new(__FILE__.gsub("rtesseract_spec.rb","")).expand_path @image_tiff = @path.join("images","test.tif").to_s @@ -62,10 +67,13 @@ RTesseract.new(@image_tiff,{:lang=>"eng"}).to_s_without_spaces.should eql("43ZZ") RTesseract.new(@image_tiff,{:lang=>"por"}).to_s_without_spaces.should eql("43ZZ") RTesseract.new(@image_tiff,{:lang=>"eng"}).lang.should eql(" -l eng ") + + #Inválid lang object + RTesseract.new(@image_tiff,{:lang=>MakeStringError.new}).lang.should eql("") end it " be configurable" do RTesseract.new(@image_tiff,{:chop_enable=>0,:enable_assoc=>0,:display_text=>0}).config.should eql("chop_enable 0\nenable_assoc 0\ndisplay_text 0") RTesseract.new(@image_tiff,{:chop_enable=>0}).config.should eql("chop_enable 0") @@ -100,10 +108,14 @@ RMagickProcessor.a_name?('RMagickProcessor').should == true MiniMagickProcessor.a_name?('teste').should == false MiniMagickProcessor.a_name?('mini_magick').should == true MiniMagickProcessor.a_name?('MiniMagickProcessor').should == true + + QuickMagickProcessor.a_name?('teste').should == false + QuickMagickProcessor.a_name?('quick_magick').should == true + QuickMagickProcessor.a_name?('QuickMagickProcessor').should == true end it " change image in a block" do test = RTesseract.read(@path.join("images","test.png").to_s) do |image| image = image.white_threshold(245) @@ -114,21 +126,22 @@ test = RTesseract.read(@path.join("images","test.jpg").to_s,{:lang=>'en'}) do |image| image = image.white_threshold(245).quantize(256, Magick::GRAYColorspace) end test.to_s_without_spaces.should eql("3R8Z") - require 'mini_magick' - test = RTesseract.read(@path.join("images","test.jpg").to_s,{:lang=>'en', :processor => 'mini_magick'}) do |image| #image.white_threshold(245) image.gravity "south" end test.to_s_without_spaces.should eql("3R8Z") end it " get a error" do expect{ RTesseract.new(@path.join("images","test.jpg").to_s, {:command => "tesseract_error"}).to_s }.to raise_error(RTesseract::ConversionError) expect{ RTesseract.new(@path.join("images","test_not_exists.png").to_s).to_s }.to raise_error(RTesseract::ImageNotSelectedError) + + #Inválid psm object + RTesseract.new(@image_tiff,{:psm=>MakeStringError.new}).psm.should eql("") end it "remove a file" do rtesseract = RTesseract.new('.') rtesseract.remove_file(Tempfile.new('config'))