[RSpec] テストコードでの Devise の使い方いろいろ

Ruby on Rails + RSpec でテストコードを書くときの Devise の使い方いろいろメモ。

主にここを読む。

How To: Controllers and Views tests with Rails 3 (and rspec) · plataformatec/devise Wiki はてなブックマーク - How To: Controllers and Views tests with Rails 3 (and rspec) · plataformatec/devise Wiki

■ current_user にスタブを使う

Controllerのテスト

before do
  controller.stub!(:current_user).and_return(FactoryGirl.create(:user))
end

他にも。

deviseを使ったコントローラのテスト #Rails #Ruby #devise #Rspec – Qiita はてなブックマーク - deviseを使ったコントローラのテスト #Rails #Ruby #devise #Rspec - Qiita