spec/rtesseract_spec.rb in rtesseract-1.0.5 vs spec/rtesseract_spec.rb in rtesseract-1.1.0
- old
+ new
@@ -14,16 +14,15 @@
RTesseract.new(@image_tiff).class.should eql(RTesseract)
end
it " translate image to text" do
RTesseract.new(@image_tiff).to_s_without_spaces.should eql("43ZZ")
+ RTesseract.new(@image_tiff, {:processor => 'mini_magick'}).to_s_without_spaces.should eql("43ZZ")
RTesseract.new(@path.join("images","test1.tif").to_s).to_s_without_spaces.should eql("V2V4")
RTesseract.new(@path.join("images","test with spaces.tif").to_s).to_s_without_spaces.should eql("V2V4")
end
-
-
it " translate images .png, .jpg, .bmp" do
RTesseract.new(@path.join("images","test.png").to_s).to_s_without_spaces.should eql("HW9W")
RTesseract.new(@path.join("images","test.jpg").to_s).to_s_without_spaces.should eql("3R8Z")
RTesseract.new(@path.join("images","test.bmp").to_s).to_s_without_spaces.should eql("ZLA6")
end
@@ -75,25 +74,54 @@
blob = image.quantize(256,Magick::GRAYColorspace).to_blob
test = RTesseract.new("", {:psm => 7})
test.from_blob(blob)
test.to_s_without_spaces.should eql("HW9W")
+
+ test = RTesseract.new("", {:psm => 7})
+ expect{test.from_blob('') }.to raise_error(RTesseract::ConversionError)
end
it " use a instance" do
RTesseract.new(Magick::Image.read(@image_tiff.to_s).first).to_s_without_spaces.should eql("43ZZ")
+ RMagickProcessor.a_name?('teste').should == false
+ RMagickProcessor.a_name?('rmagick').should == true
+ 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
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)
image = image.quantize(256,Magick::GRAYColorspace)
end
test.to_s_without_spaces.should eql("HW9W")
test = RTesseract.read(@path.join("images","test.jpg").to_s,{:lang=>'en'}) do |image|
- image = image.white_threshold(245).quantize(256,Magick::GRAYColorspace)
+ image = image.white_threshold(245).quantize(256, Magick::GRAYColorspace)
end
- test.to_s_without_spaces.should eql("3R8Z")
+ 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)
+ end
+
+ it "remove a file" do
+ rtesseract = RTesseract.new('.')
+ rtesseract.remove_file(Tempfile.new('config'))
+
+ expect{ rtesseract.remove_file(Pathname.new(Dir.tmpdir).join("test_not_exists")) }.to raise_error(RTesseract::TempFilesNotRemovedError)
+ end
end