###前提・実現したいこと
RSpecでControllerのテストケースを作成しているのですが、getでパラメータを引数渡すところがうまくできません。
どうすればeventModelのidをちゃんと渡してshow画面のレスポンスを得るテストケースを作成することができるのでしょうか?
ご教授お願いいたします!
###発生している問題・エラーメッセージ
Failure/Error: get :show, event: Event.new(:event_create) ArgumentError: When assigning attributes, you must pass a hash as an argument.
###該当のソースコード
Ruby
#/events_controller_spec.rb describe "Get #show" do it "引数として渡されたEventModelのidに対応したshow画面が呼び出されること" do get :show, event: attributes_for(:event_create) expect(assigns[:event]).to render_template :show end end
Ruby
#/factories/events.rb FactoryGirl.define do factory :event_create, class: Event do title "title" alternative_date1 Date.tomorrow author_attributes { attributes_for(:user) } end end #/factories/users.rb FactoryGirl.define do factory :user, class: User do name "name" end end
Ruby
#/events_controllerのshowメソッド #パスは/events/:id def show @event = Event.find(params[:id]) end
###補足情報(言語/FW/ツール等のバージョンなど)
RSpec -v "3.5.2"
まだ回答がついていません
会員登録して回答してみよう