Topic: Controller testing with mocks

I'm struggling with my first attempt at TDD in Rails with RSpec. So I ended up implementing a couple of controller actions first, now I'm attempting to go back and test.

Here's the code:

class SessionsController < ApplicationController
  skip_before_filter :graph
  @@oauth =['facebook']['app_id'], APP_CONFIG['facebook']['secret'], "#{APP_CONFIG["root_url"]}sessions/create/")

  def new
    redirect_to @@oauth.url_for_oauth_code

  def create
    access_token = @@oauth.get_access_token(params[:code])
    graph =
    me = graph.get_object('me')
    user = User.find_by_fb_id(me['id'])
    if user
      user.access_token = access_token
      user ={:fb_id => me['id'], :access_token => access_token})
    session[:user_id] =
    redirect_to :controller => 'pages', :action => 'index'

And here's the explanation:

I'm using the Koala gem for Facebook. It has an OAuth class for authenticating, and a GraphAPI class for interacting with the API.

SessionsController#new just redirects to Facebook, where the user grants permissions.

Once permissions are granted, Facebook redirects to SessionsController#create with a code parameter in the query string. Passing that code as an argument to @@oauth.get_access_token requests a permanent OAuth access token from Facebook.

That access token is then passed as an argument when instantiating a new GraphAPI object.

The graph.get_object('me') call gets a hash of user information from the Facebook Graph API.

Everything else is vanilla Rails.

The spec for SessionsController#new is really easy:

describe SessionsController do
  context 'new' do
    it "should redirect to Facebook's permission page" do
      get :new
      response.should be_redirect

But I'm at a loss for SessionsController#create since it requires mocking of three Facebook API calls. After reading good things about RR, that's what I attempted to use for test doubling, but I didn't come up with anything worth sharing here.

Can someone lend a hand to get me started? I'm open to using RSpec, RR, Mocha or anything else for mocking.