Stubbing Devise in rSpec and Rails3

You can try mocking the underlying warden (https://github.com/wardencommunity/warden/wiki) object which devise relies upon, here is a link to some details on how you can accomplish this with RSpec: http://www.michaelharrison.ws/weblog/?p=349 (entry covers some other topics as well, the solution you want is towards the bottom of the page.)


I found that it is now pretty easy to do this. There was a problem with rspec2 and devise, but is now solved. I guess you would need to update your gems. Then you can write

require 'spec_helper'

describe DoStuffController do
  include Devise::TestHelpers

  before (:each) do
    @user = Factory.create(:user)
    sign_in @user
  end

  describe "GET 'index'" do
    it "should be successful" do
      get 'index'
      response.should be_success
    end
  end
end

[UPDATE] On the devise wiki there is now a detailed (and probably more up-to-date) description.