2015-10-30 03:32:02 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-01-22 02:16:57 +00:00
|
|
|
describe RuCaptcha do
|
|
|
|
describe '.generate' do
|
2016-11-08 03:18:07 +00:00
|
|
|
it 'should work' do
|
2017-01-22 02:16:57 +00:00
|
|
|
res = RuCaptcha.generate()
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(5)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
2016-11-08 03:18:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-22 02:16:57 +00:00
|
|
|
describe '.create' do
|
|
|
|
it 'should len equal config.len' do
|
2017-12-07 08:49:42 +00:00
|
|
|
res = RuCaptcha.create(0, 5, 1)
|
2017-01-22 02:16:57 +00:00
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(5)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
2016-11-08 03:18:07 +00:00
|
|
|
end
|
|
|
|
|
2017-01-22 02:16:57 +00:00
|
|
|
it 'should work with color style' do
|
2017-12-07 08:49:42 +00:00
|
|
|
res = RuCaptcha.create(1, 5, 1)
|
2017-01-22 02:16:57 +00:00
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(5)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
2016-11-08 03:18:07 +00:00
|
|
|
end
|
2017-12-07 08:49:42 +00:00
|
|
|
|
|
|
|
it 'should raise when length not in 3..7 ' do
|
|
|
|
RuCaptcha.configure do
|
|
|
|
self.length = 2
|
|
|
|
end
|
|
|
|
#expect(RuCaptcha.generate()).to raise_error('length config error, value must in 3..7')
|
|
|
|
expect { RuCaptcha.generate() }.
|
|
|
|
to raise_error('length config error, value must in 3..7')
|
|
|
|
RuCaptcha.configure do
|
|
|
|
self.length = 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should work when length in 3..7 ' do
|
|
|
|
RuCaptcha.configure do
|
|
|
|
self.length = 5
|
|
|
|
end
|
|
|
|
res = RuCaptcha.generate()
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(5)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should len equal 3' do
|
|
|
|
res = RuCaptcha.create(1, 3, 1)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(3)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should len equal 4' do
|
|
|
|
res = RuCaptcha.create(1, 4, 1)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(4)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should len equal 5' do
|
|
|
|
res = RuCaptcha.create(1, 5, 1)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(5)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should len equal 6' do
|
|
|
|
res = RuCaptcha.create(1, 6, 1)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(6)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should len equal 7' do
|
|
|
|
res = RuCaptcha.create(1, 7, 0)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(7)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
2017-12-07 09:04:25 +00:00
|
|
|
it 'should work with strikethrough enable' do
|
2017-12-07 08:49:42 +00:00
|
|
|
res = RuCaptcha.create(1, 7, 1)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(7)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
2017-12-07 09:04:25 +00:00
|
|
|
it 'should work with strikethrough disable' do
|
2017-12-07 08:49:42 +00:00
|
|
|
res = RuCaptcha.create(1, 7, 0)
|
|
|
|
expect(res.length).to eq(2)
|
|
|
|
expect(res[0].length).to eq(7)
|
|
|
|
expect(res[1]).not_to eq(nil)
|
|
|
|
end
|
2016-11-08 03:18:07 +00:00
|
|
|
end
|
2015-10-30 03:32:02 +00:00
|
|
|
end
|