railsのcontrollerのテスト続き

ちょっとメモ書き。
controllerのテストでcontroller内で定義したメソッドの戻り値のチェックをする時はassiginsメソッドを使う

expect(assigns[:user].name).to eql('testUserName')

例えば上記みたいに。
またそれ以外にresponse.statusでステータスコードをチェックしたり遷移先のテンプレートやレイアウトファイル名、などなど

      it { response.should be_success }
      it { expect(current_user.movies).not_to be_nil }
      it { expect(current_user.movies.size).to eql(2) }
      it { expect(render_with_layout 'application') }
      it { expect(render_template 'index') }

そして後はdeviseなど使っている場合はuser情報をcontroller内にセットするのは

    before do
        allow(controller).to receive(:current_user) { current_user }
      end

みたいに書く
以上メモ書き