Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Created July 12, 2017 18:22
Show Gist options
  • Select an option

  • Save patmaddox/1d5b41e66e6ed4d2f0c75b7bd18a6375 to your computer and use it in GitHub Desktop.

Select an option

Save patmaddox/1d5b41e66e6ed4d2f0c75b7bd18a6375 to your computer and use it in GitHub Desktop.
require 'net/http'
class PageFetcher
def fetch(url)
@response = Net::HTTP.get_response URI(url)
Response.new @response
end
class Response
def initialize(response)
@response = response
end
def success?
@response.code == '200'
end
end
end
describe PageFetcher do
describe '#fetch(url)' do
let(:response) { double('response', code: '200') }
before do
allow(Net::HTTP).to receive(:get_response)
.and_return(response)
end
it 'is successful' do
expect(PageFetcher.new.fetch('http://example.com')).to be_success
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment