spec/unit/base_spec.rb in rawler-0.0.2 vs spec/unit/base_spec.rb in rawler-0.0.3
- old
+ new
@@ -70,9 +70,39 @@
rawler.send(:add_status_code, url)
rawler.responses[url][:status].should == 302
end
+ it "should save username and password" do
+ rawler = Rawler::Base.new('http://example.com', output, 'my_user', 'secret')
+
+ Rawler.username.should == 'my_user'
+ Rawler.password.should == 'secret'
+ end
+
+ it "should rescue from Errno::ECONNREFUSED" do
+ url = 'http://example.com'
+
+ Rawler::Request.should_receive(:get).and_raise Errno::ECONNREFUSED
+
+ output.should_receive(:puts).with("Connection refused - '#{url}'")
+
+ rawler.send(:add_status_code, url)
+ end
+
+ [Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError].each do |error|
+ it "should rescue from #{error}" do
+ url = 'http://example.com'
+
+ Rawler::Request.should_receive(:get).and_raise error
+
+ output.should_receive(:puts).with("Connection problems - '#{url}'")
+
+ rawler.send(:add_status_code, url)
+ end
+ end
+
end
private
\ No newline at end of file