Created
February 9, 2012 10:08
-
-
Save jimweirich/1779028 to your computer and use it in GitHub Desktop.
Vital Ruby Advanced Lab 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
class UrlFetcher | |
def fetch(url) | |
open(url) { |f| f.read } | |
rescue StandardError => ex | |
nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec-given' | |
require './url_fetcher' | |
describe UrlFetcher do | |
Given(:fetcher) { UrlFetcher.new } | |
context "with good url" do | |
Then { fetcher.fetch("http://onestepback.org").should =~ /<html/i } | |
end | |
context "with bad url path" do | |
Then { fetcher.fetch("http://onestepback.org/this_path_does_not_exist").should be_nil } | |
end | |
context "with bad url host" do | |
Then { fetcher.fetch("http://this_host_does_not_exist.com/").should be_nil } | |
end | |
context "with an ill-formed url" do | |
Then { fetcher.fetch("http://no_dot_com").should be_nil } | |
end | |
context "with an ill-formed protocol" do | |
Then { fetcher.fetch("bad_protocol://onestepback.org").should be_nil } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment