You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But now I can't find evidence that the factory's before(:create) block that I need to run is running (at least in the order I expect). See repro steps below.
Reproduction Steps
This fails because the http call is not getting stubbed out:
I think I'm running into something similar, where factory use in a before(:all) block fails because http calls arent being stubbed. Nothing to add other than that so far 😅
In my project, before(:create) doesn't seem to be run at all. This leads to a situation where
FactoryBot.build(:my_factory).save!
works - the after(:build) callback runs as expected and fills in some bidirectional associations for delegated types correctly.
But
FactoryBot.create(:my_factory)
throws
Validation failed: Data source can't be blank (ActiveRecord::RecordInvalid)
because neither after(:build) nor before(:create) are invoked. This is contrary to the documentation which suggests that FactoryBot.create should run both after(:build) and before(:create) callbacks.
Description
The
before(:create)
block is not getting executed in the order I expect when usinginstance
in one of the factory's associations.I'm trying to update an existing factory I have (
organization
) to allow a:build
strategy. It currently makes use of a block like this:Which obviously won't work when using
build
. So I've updated it by making an association:But now I can't find evidence that the factory's
before(:create)
block that I need to run is running (at least in the order I expect). See repro steps below.Reproduction Steps
This fails because the http call is not getting stubbed out:
However, if you change the organization factory to this, the http call does in fact get stubbed out and everything works as expected:
Expected behavior
I expected the factory's
before(:create)
block to run before the model'safter(:create)
block.Actual behavior
The factory's
before(:create)
block is not run, the HTTP call is not stubbed out, and the test fails because the model is running it'safter(:create)
.System configuration
factory_bot version: 6.2.1
rails version: 6.1.7.3
ruby version: 2.7.8
The text was updated successfully, but these errors were encountered: