Railsのコントローラのテスト時に、以下のような実行エラーが出ます。原因がわかりません。
以下に実行結果およびコードを記載します。
原因がお分かりになる方、お教えいただけないでしょうか?
よろしくお願いします。
- CommentsControllerのcreateアクションをテストする
RSpec.describe CommentsController, type: :controller do let(:post) { Post.create(user_id: 1, title: 'title', content: 'content') } describe '#create' do it 'create new comment' do expect { post :create, post_id: post.id, comment: { body: 'body' } }.to change { Comment.count }.from(0).to(1) end end end
- 実行結果
Failures: 1) CommentController#create create new commnet Failure: post :create, post_id: post.id, comment: { body: 'body' } ArgumentError: wrong number of arguments (2 for 0)
- CommentsController.rb
class CommentsController < ApplicationController end
- Comment.rb
class Comment < ActiveRecord::Base validates :post, presence: true validates :body, presence: true #postとcommnetsは1対多 belongs_to :post end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。