Testing (RSpec) with Devise's confirmable module

后端 未结 7 1120
不思量自难忘°
不思量自难忘° 2020-12-24 13:06

It\'s my understanding that Rails\' testing environment is torn down and rebuilt before each test...so how do I test a controller that requires that a user be logged in and

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 13:40

    Try stubbing active?

    @user = Factory.create(:user)
    @user.stub(:active?).and_return(true)
    sign_in @user
    

    You might also need to stub confirmed?, I'm not too familiar with Devise.

提交回复
热议问题