Improve tests rspec syntax

master
Guillaume DOTT 2013-01-14 14:30:07 +01:00
parent 2f87b63c18
commit a1a7beb464
2 changed files with 24 additions and 26 deletions

View File

@ -2,20 +2,20 @@ require "spec_helper"
describe ProjectHoneypot::Base do describe ProjectHoneypot::Base do
describe "with honeypot response" do describe "with honeypot response" do
let(:base) { ProjectHoneypot::Base.new("abcdefghijklmnop") }
before(:each) do before(:each) do
flexmock(Net::DNS::Resolver, :start => flexmock("answer", :answer => ["somedomain.httpbl.org A Name 127.1.63.5"])) flexmock(Net::DNS::Resolver, :start => flexmock("answer", :answer => ["somedomain.httpbl.org A Name 127.1.63.5"]))
@base = ProjectHoneypot::Base.new("abcdefghijklmnop")
end end
it "returns a Url object" do it "returns a Url object" do
url = @base.lookup("127.10.10.5") url = base.lookup("127.10.10.5")
url.should be_a ProjectHoneypot::Url url.should be_a ProjectHoneypot::Url
url.last_activity.should == 1 url.last_activity.should == 1
url.score.should == 63 url.score.should == 63
end end
it "looks up non-ip addresses" do it "looks up non-ip addresses" do
url = @base.lookup("iamspam.com") url = base.lookup("iamspam.com")
Net::DNS::Resolver.should_receive(:start).with("iamspam.com") Net::DNS::Resolver.should_receive(:start).with("iamspam.com")
end end
end end

View File

@ -2,53 +2,51 @@ require "spec_helper"
describe ProjectHoneypot::Url do describe ProjectHoneypot::Url do
describe "with honeypot response" do describe "with honeypot response" do
before(:each) do let(:url) { ProjectHoneypot::Url.new("127.0.0.1", "127.1.63.3") }
@url = ProjectHoneypot::Url.new("127.0.0.1", "127.1.63.3")
end
it "is safe" do it "is safe" do
@url.should_not be_safe url.should_not be_safe
@url.safe?(score: 63).should be_false url.safe?(score: 63).should be_false
@url.safe?(score: 64).should be_true url.safe?(score: 64).should be_true
@url.safe?(last_activity: 1).should be_false url.safe?(last_activity: 1).should be_false
@url.safe?(last_activity: 2).should be_true url.safe?(last_activity: 2).should be_true
@url.safe?(last_activity: 2, score: 64).should be_true url.safe?(last_activity: 2, score: 64).should be_true
@url.safe?(last_activity: 1, score: 64).should be_false url.safe?(last_activity: 1, score: 64).should be_false
@url.safe?(last_activity: 2, score: 63).should be_false url.safe?(last_activity: 2, score: 63).should be_false
@url.safe?(offenses: [:comment_spammer]).should be_true url.safe?(offenses: [:comment_spammer]).should be_true
@url.safe?(offenses: [:suspicious, :comment_spammer]).should be_false url.safe?(offenses: [:suspicious, :comment_spammer]).should be_false
end end
it "has the correct latest activity" do it "has the correct latest activity" do
@url.last_activity.should == 1 url.last_activity.should == 1
end end
it "has the correct score" do it "has the correct score" do
@url.score.should == 63 url.score.should == 63
end end
it "has the correct offenses" do it "has the correct offenses" do
@url.offenses.should include(:suspicious) url.offenses.should include(:suspicious)
@url.offenses.should include(:harvester) url.offenses.should include(:harvester)
@url.offenses.should_not include(:comment_spammer) url.offenses.should_not include(:comment_spammer)
@url.should be_suspicious url.should be_suspicious
@url.should be_harvester url.should be_harvester
@url.should_not be_comment_spammer url.should_not be_comment_spammer
end end
end end
describe "with search engine honeypot response" do describe "with search engine honeypot response" do
subject { @url = ProjectHoneypot::Url.new("127.0.0.1", "127.0.9.0") } subject { ProjectHoneypot::Url.new("127.0.0.1", "127.0.9.0") }
it { should be_safe } it { should be_safe }
it { should be_search_engine } it { should be_search_engine }
end end
describe "with nil honeypot response" do describe "with nil honeypot response" do
subject { @url = ProjectHoneypot::Url.new("127.0.0.1", nil) } subject { ProjectHoneypot::Url.new("127.0.0.1", nil) }
it { should be_safe } it { should be_safe }
end end
end end