thoughtbot / thoughtbot/factory_bot
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 #408
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.2k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the FactoryBot.define factory and the failing create(:registration, :unfrozen) call in the reported RSpec test, reproducing it with Ruby 3.0, Rails 6.1.72, and factory_bot_rails 6.1.0. Trace how multiple traits are passed during factory creation; done means the factory can be created with the listed traits without the ArgumentError and the regression is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100