2015-10-30 03:32:02 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RuCaptcha::Captcha do
|
|
|
|
describe '.random_chars' do
|
|
|
|
it 'should len equal config.len' do
|
2016-05-25 03:07:26 +00:00
|
|
|
expect(RuCaptcha::Captcha.random_chars.length).to eq(RuCaptcha.config.len)
|
2015-10-30 03:32:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return 0-9 and lower str' do
|
2016-05-25 03:07:26 +00:00
|
|
|
expect(RuCaptcha::Captcha.random_chars).to match(/[a-z0-9]/)
|
2015-10-30 03:32:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not include [0ol1]' do
|
2016-05-23 07:11:04 +00:00
|
|
|
10_000.times do
|
2016-05-25 03:07:26 +00:00
|
|
|
expect(RuCaptcha::Captcha.random_chars).not_to match(/[0ol1]/i)
|
2015-10-30 03:32:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-06 07:50:30 +00:00
|
|
|
|
|
|
|
describe '.random_color' do
|
|
|
|
it 'should return colorful array' do
|
|
|
|
allow(RuCaptcha.config).to receive(:style).and_return(:colorful)
|
|
|
|
colors = RuCaptcha::Captcha.random_color
|
|
|
|
expect(colors.uniq.size >= 2).to eq true
|
|
|
|
colors1 = RuCaptcha::Captcha.random_color
|
|
|
|
expect(colors).not_to eq colors1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return black color array' do
|
|
|
|
allow(RuCaptcha.config).to receive(:style).and_return(:black_white)
|
|
|
|
colors = RuCaptcha::Captcha.random_color
|
|
|
|
expect(colors.uniq.size).to eq 1
|
|
|
|
colors1 = RuCaptcha::Captcha.random_color
|
|
|
|
expect(colors).not_to eq colors1
|
|
|
|
end
|
|
|
|
end
|
2016-11-08 03:18:07 +00:00
|
|
|
|
|
|
|
describe '.rand_line_top' do
|
|
|
|
it 'should work' do
|
|
|
|
expect(RuCaptcha::Captcha.send(:rand_line_top, 1, 24)).to be_a(Integer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.uniq_rgbs_for_each_chars' do
|
|
|
|
let(:chars) { %w(a b c d e) }
|
|
|
|
let(:colors) { RuCaptcha::Captcha.send(:uniq_rgbs_for_each_chars, chars) }
|
|
|
|
|
|
|
|
it 'should work' do
|
|
|
|
expect(colors.length).to eq chars.length
|
|
|
|
expect(colors[0].length).to eq 3
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'Be sure the color not same as preview color' do
|
|
|
|
pre_rgb = nil
|
|
|
|
colors.each do |rgb|
|
|
|
|
if pre_rgb
|
|
|
|
same = rgb.index(rgb.min) == pre_rgb.index(rgb.min) && rgb.index(rgb.max) == pre_rgb.index(pre_rgb.max)
|
|
|
|
expect(same).not_to eq true
|
|
|
|
end
|
|
|
|
pre_rgb = rgb
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-30 03:32:02 +00:00
|
|
|
end
|