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

テストコード実装準備1(自分用)

Posted at

gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'faker'

% bundle install

サーバーを再起動し、
% rails g rspec:install

.rspecに
--format documentation
を足す

spec/rails_helper.rbに

I18n.locale = "en"
を記述し、エラーメッセージを英語化する。

「spec」ディレクトリの中に「factories」ディレクトリを作成し、「モデル.rb」 作成する。
その中にFactoryBotの内容を記述。

例:

FactoryBot.define do
factory :message do
content {Faker::Lorem.sentence}
association :user
association :room

after(:build) do |message|
  message.image.attach(io: File.open('public/images/test_image.png'), filename: 'test_image.png')
end

end
end

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?