class FactoryBot::DefinitionProxy
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
are equivalent.
end
account
admin
factory :user do
and:
end
association :account
email { generate(:email) }
factory :user, traits: [:admin] do
"account" factory:
name. This means that given an "admin" trait, an "email" sequence, and an
association, then for a sequence, and finally for a trait with the same
If no argument or block is given, factory_bot will first look for an
are equivalent.
end
add_attribute(:name) { 'Billy Idol' }
factory :user do
and:
end
name { 'Billy Idol' }
factory :user do
attribute, so that:
Calls add_attribute using the missing method name as the name of the
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing association_options = args.first if association_options.nil? __declare_attribute__(name, block) elsif __valid_association_options?(association_options) association(name, association_options) else raise NoMethodError.new(<<~MSG) undefined method '#{name}' in '#{@definition.name}' factory Did you mean? '#{name} { #{association_options.inspect} }' MSG end end