Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.