Fix can not create file in tmp_dir in travis
This commit is contained in:
parent
05cb20fe9d
commit
a7bc855fa2
|
@ -1,15 +1,17 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'tmpdir'
|
||||||
|
|
||||||
describe 'OCR' do
|
describe 'OCR' do
|
||||||
before do
|
before do
|
||||||
|
@tmp_dir = Dir.mktmpdir
|
||||||
@samples = []
|
@samples = []
|
||||||
10.times do
|
10.times do
|
||||||
@samples << SecureRandom.hex(2)
|
@samples << SecureRandom.hex(2)
|
||||||
end
|
end
|
||||||
@filenames = []
|
@filenames = []
|
||||||
@samples.each do |chars|
|
@samples.each do |chars|
|
||||||
fname = File.join(File.dirname(__FILE__), "..", "tmp", "#{chars}.png")
|
fname = File.join(@tmp_dir, "#{chars}.png")
|
||||||
img = RuCaptcha::Captcha.create(chars)
|
img = RuCaptcha::Captcha.create(chars)
|
||||||
File.open(fname, 'w+') do |f|
|
File.open(fname, 'w+') do |f|
|
||||||
f.puts img
|
f.puts img
|
||||||
|
@ -19,14 +21,13 @@ describe 'OCR' do
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
path = File.expand_path File.join(File.dirname(__FILE__), '..', 'tmp/*.png')
|
FileUtils.rm_f(@tmp_dir)
|
||||||
FileUtils.rm_f(path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not read by OCR lib' do
|
it 'should not read by OCR lib' do
|
||||||
results = []
|
results = []
|
||||||
@samples.each do |chars|
|
@samples.each do |chars|
|
||||||
str = RTesseract.new(File.join(File.dirname(__FILE__), "..", "tmp", "#{chars}.png"), processor: 'mini_magick').to_s
|
str = RTesseract.new(File.join(@tmp_dir, "#{chars}.png"), processor: 'mini_magick').to_s
|
||||||
results << "- Chars: #{chars}, OCR read #{str.strip}"
|
results << "- Chars: #{chars}, OCR read #{str.strip}"
|
||||||
expect(chars).not_to eq(str)
|
expect(chars).not_to eq(str)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue