LoginSignup
6
3

More than 5 years have passed since last update.

ControllerのRspecを書いていて地味に嫌だったエラー

Posted at

Postというオブジェクト名のせいで地味に嫌なエラーにあたったので書いておく

PostsControllerのrspecを書いていたら、「post」という名前のせいで挙動がおかしくなった。

コントローラのテストでpostという名前でfactoryからcreateした

let!(:post) { create(:post, user: post_user) }

で、controllerの以下のようなテストを動かすと

it 'コメントが作成されること' do
    expect do
        post :create, params: valid_attributes
    end.to change(Comment, :count).by(1)
end

argment error?なんで?

wrong number of arguments (given 2, expected 0)

postという命名がpostメソッドと被ってたらしくこうしたら直った

let!(:commented_post) { create(:post, user: post_user) }
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3