rucaptcha/spec/ocr_spec.rb

37 lines
954 B
Ruby
Raw Normal View History

2015-10-26 13:55:46 +00:00
require 'spec_helper'
require 'fileutils'
2015-10-26 13:55:46 +00:00
describe 'OCR' do
before do
@samples = []
10.times do
@samples << SecureRandom.hex(2)
end
@filenames = []
@samples.each do |chars|
fname = File.join(File.dirname(__FILE__), "..", "tmp", "#{chars}.png")
img = RuCaptcha::Captcha.create(chars)
File.open(fname, 'w+') do |f|
f.puts img
end
@filenames << fname
end
end
after do
path = File.expand_path File.join(File.dirname(__FILE__), '..', 'tmp/*.png')
FileUtils.rm_f(path)
2015-10-26 13:55:46 +00:00
end
it 'should not read by OCR lib' do
results = []
@samples.each do |chars|
2015-10-29 10:28:11 +00:00
str = RTesseract.new(File.join(File.dirname(__FILE__), "..", "tmp", "#{chars}.png"), processor: 'mini_magick').to_s
2015-10-26 13:55:46 +00:00
results << "- Chars: #{chars}, OCR read #{str.strip}"
expect(chars).not_to eq(str)
end
2015-10-29 10:22:27 +00:00
puts %(\n------------------------\nOCR all results: \n#{results.join("\n")})
2015-10-26 13:55:46 +00:00
end
end