[Rails4]StrongParameterとFactoryGirlを用いたRspecのスタブ定義
StrongParameterの使用が前提となったRails4では、Rails3でRspecのテスト時にparamsをスタブ定義しつつFactory Girlを使ってデータを生成していると、以下のようなエラーが起きる場合がある。
no implicit conversion of Symbol into String
下記Qiitaに書かれているように、Factory GirlのKeyはHashなのに対し、StrongParameterはKeyがStringであるために発生するっぽい。 http://qiita.com/hisatake/items/ac3a9ea8b681a628e695
なので、この場合paramsのstabにFactory Girlで生成したHashを代入する際に、以下のように定義するとよい。
controller.stub(:params).and_return(ActionController::Parameters.new(FactoryGirl_data))
参考:http://stackoverflow.com/questions/16574509/rspec-testing-strong-parameters













