LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby on Rails】RSpecの導入方法

Last updated at Posted at 2022-11-14

RSpecの導入方法

Gemfileに追記

GemfileにRspec, Factorybot, Fakerを追加するための記述を追記。
この時、:test 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]
  #ここに以下3行を書き足す
  gem 'rspec-rails', '~> 4.0.0'
  gem 'factory_bot_rails'
  gem 'faker'
end

ターミナル実行

ターミナルで以下を実行。

ターミナル
bundle install
rails g rspec:install

以下の実行結果が表示される。
specフォルダー内に「spec_helper.rb」「rails_helper.rb」の二つのファイルが作成されている。

ターミナル実行結果
create  .rspec
create  spec
create  spec/spec_helper.rb
create  spec/rails_helper.rb

Rspecに設定を追記

「.rspec」に「--format documentation」を追記。

.rspec
--require spec_helper
+ --format documentation

#techcamp136期

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