1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Active StrageをRSpecでテスト

Posted at

##はじめに
Active Strageを使用し、画像投稿ができるアプリを制作中です。
その際のテストの書き方の例を紹介します。

##factories

FactoryBot.define do
  factory :post do
...
      trait :post_image do
        image {
          fixture_file_upload("app/assets/images/XXX.PNG")
        }
      end
...

##letを定義


let(定義名) { 定義の内容 }

let(:post_image) { FactoryBot.create(:post_image) }

##使用する(例)

post = FactoryBot.create(:post,:post_image)

##参考にさせて頂いたサイト
https://qiita.com/maca12vel/items/ee4d16827f24f69080ae
https://shuttodev.hatenablog.com/entry/2019/09/04/015756

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?