No description, website, or topics provided.
Pull request Compare This branch is 4 commits ahead, 37 commits behind nov:master.
Latest commit 927be03 Feb 28, 2014 @basdl Merge pull request #1 from net-engine/master
email and username for users
Failed to load latest commit information.
lib/fb_graph Using RSpec 'expect' syntax + cleaning code Dec 6, 2013
spec now 100% coverage Dec 3, 2012
.gitignore first commit Dec 1, 2012
.rspec Using RSpec 'expect' syntax + cleaning code Dec 6, 2013
Gemfile Using RSpec 'expect' syntax + cleaning code Dec 6, 2013
LICENSE.txt first commit Dec 1, 2012
README.rdoc one more wrong code Dec 1, 2012
VERSION v0.1.1 Jan 29, 2013
fb_graph-mock.gemspec json gem is not require :p Dec 1, 2012



Facebook Graph API mocking helper, originally used in fb_graph gem.

This gem simply mock HTTP request & response using webmock gem, and returns pre-registered JSON response.

It means you can use fb_graph-mock gem even with kwala, rest-client, or any other code which access to Facebook Graph API.


gem install fb_graph-mock


In spec_helper.rb

require 'fb_graph/mock'
include FbGraph::Mock
WebMock.disable_net_connect! # Optional

In foo_spec.rb

it do
  mock_graph :get, 'me', 'users/me_private', :access_token => 'access_token' do
    user ='access_token').fetch == ''

it do
  mock_graph :get, 'me', 'users/me_public', :status => [401, 'Unauthorized'] do
    lambda do
      FbGraph::User.fetch :me
    end.should raise_error FbGraph::Unauthorized

More Examples?

You can see lots of samples in fb_graph's specs.

Registered Mocks and Your Custom Mocks

To improve fb_graph and other projects using this gem, keeping mock JSONs are important.

If you find any legacy response format in this gem's mock_json directory, please report an issue or send a pull request with new JSON file.

You can find all registered responses as below.


If it's hard to share your mock JSON (e.g. because of privacy issue), you can use your own response file as below.

file_path = File.join(Rails.root, 'spec/my_own_mock_json/users/me_private.json')
mock_graph :get, 'me', file_path do
  # Do something.

If a file is found at the given file path, this gem uses the file.

Otherwise, this gem search a registered mock JSON file in its own registry.

mock_graph :get, 'me', 'users/albums/arjun_public' do
  # => uses "mock_json/users/albums/arjun_public.json" in this gem.
  # Do something.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.


Copyright © 2012 nov matake. See LICENSE for details.