captcha_spec.rb
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'lib/math_captcha/captcha'
require 'base64'
describe Captcha do
describe "with a random task" do
before(:each) do
@captcha = Captcha.new
end
it "should have arguments and an operator" do
@captcha.x.should_not be_nil
@captcha.y.should_not be_nil
@captcha.operator.should_not be_nil
end
it "should use numbers bigger than zero" do
@captcha.x.should > 0
@captcha.y.should > 0
end
it "should offer a human readable task" do
@captcha.task.should =~ /^\d+\s*[\+\-\*]\s*\d+$/
end
it "should have a secret to use in forms" do
@captcha.to_secret.should_not be_nil
@captcha.to_secret.should_not be_empty
end
it "should re-use its cipher" do
@captcha.send(:cipher).should == @captcha.send(:cipher)
end
it "should have a base64 encoded secret" do
lambda { Base64.decode64(@captcha.to_secret).should_not be_nil }.should_not raise_error
end
describe "re-creating another from secret" do
before(:each) do
@secret = @captcha.to_secret
@new_captcha = Captcha.from_secret(@secret)
end
it "should have the same arguments and operator" do
@new_captcha.x.should == @captcha.x
@new_captcha.y.should == @captcha.y
@new_captcha.operator.should == @captcha.operator
end
it "should have the same string" do
@new_captcha.task.should == @captcha.task
end
end
end
end