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 5 years have passed since last update.

[Rails]Rspecの下準備

0
Posted at

はじめに

自作の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の下準備が完了です

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?