0
1

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.

Rspec導入まとめ

Last updated at Posted at 2019-02-26

最低限の導入手順を記載
後ほどいつもやりそうな初期設定を追記

事前設定

config/database.ymlにtestの指定がある事

config/database.yml
test:
  <<: *default
  database: プロジェクト名_test

テストを導入したい環境に以下のgemを指定している事

Gemfile
group :development, :test do
    
    
  gem 'rspec-rails', '~> 3.6'
  gem 'factory_bot_rails'
  gem 'database_cleaner'
    
    
end

導入

rspecに必要なモジュールをインストールする

bundle install
rspec:install
rails generate rspec:install

下記を追記

spec/support/factory_bot.rb
RSpec.configure do |config|
  config.include FactoryBot::Syntax::Methods
end

テスト用DBの作成

rails db:migrate RAILS_ENV=test

実行方法

rspec spec/対象の階層下 or ファイル
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?