Sha256: a1c2732098ebfbdaf1d35b3ce5cd2d83ab3df5e8c9fa86707985fd3cd453ca1c
Contents?: true
Size: 1.67 KB
Versions: 5
Compression:
Stored size: 1.67 KB
Contents
# -*- encoding: utf-8 -*- require File.join(File.dirname(__FILE__), "/spec_helper") describe MetaInspector::Request do describe "read" do it "should return the content of the page" do page_request = MetaInspector::Request.new(url('http://pagerankalert.com')) page_request.read[0..14].should == "<!DOCTYPE html>" end end describe "content_type" do it "should return the correct content type of the url for html pages" do page_request = MetaInspector::Request.new(url('http://pagerankalert.com')) page_request.content_type.should == "text/html" end it "should return the correct content type of the url for non html pages" do image_request = MetaInspector::Request.new(url('http://pagerankalert.com/image.png')) image_request.content_type.should == "image/png" end end describe 'exception handling' do before(:each) do FakeWeb.allow_net_connect = true end after(:each) do FakeWeb.allow_net_connect = false end it "should handle timeouts" do impatient = MetaInspector::Request.new(url('http://example.com'), timeout: 0.0000000000001) expect { impatient.read.should be_nil }.to change { impatient.exceptions.size } impatient.exceptions.first.class.should == Timeout::Error end it "should handle socket errors" do nowhere = MetaInspector::Request.new(url('http://caca232dsdsaer3sdsd-asd343.org')) expect { nowhere.read.should be_nil }.to change { nowhere.exceptions.size } nowhere.exceptions.first.class.should == SocketError end end private def url(initial_url) MetaInspector::URL.new(initial_url) end end
Version data entries
5 entries across 5 versions & 1 rubygems