Skip to content

Instantly share code, notes, and snippets.

@mclosson
Created May 7, 2016 03:31
Show Gist options
  • Save mclosson/5bd2a085b03934e6a4603a4969a3af23 to your computer and use it in GitHub Desktop.
Save mclosson/5bd2a085b03934e6a4603a4969a3af23 to your computer and use it in GitHub Desktop.
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