I am building a rails 4 mounted application with mongoid odm. Everything works fine but rspec tests does not work properly. When I run bundle exec rspec an error occurs saying that:
Factory not registered: cafcaf_user
My user model:
module Cafcaf
class User
include Mongoid::Document
field :username, type: String
field :email, type: String
field :full_name, type: String
field :last_name, type: String
end
end
my spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../spec/test_app/config/environment.rb", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
my user_spec.rb
require 'spec_helper'
module Cafcaf
describe User do
it "has a valid factory" do
FactoryGirl.create(:cafcaf_user).should be_valid
end
it "is invalid without a username"
it "is invalid without an email"
end
end
my factories.rb
FactoryGirl.define do
factory :cafcaf_user, :class => 'User' do
username "MyString"
email "MyString"
full_name ""
last_name "MyString"
end
end
my lib/cafcaf/engine.rb
module Cafcaf
class Engine < ::Rails::Engine
isolate_namespace Cafcaf
config.generators do |g|
g.test_framework :rspec
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end
end
end
my Gemfile
source "https://rubygems.org"
gem 'rails', "~> 4.0.4"
gem 'mongoid', github: 'mongoid/mongoid', tag: 'v4.0.0.beta1'
group :development, :test do
gem 'rspec-rails', '~> 3.0.0.beta2'
gem 'database_cleaner', '~> 1.2.0'
gem 'factory_girl_rails', '~> 4.4.1'
end
my gemspec
$:.push File.expand_path("../lib", __FILE__)
require "cafcaf/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "cafcaf"
s.version = Cafcaf::VERSION
s.authors = ["Your name"]
s.email = ["bla#bla.com"]
s.homepage = "http://ir.io"
s.summary = "Summary of Cafcaf."
s.description = " Description of Cafcaf."
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.add_dependency "rails", "~> 4.0.4"
end
Exactly I do not know ho to proceed. How to use rspec and factory_girs gem in a mounted rails engine app? I have done tons of test but did not find the solution.
I have found the solution by adding the following codes to spec_helper.rb
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f }
Now it works like a charm.
Related
I have been bashing my skull for the past 4 hours.
So basicly i cant login/sign in as a user in my feature test, i am using devise_auth_token gem.
Feature test:
1 require 'rails_helper'
2
3 # TODO: rename unit to features
4 feature 'Access' do
5 before :each do
6 #user = Fabricate :user
7 #user.confirm
8
9 #post = Fabricate :post, user: #user
10 Fabricate :note, post: #post
11 end
12
13 it 'should show error if not loged in' do
14 visit api_posts_path
15 expect(page).to have_content '{"errors":["Authorized users only."]}'
16 end
17
18 it 'should let all user roles view list of posts', format: :js do
19 login_as #user, scope: :user
20 visit api_posts_path
21 binding.pry
My spec helper:
require 'database_cleaner'
require 'devise'
require 'auth'
include Devise::TestHelpers
include Warden::Test::Helpers
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.include Devise::TestHelpers, :type => :controller
config.include Warden::Test::Helpers
config.before :suite do
Warden.test_mode!
end
config.include AuthHelper
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end
It gives me that the user is not authorized.
My gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.6'
gem 'sqlite3'
gem 'uglifier', '>= 1.3.0'
gem 'jbuilder', '~> 2.0'
group :development, :test do
gem 'better_errors'
gem 'binding_of_caller'
gem 'bullet'
gem 'meta_request'
gem 'pry-awesome_print'
gem 'pry-rails'
gem 'quiet_assets'
gem 'rspec-rails', '~> 3.0'
gem 'rubocop', require: false
gem 'fabrication'
gem 'database_cleaner'
gem 'capybara'
end
gem 'devise_token_auth'
gem 'puma'
gem 'rack-cors'
For the specific error you're having I think the most likely cause here is that you don't have config.use_transactional_fixtures = false in your spec_helper, which would mean you're still running with transactional database access in your tests and any objects you create in your tests won't actually be visible to the app in js: true tests. A second issue (not causing this problem) is that you aren't calling Warden.test_reset! in an after block.
The bigger issue here is you appear to be using Capybara to test an API, which Capybara isn't designed for. You probably want to using request specs to test an API.
I keep getting Factory not registered: user (ArgumentError)
when I try to run my test files with factory_girl_rails. I read several post about that and tried to follow each of them without any success. In my gemfile I have the gem 'factory_girl_rails':
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
gem 'letter_opener'
gem 'pry-byebug'
gem 'pry-rails'
gem 'quiet_assets'
gem 'spring'
end
I have a spec folder in my project with different folders inside :
controllers, factories, models, lib and support.
In my spec folder I have a spec_helper.rb :
require 'factory_girl_rails'
FactoryGirl.find_definitions
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.include FactoryGirl::Syntax::Methods
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
end
and a rails_helper.rb :
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'devise'
require_relative 'support/controller_macros'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
end
Inside my factories' folder, I have files for each one of my models for instance tournaments.rb :
require 'factory_girl_rails'
FactoryGirl.define do
factory :tournament do |f|
f.user FactoryGirl.create(:user)
f.accepted [true, false].sample
f.amount { Faker::Number.number(2) }
f.starts_on { Faker::Date.between(2.days.ago, Date.today) }
f.ends_on { Faker::Date.forward(23) }
f.address {Faker::Address.street_address}
f.city { Faker::Address.city }
f.name { Faker::Lorem.sentence }
f.club_organisateur { Faker::Company.name }
f.homologation_number {Faker::Company.swedish_organisation_number}
f.postcode { Faker::Address.postcode }
f.young_fare { Faker::Number.number(2) }
f.iban "jjddjjdjdjdjddj"
f.bic "djdjdjdjdjdjdjdjd"
f.club_email { Faker::Internet.email }
f.region "Ile de France"
end
end
Inside controllers folder, I have for instance tournaments_controller_spec.rb that looks like this :
require 'rails_helper'
require 'factory_girl_rails'
require 'spec_helper'
describe TournamentsController do
render_views
login_user
describe "index" do
it "returns a valid html_body" do
get :index
expect(response.body).to include("Il n'y a pas encore de tournoi référencé sur WeTennis")
end
end
describe "show" do
it "returns a valid tournament si le tournament n'est pas fini" do
get :show
expect(response.body).to include("s'inscrire")
end
end
end
and inside models folder for instance tournament_spec.rb :
require 'rails_helper'
require 'factory_girl_rails'
require 'spec_helper'
describe Tournament do
it "has a valid factory" do
FactoryGirl.create(:tournament).should be_valid
end
it "is invalid without a start date" do
FactoryGirl.build(:tournament, start_date: nil).should_not be_valid
end
it "is invalid without a end date" do
FactoryGirl.build(:tournament, end_date: nil).should_not be_valid
end
it "is invalid without a user" do
FactoryGirl.build(:tournament, user: nil).should_not be_valid
end
end
My users factory looks exactly like the others in folder factories (users.rb)
require 'factory_girl_rails'
FactoryGirl.define do
factory :user do |f|
f.first_name { Faker::Name.first_name}
f.last_name { Faker::Name.last_name }
f.password { Faker::Internet.password}
f.licence_number { Faker::Lorem.sentence }
f.email { Faker::Internet.email }
end
end
same for my user_spec.rb inside my models folder :
require 'rails_helper'
require 'factory_girl_rails'
require 'spec_helper'
describe User do
it "has a valid factory" do
FactoryGirl.create(:user).should be_valid
end
it "is invalid without an email" do
FactoryGirl.build(:user, email: nil).should_not be_valid
end
it "is invalid without a password" do
FactoryGirl.build(:user, password: nil).should_not be_valid
end
end
Why am I getting this error ?
I suspect the problem is your use of the user factory in the tournament factory (and maybe others):
factory :tournament do |f|
f.user FactoryGirl.create(:user)
FactoryGirl allows you to created associated objects quite simply (see the relevant section their documentation). To add an associated object which is created by a factory you can just do:
f.user
This will cause FactoryGirl to create a user object using the equivalent of FactoryGirl.create(:user) when a tournament is created.
Note also that you don't need the f. prefix. It should work find without.
The reason that it is causing an error is that the code FactoryGirl.create(:user) is being executed when your tournament factory loads and the user factory hasn't been loaded at that point. For stuff like: region 'Ile de France it doesn't matter because the string can be evaluated fine but for another factory call it does matter because the factory has to be defined already.
I have set up Rspec with a rails4 app however the tests are returning:
Failure/Error: user = Factory(:user)
NoMethodError:
undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_1:0x007fa08c0d8a98>
Seems like I'm including FactoryGirl incorrectly. I've tried a couple of variations but I can't get it to work.
My Spec Helper:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl_rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include Capybara::DSL, :type => :request
config.include FactoryGirl::Syntax::Methods
end
gem file:
group :development, :test do
gem 'rspec-rails', '~> 2.0'
gem 'factory_girl_rails', :require => false # as per sugestion on SO. Without the require false also fails
gem "capybara"
end
my spec:
require 'spec_helper'
describe "Create Event" do
describe "Log in and create an event" do
it "Allows creation of individual events" do
user = Factory(:user)
visit "/"
end
end
end
and in /spec/factories/users.rb
FactoryGirl.define do
factory :user do |f|
f.email "provider#example.com"
f.password "password"
end
end
How can i get going with factory girl?
Given that you have included:
config.include FactoryGirl::Syntax::Methods
In your RSpec configure block, I'm guessing that the syntax you're looking for is:
user = create(:user)
or:
user = build(:user)
To create a user using FactoryGirl:
user = FactoryGirl.create(:user)
This will use everything you defined in the factory to create the user. You can also override any value, or specify additional values at the same time. For example:
user = FactoryGirl.create(:user, username: 'username', email: 'different-email#example.com)
Alternatively you can use FactoryGirl.build(:user, ...) where you want to make use of the factory to build an instance but not actually save it to the database.
I have a simple rails app which Im trying to introduce elementary tests in. Im following this url.
My application is structured as follows:
Im trying to test the single page: called Main Page.
In spec/features/main_pages_spec.rb I have the following code:
require 'spec_helper'
feature "soadevise" do
feature "Main Page" do
scenario "should have the content 'Main Page' "
visit '/main_page/home'
expect(page).to have_content('Main Page')
end
end
My spec/spec_helper.rb looks like this:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.include Capybara::DSL
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
When I run this command in the terminal:
MRMIOMP0903:soadevise $ bundle exec rspec spec/features/main_pages_spec.rb
I get the following error:
/Users/am/Desktop/x/xx/rails_projects/mysql_apps/soadevise/
spec/features/main_pages_spec.rb:6:
in `block (2 levels) in <top (required)>': undefined method `visit' for #
<Class:0x007fb7237377b0> (NoMethodError)
from /Users/am/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core 2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'
from /Users/am.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'
from /Users/am.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'
My gemfile contains these:
#For testing
group :development, :test do
gem "rspec-rails", "~> 2.14.1"
end
group :test do
gem "selenium-webdriver"
gem "capybara"
end
I refered to this link as well.
Can someone suggest what Im doing wrong?
You're calling feature twice. It should look like this:
require 'spec_helper'
feature "soadevise Main Page" do
scenario "should have the content 'Main Page'" do
visit '/main_page/home'
expect(page).to have_content('Main Page')
end
end
I want to test a model with RSpec but I probably have stumbled on a typo that I just can't find. Can somebody please help me a bit? I've been struggling with it for a long time and just can't find any mistakes. Thank you in advance!
user_spec.rb
require 'spec_helper'
describe User do
it "has a valid factory" do
FactoryGirl.build(:user).should be_valid
end
it "is invalid without an e-mail"
it "is invalid without a correct e-mail"
it "is invalid without a password"
it "is invalid without a matching password confrimation"
end
user.rb
FactoryGirl.define do
factory :user do |f|
f.email "aabb#hh.de"
f.password "ruby"
f.password_confrimation "ruby"
end
end
spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
error
Factory not registered: user
You have your factory definition in the wrong file, according to your question it is in user.rb. This needs to be in a factories.rb in your test folder (spec) if you use rspec
# user.rb
FactoryGirl.define do
factory :user do |f|
f.email "aabb#hh.de"
f.password "ruby"
f.password_confrimation "ruby"
end
end
Change above to this, (Also you don't need the f variable)
# spec/factories.rb
FactoryGirl.define do
factory :user do
email "aabb#hh.de"
password "ruby"
password_confrimation "ruby"
end
end
Also as the comments say, make sure gem 'factory_girl_rails' is in your Gemfile, instead of just gem 'factory_girl'
I had run into the following issue with the structure in my folder factories/
- factories/
-- artists.rb
-- techniques.rb
artists.rb
FactoryBot.define do
factory :artist do
name 'Michael'
technique FactoryBot.create :technique
end
end
techniques.rb
FactoryBot.define do
factory :technique do
name 'Some name'
end
end
So it was loading artist before technique object were loaded. So it couldn't find it. The solution is to not use nested FactoryBot create in factories or rename your nested factories to something that stands before your parent factory.
I just moved my technique factory. to factories.rb and defined it there. And issue was resolved.
I got this error when running the Rails application in the production environment.
Usually, the Gem factory_bot_rails is only added here:
group :development, :test do
gem 'factory_bot_rails'
gem 'faker'
end
You should add these to the "general" list of Gems if you want to use them in production.
I had the same issue and the only thing I added was a factories.rb file. All tests passed from that.