Created
July 12, 2017 18:22
-
-
Save patmaddox/1d5b41e66e6ed4d2f0c75b7bd18a6375 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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