3
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を導入した時、詰まったこと(NameError: uninitialized constant FactoryBot)

Last updated at Posted at 2020-02-19

#エラー内容
Rspecを使ったテストを実行する際、以下のようなエラーが発生。

An error occurred while loading ./spec/models/board_spec.rb.
Failure/Error: config.include FactoryBot::Syntax::Methods

NameError:
  uninitialized constant FactoryBot

#行ったこと
参考
http://yurafuca.hatenablog.com/entry/2018/06/28/190842
https://qiita.com/Sa2Knight/items/90d32c9b8493d6bf94b3
・gemにrspec-railsを導入済み
・rspecの初期ファイルを作成済み

#エラー原因
spec/rails_helper.rbの一番最初の行にいきなりconfig.include FactoryBot::Syntax::Methodsを記入してしまった。
下記が正しい書き方。

RSpec.configure do |config|
  # 中略
  config.include FactoryBot::Syntax::Methods
end
3
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
3
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?