Skip to content

Instantly share code, notes, and snippets.

@ogawatti
Created March 31, 2015 07:16
Show Gist options
  • Save ogawatti/231f55280ded3d6a2e0e to your computer and use it in GitHub Desktop.
Save ogawatti/231f55280ded3d6a2e0e to your computer and use it in GitHub Desktop.
mock_by_webmock_for_fb_graph.rb
require 'fb_graph'
require 'webmock'
require 'dotenv'
require 'nenv'
include WebMock::API
Dotenv.load
class MyRackApp
def call(env)
[ 500, {}, [ "{}" ] ]
end
end
class MyMiddleware
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.path == "/me"
[ 200, {}, [ "{}" ] ]
else
@app.call(env)
end
end
end
app = MyRackApp.new
app = MyMiddleware.new(app)
stub_request(:any, /graph\.facebook\.com/).to_rack(app)
user = FbGraph::User.me(Nenv.access_token).fetch
p user.name #=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment