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

Rspecでテストを作成する時、各ファイル毎に require 'rails_helper' と書くのを省略する

Last updated at Posted at 2021-01-24

環境

Mac OS X
Ruby: 2.7.1
Rails: 6.0.3.4

課題

RSpecでテストを作成する時、何も設定しないと以下のように記述すると思う

model_spec.rb
require 'rails_helper'
Rspec.describe Model, type: :model do

~以下テスト~

しかしrequire 'rails_helper'と毎回記述するのは面倒くさいので省略できないか調査した

解決法

.rspecに以下のコードを追加する

.rspec
--require rails_helper

結果

以下のようにしてもテストが動き、コードを削減することができた

model_spec.rb
Rspec.describe Model, type: :model do

~以下テスト~

参考記事

最後に

お読みいただきありがとうございました。

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?