Rspecのセットアップ
Gemfileの中のgroup :development, :test do ~ endとある「do ~ endの間」に記述
Gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'faker'
end
Gemを記述できたらbundle install
% bundle install
サーバー再起動
% rails s
導入したRspecを使用できるようにする
% rails g rspec:install
テストコードの結果をターミナル上で可視化するため、
.rspecに以下の記述をしましょう。
.rspec
--require spec_helper
# 以下を記述
--format documentation
この記述をすることによってテスト実行時のログがより詳細に表示される。
エラーメッセージを英語に設定
spec/rails_helper.rb
# 中略
I18n.locale = "en"
# RSpec.configure do |config| 〜 end の外に記載
RSpec.configure do |config|
# 中略
end