Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Created February 9, 2012 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jimweirich/1779028 to your computer and use it in GitHub Desktop.
Save jimweirich/1779028 to your computer and use it in GitHub Desktop.
Vital Ruby Advanced Lab 1
require 'open-uri'
class UrlFetcher
def fetch(url)
open(url) { |f| f.read }
rescue StandardError => ex
nil
end
end
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