spec/lib/rawler_spec.rb in rawler-0.1.5 vs spec/lib/rawler_spec.rb in rawler-0.1.6
- old
+ new
@@ -10,10 +10,44 @@
before(:each) do
Rawler.stub!(:output).and_return(output)
register('http://example.com', site)
end
+ describe "logfile" do
+ it "should have default value" do
+ url = 'http://example.com'
+
+ Rawler::Base.new(url, output)
+ Rawler.logfile.should == Rawler::Base::DEFAULT_LOGFILE
+ end
+
+ it "should honor logfile option" do
+ url = 'http://example.com'
+ logfile = 'custom_logfile'.freeze
+
+ Rawler::Base.new(url, output, :logfile => logfile)
+ Rawler.logfile.should == logfile
+ end
+ end
+
+ describe "log" do
+ it "should be turned off by default" do
+ url = 'http://example.com'
+
+ Rawler::Base.new(url, output)
+ Rawler.log.should == false
+ end
+
+ it "should be turned on when assigning custom logfile" do
+ url = 'http://example.com'
+ logfile = 'custom_logfile'
+
+ Rawler::Base.new(url, output, :logfile => logfile)
+ Rawler.log.should == true
+ end
+ end
+
describe "url encoding" do
it "should encode url" do
original = 'http://example.com/写程序容易出现的几个不好的地方'
expected = 'http://example.com/%E5%86%99%E7%A8%8B%E5%BA%8F%E5%AE%B9%E6%98%93%E5%87%BA%E7%8E%B0%E7%9A%84%E5%87%A0%E4%B8%AA%E4%B8%8D%E5%A5%BD%E7%9A%84%E5%9C%B0%E6%96%B9'
@@ -89,9 +123,18 @@
register('http://example.com/foo', '', 301, :location => 'http://example.com/bar')
register('http://example.com/bar', '')
output.should_receive(:warn).with('301 - http://example.com/foo - Called from: http://example.com - Following redirection to: http://example.com/bar')
output.should_receive(:info).with('200 - http://example.com/bar')
+
+ rawler.validate
+ end
+
+ it "should handle circular redirections" do
+ register('http://example.com', '<a href="/foo">foo</a>')
+ register('http://example.com/foo', '', 301, :location => 'http://example.com/foo')
+
+ output.should_receive(:warn).with('301 - http://example.com/foo - Called from: http://example.com - Following redirection to: http://example.com/foo')
rawler.validate
end
end