How to use Alchemy factories in my app specs? #2440
-
Having upgraded to Alchemy 5.2, I'm now getting the deprecation message to tell me to stop calling:
Which I'm doing at the top of my
Only problem is ... where exactly to put that block? The top of my rails_helper.rb looks like:
If I put it after line 3, it's too late - on line 3, the app files get loaded, and any specs using an Alchemy factory complains about unregistered factories. If I put i ABOVE line 3, it's too early - FactoryBot and Alchemy haven't yet been loaded; and trying to throw some require statements infront of it just gets messy. I also tried following https://github.com/thoughtbot/factory_bot_rails/blob/main/README.md#automatic-factory-definition-loading and adding At this point, after a few hours of trying, I went back to the deprecated approach. But next week, we're trying to get up to Alchemy 6, so ideally I can figure out how to do this "correctly" by then, but I'm very puzzled the the deprecation warning doesn't seem to be supplying working code (and yes, I've seen it changes slightly on the Alchemy 6 branch, but the overall suggestion looks to be the same) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Maybe this helps? https://github.com/AlchemyCMS/alchemy-solidus/blob/main/spec/rails_helper.rb |
Beta Was this translation helpful? Give feedback.
-
Looks like This problem might not apply to other rails apps, as I also uncovered that we have the following in OUR factory definitions:
Meaning we need the alchemy factory definitions loaded before we load ours. Going back to just
And looks like it works nicely now! |
Beta Was this translation helpful? Give feedback.
Looks like
factory_bot_rails
was the problem - it loads the factory definitions whenrequire_relative '../config/environment'
executes, which causes the chicken and egg problem for our app.This problem might not apply to other rails apps, as I also uncovered that we have the following in OUR factory definitions:
Meaning we need the alchemy factory definitions loaded before we load ours. Going back to just
factory_bot
gem, and adding in the recommend lines ALMOST works; due to us modifying …