Stubbing Devise in rSpec and Rails3

前端 未结 2 1672
闹比i
闹比i 2021-01-30 04:21

How would you stub Devise in Rails 3 with rSpec. I have a UsersController and a User model. Both of which are associated with Devise at the moment, I\'

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 05:05

    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.

提交回复
热议问题