spec/rtesseract_spec.rb in rtesseract-1.3.3 vs spec/rtesseract_spec.rb in rtesseract-2.0.0

- old
+ new

@@ -33,11 +33,11 @@ expect(RTesseract.new(@path.join('images', 'test.jpg').to_s).to_s_without_spaces).to eql('3R8F') expect(RTesseract.new(@path.join('images', 'test.bmp').to_s).to_s_without_spaces).to eql('FLA6') end it ' should not error with depth > 32' do - #expect(RTesseract.new(@path.join('images', 'README.pdf').to_s, debug: true).to_s_without_spaces).to eql('') + # expect(RTesseract.new(@path.join('images', 'README.pdf').to_s, debug: true).to_s_without_spaces).to eql('') end it ' support different processors' do # Rmagick expect(RTesseract.new(@image_tif).to_s_without_spaces).to eql('43XF') @@ -46,19 +46,14 @@ # MiniMagick expect(RTesseract.new(@image_tif, processor: 'mini_magick').to_s_without_spaces).to eql('43XF') expect(RTesseract.new(@path.join('images', 'test.png').to_s, processor: 'mini_magick').to_s_without_spaces).to eql('HW9W') - # QuickMagick - expect(RTesseract.new(@image_tif, processor: 'quick_magick').to_s_without_spaces).to eql('43XF') - expect(RTesseract.new(@path.join('images', 'test.png').to_s, processor: 'quick_magick').to_s_without_spaces).to eql('HW9W') - # NoneMagick expect(RTesseract.new(@image_tif, processor: 'none').to_s_without_spaces).to eql('43XF') end - it ' change the image' do image = RTesseract.new(@image_tif) expect(image.to_s_without_spaces).to eql('43XF') image.source = @path.join('images', 'test1.tif').to_s expect(image.to_s_without_spaces).to eql('V2V4') @@ -104,14 +99,14 @@ expect(RTesseract.new(@image_tif, chop_enable: 0, enable_assoc: 0).config).to eql("chop_enable 0\nenable_assoc 0") expect(RTesseract.new(@image_tif, chop_enable: 0).to_s_without_spaces).to eql('43XF') end it ' crop image' do - expect(RTesseract.new(@image_tif, psm: 7).crop!(140, 10, 36, 40).to_s_without_spaces).to eql('4') - expect(RTesseract.new(@image_tif, psm: 7).crop!(180, 10, 36, 40).to_s_without_spaces).to eql('3') - expect(RTesseract.new(@image_tif, psm: 7).crop!(216, 10, 20, 40).to_s_without_spaces).to eql('X') - expect(RTesseract.new(@image_tif, psm: 7).crop!(240, 10, 30, 40).to_s_without_spaces).to eql('F') + expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 36, h: 40, x: 140, y: 10).to_s_without_spaces).to eql('4') + expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 36, h: 40, x: 180, y: 10).to_s_without_spaces).to eql('3') + expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 20, h: 40, x: 216, y: 10).to_s_without_spaces).to eql('X') + expect(RTesseract.new(@image_tif, psm: 7).crop!(w: 30, h: 40, x: 240, y: 10).to_s_without_spaces).to eql('F') end it ' read image from blob' do image = Magick::Image.read(@path.join('images', 'test.png').to_s).first blob = image.quantize(256, Magick::GRAYColorspace).to_blob @@ -130,45 +125,42 @@ expect(RMagickProcessor.a_name?('rmagick')).to eql(true) expect(RMagickProcessor.a_name?('RMagickProcessor')).to eql(true) expect(MiniMagickProcessor.a_name?('teste')).to eql(false) expect(MiniMagickProcessor.a_name?('mini_magick')).to eql(true) expect(MiniMagickProcessor.a_name?('MiniMagickProcessor')).to eql(true) - expect(QuickMagickProcessor.a_name?('teste')).to eql(false) - expect(QuickMagickProcessor.a_name?('quick_magick')).to eql(true) - expect(QuickMagickProcessor.a_name?('QuickMagickProcessor')).to eql(true) expect(NoneProcessor.a_name?('none')).to eql(true) expect(NoneProcessor.a_name?('NoneProcessor')).to eql(true) end it ' change image in a block' do test = RTesseract.read(@path.join('images', 'test.png').to_s) {} expect(test.class).to eql(RTesseract) test = RTesseract.new(@image_tif) - test.read do |image| - image = image.quantize(256, Magick::GRAYColorspace) + test.read do |_image| + _image = _image.quantize(256, Magick::GRAYColorspace) end expect(test.to_s_without_spaces).to eql('43XF') test = RTesseract.new(@path.join('images', 'blank.tif').to_s) - test.read do |image| - image + test.read do |_image| + _image end expect(test.to_s_without_spaces).to eql('') - test = RTesseract.read(@path.join('images', 'test.png').to_s) do |image| - image.rotate(90) + test = RTesseract.read(@path.join('images', 'test.png').to_s) do |_image| + _image.rotate(90) end expect(test.to_s_without_spaces).to 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) + test = RTesseract.read(@path.join('images', 'test.jpg').to_s, lang: 'en') do |_image| + _image = _image.white_threshold(245).quantize(256, Magick::GRAYColorspace) end expect(test.to_s_without_spaces).to eql('3R8F') - test = RTesseract.read(@path.join('images', 'test.jpg').to_s, lang: 'en', processor: 'mini_magick') do |image| - image.gravity 'south' + test = RTesseract.read(@path.join('images', 'test.jpg').to_s, lang: 'en', processor: 'mini_magick') do |_image| + _image.gravity 'south' end expect(test.to_s_without_spaces).to eql('3R8F') end it ' get a error' do @@ -186,32 +178,47 @@ expect { rtesseract.remove_file(Pathname.new(Dir.tmpdir).join('test_not_exists')) }.to raise_error(RTesseract::TempFilesNotRemovedError) end it ' support default config processors' do # Rmagick - RTesseract.configure {|config| config.processor = 'rmagick' } + RTesseract.configure { |config| config.processor = 'rmagick' } expect(RTesseract.new(@image_tif).processor.a_name?('rmagick')).to eql(true) # MiniMagick - RTesseract.configure {|config| config.processor = 'mini_magick' } + RTesseract.configure { |config| config.processor = 'mini_magick' } expect(RTesseract.new(@image_tif).processor.a_name?('mini_magick')).to eql(true) - # QuickMagick - RTesseract.configure {|config| config.processor = 'quick_magick' } - expect(RTesseract.new(@image_tif).processor.a_name?('quick_magick')).to eql(true) - # NoneMagick - RTesseract.configure {|config| config.processor = 'none' } + RTesseract.configure { |config| config.processor = 'none' } expect(RTesseract.new(@image_tif).processor.a_name?('none')).to eql(true) # overwrite default - RTesseract.configure {|config| config.processor = 'mini_magick' } - expect(RTesseract.new(@image_tif, processor: 'quick_magick').processor.a_name?('quick_magick')).to eql(true) + RTesseract.configure { |config| config.processor = 'rmagick' } + expect(RTesseract.new(@image_tif, processor: 'mini_magick').processor.a_name?('mini_magick')).to eql(true) - RTesseract.configure {|config| config.lang = 'portuguese' } + RTesseract.configure { |config| config.lang = 'portuguese' } expect(RTesseract.new(@image_tif).lang).to eql(' -l por ') - RTesseract.configure {|config| config.psm = 7 } + RTesseract.configure { |config| config.psm = 7 } expect(RTesseract.new(@image_tif).psm).to eql(' -psm 7 ') + + + RTesseract.configure { |config| config.tessdata_dir = '/tmp/test' } + expect(RTesseract.new(@image_tif).tessdata_dir).to eql(' --tessdata-dir /tmp/test ') + + RTesseract.configure { |config| config.user_words = '/tmp/test' } + expect(RTesseract.new(@image_tif).user_words).to eql(' --user-words /tmp/test ') + + RTesseract.configure { |config| config.user_patterns = '/tmp/test' } + expect(RTesseract.new(@image_tif).user_patterns).to eql(' --user-patterns /tmp/test ') end + it ' support new configs' do + expect(RTesseract.new(@image_tif, tessdata_dir: '/tmp/test').tessdata_dir).to eql(' --tessdata-dir /tmp/test ') + expect(RTesseract.new(@image_tif, user_words: '/tmp/test').user_words).to eql(' --user-words /tmp/test ') + expect(RTesseract.new(@image_tif, user_patterns: '/tmp/test').user_patterns).to eql(' --user-patterns /tmp/test ') + + expect(RTesseract.new(@image_tif, tessdata_dir: MakeStringError.new).tessdata_dir).to eql('') + expect(RTesseract.new(@image_tif, user_words: MakeStringError.new).user_words).to eql('') + expect(RTesseract.new(@image_tif, user_patterns: MakeStringError.new).user_patterns).to eql('') + end end