LoginSignup
0
0

More than 1 year has passed since last update.

テストコードでimageが空の時について、エラーになってしまう

Posted at
spec>models>item_spec.rb
it "imageが空だと登録できない" do
        @item.image = ''
        @item.valid?
        expect(@item.errors.full_messages).to include("Image can't be blank")
      end

:エラー文
Failure/Error: expect(@item.errors.full_messages).to include("Image can't be blank")
expected [] to include "Image can't be blank"
# ./spec/models/item_spec.rb:22:in `block (4 levels) in

spec>models>item_spec.rb
it "imageが空だと登録できない" do
        @item.image = nil
        @item.valid?
        expect(@item.errors.full_messages).to include("Image can't be blank")
      end

「’’」を「nil」に変えるだけで解決しました。

※ これだけで1〜2時間もエラー解決に時間かかっちゃったよ〜〜〜(泣)

0
0
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
0
0