This repository has been archived by the owner on Feb 8, 2019. It is now read-only.
/
yandex_cleanweb_test.rb
92 lines (73 loc) · 2.29 KB
/
yandex_cleanweb_test.rb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# encoding: utf-8
require "test_helper"
describe YandexCleanweb do
context "without api key" do
before do
YandexCleanweb.api_key = nil
end
describe "#spam?" do
it "raise an error" do
-> {
YandexCleanweb.spam?("anything")
}.must_raise YandexCleanweb::NoApiKeyException
end
end
describe "#get_captcha" do
it "raise an error" do
-> {
YandexCleanweb.get_captcha("anything")
}.must_raise YandexCleanweb::NoApiKeyException
end
end
describe "#valid_captcha?" do
it "raise an error" do
-> {
YandexCleanweb.valid_captcha?("anything", "anything", 123)
}.must_raise YandexCleanweb::NoApiKeyException
end
end
end
context "with empty api key" do
before do
YandexCleanweb.api_key = ""
end
it "raise an error" do
-> {
YandexCleanweb.spam?("anything")
}.must_raise YandexCleanweb::NoApiKeyException
end
end
context "with api key" do
before do
YandexCleanweb.api_key = "cw.1.1.20121227T080449Z.51de1ee126e5ced6.f4f417fb55727520d7e39b00cf5393d4b1ca5e78"
end
describe "#spam?" do
describe "simple check" do
it "works" do
YandexCleanweb.spam?("фраза").must_equal false
YandexCleanweb.spam?("недорого увеличение пениса проститутки").must_equal false
end
end
describe "advanced mode" do
it "works" do
YandexCleanweb.spam?(:body_plain => "my text", :ip => "80.80.40.3").must_equal false
end
it "with some html" do
result = YandexCleanweb.spam?(:body_html => "some spam <a href='http://spam.com'>spam link</a>")
result[:id].wont_be_empty
result[:links].must_be_empty
end
end
end
describe "#get_captcha + #valid_captcha?" do
it "works for not valid captchas" do
result = YandexCleanweb.spam?(:body_html => "some spam <a href='http://spam.com'>spam link</a>")
captcha = YandexCleanweb.get_captcha(result[:id])
captcha[:url].wont_be_empty
captcha[:captcha].wont_be_empty
valid = YandexCleanweb.valid_captcha?(result[:id], captcha[:captcha], "1234")
valid.must_equal false
end
end
end
end