-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert to FactoryBot initialization without Rails lifecycle methods (was: Create factories earlier in the lifecycle) #76
Conversation
Hope you don't mind if I join in on this conversation, I can make a new issue if it makes sense, but I wanted to add on to my custom dir not being loaded (on I have it under I am seeing it in application class's > MyService::Application.config.factory_bot.definition_file_paths
=> ["factories", "test/factories", "spec/factories", "packs/my_pack/spec/factories", "packs/my_pack/test/factories"] BUT the key part seems to be > FactoryBot.definition_file_paths
=> [#<Pathname:/Users/me/work/my-service/factories>, #<Pathname:/Users/me/work/my-service/test/factories>, #<Pathname:/Users/me/work/my-service/spec/factories>] I am currently working around this by manually adding the
then it appears in |
Hm... we're in a bit of a pickle here...
Where to go from here? |
What versions of factory bot is everyone on? |
We could call it twice: on Other idea is to add a config parameter to tell when to load FactoryBot. |
I am using:
|
factory bot 6.4.2 |
@matiaseche in your spec helper, what comes first: loading of factories vs loading of the app environment? |
@matiaseche check the Ruby/Rails modularity slack |
@yesthesoup would you check whether this sha works for you: 81bc3ff (without the workaround in |
@matiaseche I agree with this idea. It's more flexible to different folks' implementations and configuration and is a simple fix. If a future upstream change makes one or the other implementation no longer practical to maintain (e.g. Rails or factorybot api change), we could release a breaking change that favors one or the other. Although I'd still be curious why our environments are so different! This configuration affects the point in time at which factory bot is assumed to have loaded all factories, I guess? Could be worth filing an issue question over at factory bot! Cc @shageman |
@shageman same versions as yourself: factory_bot_rails / factory_bot 6.4.2 maybe the new behaviour differs based on rails/factory bot major versions let me try that sha thanks, will update. |
Can you paste your Gemfile here? Or where is factory_bot_rails in relation to your rails entry? What does your factory bot |
Downgrading to 81bc3ff does work! Here's an abbreviated version of my gemfile: source 'https://rubygems.org'
ruby '3.2.2'
# Core Gems
# ... aws ...
gem 'bootsnap', require: false
gem 'bullet'
gem 'dogstatsd-ruby'
gem 'dotenv-rails'
gem 'graphql'
gem 'lograge'
gem 'logstash-event'
gem 'logstash-logger'
gem "packs-rails", github: "rubyatscale/packs-rails", ref: "81bc3ff" # was just 'pack-rails` latest before
gem 'pg'
gem 'pry-rails'
gem 'puma'
gem 'rack-timeout', require: 'rack/timeout/base'
gem 'rails', '~> 7.0.1'
gem 'rake'
gem 'rbtrace'
gem 'redis-reconnect_with_readonly'
gem 'request_store'
gem 'rollbar'
# sidekiq gems
...
source 'nexus' do
# private gems
...
end
group :development, :test do
gem 'brakeman'
gem 'bundler-audit'
gem 'byebug'
gem 'factory_bot_rails'
gem 'fakeredis', require: false
gem 'fuubar'
gem 'guard'
gem 'guard-bundler'
gem 'guard-rspec'
gem 'guard-rubocop'
gem 'listen'
gem 'pry-byebug'
gem 'rails-erd'
gem 'rspec'
gem 'rspec-rails'
gem 'simplecov'
gem 'simplecov_json_formatter'
gem 'timecop'
gem 'webmock'
gem 'ws-style'
gem 'packwerk'
end
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end no other factory bot config in application.rb or test.rb
@matiaseche looking at your original PR #71 just wanted to throw it out there that |
Yes! @yesthesoup that was my problem! gem 'factory_bot', require: false
gem 'factory_bot_rails', require: false If I remove the |
@matiaseche awesome! I think this is probably something that could be easily overlooked that should be added to the README, I'll make a PR :) EDIT: PR #78 |
Thanks team for getting to the bottom of this! |
Yay! to all the progress. And... I am unsure how to proceed :D For @yesthesoup the downgraded version (i.e., before initializer stuff at all worked). If both work for all of us now... which one is better? I am leaning towards removing the initializer code (i.e., "downgrade" rather then this PR) because it is simpler. Given that we know how to fix in all situations, I won't proceed before your feedback. Thanks all! |
Oh wait... I had pushed another change onto this branch that is effectively the downgrade... Since that's now confirmed to be working for folks, I will merge this. |
#71 breaks gusto's build. By loading factories earlier in the lifecycle, we see more? full? success.
@matiaseche would you check out if this branch works for your use case?