rucaptcha/spec/cache_spec.rb

27 lines
743 B
Ruby
Raw Normal View History

require 'spec_helper'
describe RuCaptcha::Cache do
2016-05-25 03:08:48 +00:00
before(:all) do
RuCaptcha::Captcha.send(:prepend, RuCaptcha::Cache)
end
describe '.random_chars_with_cache' do
it 'should generate max chars by config.cache_limit' do
allow(RuCaptcha.config).to receive(:cache_limit).and_return(5)
items = []
2016-05-25 03:07:26 +00:00
100.times do
items << RuCaptcha::Captcha.random_chars
end
2016-05-25 03:07:26 +00:00
expect(items.uniq.length).to eq RuCaptcha.config.cache_limit
expect(RuCaptcha::Captcha.cached_codes).to eq items.uniq
end
end
describe '.create' do
it 'should work' do
2016-05-25 03:07:26 +00:00
expect(RuCaptcha::Captcha).to receive(:create).and_return('aabb')
expect(RuCaptcha::Captcha.create('abcd')).to eq('aabb')
end
end
end