はじめに
自作のRailsアプリケーションでRspecを利用したので備忘録として残しておきます。
Gemの追加
Gemfile
gem 'rspec-rails'
Gem追加後以下のコマンドを入力します。
$ rails g rspec:install
factory_bot
factory_botとはテストモデルの自動生成ができるGemです
gem 'factory_bot_rails'
インストールすると以下のようにダミーデータを作成することができます。
spec/factories/user.rb
FactoryBot.define do
factory :user do
name {Faker::Name.name}
email {Faker::Internet.email}
password {'password'}
password_confirmation {'password'}
end
end
以上でRpecの下準備が完了です