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】エラー:NameError: uninitialized constant FactoryBot

Posted at

環境

ruby 2.7.1
Rails 6.1.3.2
Docker version 20.10.7, build f0df350
docker-compose version 1.29.2, build 5becea4c

状況

テストを実行するとエラーを吐く

$ docker-compose exec app bundle exec rspec spec/requests/XXXXXXX_spec.rb

Failure/Error: config.include FactoryBot::Syntax::Methods

NameError:
  uninitialized constant FactoryBot
spec/rails_helper.rb
RSpec.configure do |config|
  #略
  config.include FactoryBot::Syntax::Methods
end
Gemfile.
group :test do
     #略
  gem 'factory_bot_rails'
end

解決方法

Gemfileで開発とテスト両方でインストール

Gemfile.
group :development, :test do
    #略
  gem 'factory_bot_rails'
end

ちゃんとドキュメント通りにインストールするのは大事ですね‥

参考

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?