Cannot create Factory with multiple traits got (ArgumentError Exception: wrong number of arguments (given 1, expected 0)) Ruby 3.0, Rails 6.1.72, factory_bot_rails 6.1.0
aliahmadexe opened this issue · comments
I have upgraded my application from rails 5.2 to 6.1.
and Ruby from 2.7 to 3.0
but when i rspec my test cases i got this error when i try to create a factory that have Factory and traits.
FactoryBot.define do
factory :registration, class: "METS::Registration" do
meeting { create(:meeting) }
transient do
attendee_attributes { {} }
end
email
registration_email { email&.value }
address_postal_code { attendee.business_address&.postal_code }
attendance_type { METS::Registration.attendance_type_values.sample }
attendee_type { registration_attendee_type(:invitee) }
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
rsvp_type { meeting.default_attendance_type }
trait :unfrozen do
meeting { build :meeting, :unfrozen_for_registrations }
end
trait :attended do
attendance_type { registration_attendance_type(:in_person) }
end
end
end
in Rspec/test.rb
create(:registration, :unfrozen, :as_employee, attendee: attendee, email: primary_email, email_value: primary_email.value)
Error:
Failure/Error: create(:registration, :unfrozen)
ArgumentError:
wrong number of arguments (given 1, expected 0)
you might have another gem that needs to be updated
try running bundle outdated
to see which are behind.
its unlikely a bug in this gem.
you could focus on your rails upgrade first. and do ruby 3.0 in a second step. because this type of error is sure ruby 3.0 related.
somewhere a hash is being sent as a param instead of named keyword arguments
method({foo: bar})
versus method(foo: bar)
this was acceptable in 2.7, not in 3.0 anymore.
I agree with Mathieu. I don't see an obvious bug in the code snippets you shared, so I'm going to close this for now.
If you narrow it down to a bug in factory_bot we can reopen the issue. We'd probably need a runnable reproduction script like https://github.com/thoughtbot/factory_bot/blob/main/.github/REPRODUCTION_SCRIPT.rb to be of much help.
Thank you!