Skip to content

Instantly share code, notes, and snippets.

# spec/spec_helper.rb
RSpec.configure do |config|
config.before(:each) do
stub_request(:any, /supercool.com/).to_rack(FakeSuperCool)
end
end
require 'sinatra/base'
class FakeSuperCool < Sinatra::Base
get "/api/" do
if params[:keywords] == 'ruby'
json_response 200, 'super_cool_ruby_response.json'
elsif params[:keywords] == 'rubular'
json_response 200, 'super_cool_no_results_response.json'
elsif params[:api_key] == '123'
json_response 200, 'super_cool_bad_api_key_response.json'
class TwitterService
attr_reader :connection, :user
def initialize(user)
@user = user
@connection = Faraday.new(url: "https://api.twitter.com/")
end
def friends
response = connection.get do |req|
class Friend
def self.service(current_user)
TwitterService.new(current_user)
end
def self.get_friends(current_user)
friends_json = service(current_user).friends
friends = friends_json.map do |friend|
build_object(friend)
end