Created
May 7, 2016 03:31
-
-
Save mclosson/5bd2a085b03934e6a4603a4969a3af23 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 'httparty' | |
require 'minitest/autorun' | |
require 'minitest/mock' | |
require 'httparty' | |
class GoogleClient | |
BASE_URI = "http://google.com" | |
def query(query_string) | |
http_client.get(BASE_URI + '/search?q=' + query_string.tr(" ", "+")) | |
end | |
private | |
def http_client | |
HTTParty | |
end | |
end | |
class GoogleClientTest < Minitest::Test | |
def test_calls_http_client | |
mock = Minitest::Mock.new | |
mock.expect(:get, nil, ["http://google.com/search?q=cats"]) | |
client = GoogleClient.new | |
client.stub(:http_client, mock) do | |
client.query('cats') | |
end | |
mock.verify | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment