-
-
Notifications
You must be signed in to change notification settings - Fork 191
Mocking API Calls
FbGraph is using its own Graph API mocking helper gem called “fb_graph-mock”
https://github.com/nov/fb_graph-mock
It works as HTTP level mocking like webmock/fakeweb, but optimized for mocking Facebook Graph API request & response.
If you are making a new mocked JSON response file, you have 2 ways to do so.
- put the JSON file in spec/mock_json in fb_graph gem itself
- register the JSON file to fb_graph-mock gem and make a separate pull request to the gem
If you choose 1, I’ll move your JSON file to fb_graph-mock gem, so that all fb_graph users can share your mocked JSON for their own tests.
In fb_graph-mock gem, there are 2 ways to register a mock, with and without block.
# with block
mock_graph :get, 'me', 'users/me_private', :access_token => 'access_token' do
user = FbGraph::User.me('access_token').fetch
user.website.should == 'http://matake.jp'
end
# without block
mock_graph :get, 'me', 'users/me_private', :access_token => 'access_token'
user = FbGraph::User.me('access_token').fetch
user.website.should == 'http://matake.jp'
With block, fb_graph-mock asserts the mocked request is actually called in the block.
Without block, it doesn’t do such assertion.
Latter way is for use out of fb_graph gem, so please use block if you are writing specs for fb_graph itself.