Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

RSpecを導入した時、詰まったこと(NameError: uninitialized constant FactoryBot)

More than 1 year has passed since last update.

エラー内容

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
blackpeach7
駆け出しエンジニア向けに情報発信をしております。初心者向けにエラーで詰まった所や、まとめ記事をあげていきます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away