I prefer option 2. There are a few ways you can improve it:
- If the
@uservariable isn’t used outside of thebeforeblock then you can use a local variable instead. - If the user’s name isn’t important for the test, consider setting
first_nameandlast_namein the factory instead. And similarly withtail_length. - If you define a
kiteassociation in thetailfactory, it will be created automatically. (Sometimes this feature is overused and make tests hard to understand, so use your judgement.) - You could use
create_listandcreate_pairas a shorthand for creating multiple records.
So you could potentially reduce the whole block to something like:
before do
user = create(:user)
create_pair(:tail, user: user)
end