{"record":{"id":"4f5668d77c9d8d6c","repo":"thoughtbot/factory_bot","slug":"undefined-method-name-in-definition-name","errorCode":null,"errorMessage":"undefined method '#{name}' in '#{@definition.name}' factory\nDid you mean? '#{name} { #{association_options.inspect} }'","messagePattern":"undefined method '#(.+?)' in '#(.+?)' factory\nDid you mean\\? '#(.+?) (.+?) \\}'","errorType":"exception","errorClass":"NoMethodError","httpStatus":null,"severity":"error","filePath":"lib/factory_bot/definition_proxy.rb","lineNumber":99,"sourceCode":"    #\n    # and:\n    #\n    #   factory :user do\n    #     admin\n    #     email\n    #     account\n    #   end\n    #\n    # are equivalent.\n    def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing\n      association_options = args.first\n\n      if association_options.nil?\n        __declare_attribute__(name, block)\n      elsif __valid_association_options?(association_options)\n        association(name, association_options, &block)\n      else\n        raise NoMethodError.new(<<~MSG)\n          undefined method '#{name}' in '#{@definition.name}' factory\n          Did you mean? '#{name} { #{association_options.inspect} }'\n        MSG\n      end\n    end\n\n    # Adds an attribute that will have unique values generated by a sequence with\n    # a specified format.\n    #\n    # The result of:\n    #   factory :user do\n    #     sequence(:email) { |n| \"person#{n}@example.com\" }\n    #   end\n    #\n    # Is equal to:\n    #   sequence(:email) { |n| \"person#{n}@example.com\" }\n    #\n    #   factory :user do","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/thoughtbot/factory_bot/blob/18ae8b581bf55de681c8adb5f74d32787fd2157f/lib/factory_bot/definition_proxy.rb#L81-L117","documentation":"NoMethodError raised from DefinitionProxy#method_missing (definition_proxy.rb:91-104) when a bare method call inside a factory/trait/transient body receives a first argument that is neither nil nor a Hash containing :factory. factory_bot only supports three forms: `name { value }` (block), `name` (implicit association/sequence/trait), and `name factory: :x`. This is the signature failure after upgrading to factory_bot 5+, which removed static-value attributes (`title 'Hello'`); the message suggests the block form.","triggerScenarios":"In a factory body write `title 'Hello'`, `admin true`, `created_at Time.now`, or `user :admin` (trait as positional argument), then load the definitions file. method_missing sees association_options = 'Hello' (not nil, not a Hash with :factory) and raises immediately at definition time: \"undefined method 'title' in 'post' factory / Did you mean? 'title { \\\"Hello\\\" }'\".","commonSituations":"Upgrading factory_bot 4.x to 5.x/6.x where static attribute syntax was removed; copying fixtures from old tutorials or legacy apps; writing boolean flags as `admin true`; passing traits positionally instead of `association :user, :admin` or call-time traits like `create(:user, :admin)`.","solutions":["Wrap static values in a block: `title { 'Hello' }`, `admin { true }`, `created_at { Time.now }`.","For associations with options use the supported hash form: `author factory: :user`.","For traits on an association use `association :user, :admin`, or apply the trait at call time: `create(:user, :admin)`.","After an upgrade, sweep factories for leftover static syntax (grep for attribute-name followed by a value instead of a block)."],"exampleFix":"# before\nFactoryBot.define do\n  factory :post do\n    title 'Hello'      # static syntax removed in factory_bot 5\n    admin true\n  end\nend\n\n# after\nFactoryBot.define do\n  factory :post do\n    title { 'Hello' }\n    admin { true }\n  end\nend","handlingStrategy":"validation","validationCode":"# static scan for factory_bot 5+ illegal static attribute syntax\nDir['spec/factories/**/*.rb'].each do |file|\n  File.readlines(file).each_with_index do |line, i|\n    next unless line =~ /\\A\\s*[a-z_]\\w*\\s+(\\[|\\d|true|false|nil)\\b/\n    raise \"#{file}:#{i + 1} static attribute syntax - wrap in a block: #{line.strip}\"\n  end\nend","typeGuard":"->(args) { args.first.nil? || (args.first.is_a?(Hash) && args.first.key?(:factory)) }","tryCatchPattern":"begin\n  require 'spec/factories'\nrescue NoMethodError => e\n  raise unless e.message.include?(\"Did you mean?\")\n  # wrap the suggested static value in a block, e.g. title { 'Hello' }\nend","preventionTips":["On factory_bot 5+, always use block syntax `attr { value }` for values.","After upgrading, run FactoryBot.lint in CI to flush out every remaining static attribute.","Apply traits at call time (`create(:user, :admin)`) instead of passing them as positional arguments in the body."],"tags":["ruby","factory-bot","syntax","upgrade","nomethoderror"],"backgroundTag":"undefined-method-error","analyzedSha":"18ae8b581bf55de681c8adb5f74d32787fd2157f","analyzedAt":"2026-08-21T18:25:33.545Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}