{"record":{"id":"545ed2b01c096968","repo":"thoughtbot/factory_bot","slug":"count-missing-for-strategy-name-list","errorCode":null,"errorMessage":"count missing for #{strategy_name}_list","messagePattern":"count missing for #(.+?)_list","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/factory_bot/strategy_syntax_method_registrar.rb","lineNumber":37,"sourceCode":"      end\n    end\n\n    private\n\n    def define_singular_strategy_method\n      strategy_name = @strategy_name\n\n      define_syntax_method(strategy_name) do |name, *traits_and_overrides, &block|\n        FactoryRunner.new(name, strategy_name, traits_and_overrides).run(&block)\n      end\n    end\n\n    def define_list_strategy_method\n      strategy_name = @strategy_name\n\n      define_syntax_method(\"#{strategy_name}_list\") do |name, amount, *traits_and_overrides, &block|\n        unless amount.respond_to?(:times)\n          raise ArgumentError, \"count missing for #{strategy_name}_list\"\n        end\n\n        Array.new(amount) do |i|\n          block_with_index = StrategySyntaxMethodRegistrar.with_index(block, i)\n          send(strategy_name, name, *traits_and_overrides, &block_with_index)\n        end\n      end\n    end\n\n    def define_pair_strategy_method\n      strategy_name = @strategy_name\n\n      define_syntax_method(\"#{strategy_name}_pair\") do |name, *traits_and_overrides, &block|\n        Array.new(2) { send(strategy_name, name, *traits_and_overrides, &block) }\n      end\n    end\n\n    def define_syntax_method(name, &block)","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/thoughtbot/factory_bot/blob/18ae8b581bf55de681c8adb5f74d32787fd2157f/lib/factory_bot/strategy_syntax_method_registrar.rb#L19-L55","documentation":"ArgumentError raised by the *_list strategy methods (strategy_syntax_method_registrar.rb:35-38): create_list, build_list, build_stubbed_list, and attributes_for_list require an integer count as the second positional argument. The guard `amount.respond_to?(:times)` fires when that slot holds anything else — usually the count was omitted and the overrides hash or first trait slid into the position.","triggerScenarios":"`FactoryBot.create_list(:post, title: 'The Hunting of the Bear')` (count forgotten, the hash becomes amount); `build_list(:user, :admin)` (trait lands in the count slot); `create_list(:post, '3')` (string count). Each raises 'count missing for create_list' / '..._list' for the strategy used.","commonSituations":"Editing an existing *_list call and accidentally deleting the count; adding traits or overrides and forgetting the count must remain the second argument; find/replace refactors that shift positional args.","solutions":["Insert an integer count as the second argument: `create_list(:post, 3, title: 'The Hunting of the Bear')`.","Keep traits and overrides after the count: `build_list(:user, 5, :admin, name: 'X')`.","Use *_pair when exactly two records are needed — it takes no count.","When forwarding dynamic counts from params, coerce first: `Integer(params[:count])`."],"exampleFix":"# before\nFactoryBot.create_list(:post, title: 'The Hunting of the Bear') # hash lands in count slot\n\n# after\nFactoryBot.create_list(:post, 3, title: 'The Hunting of the Bear')","handlingStrategy":"validation","validationCode":"# coerce user-supplied counts before calling *_list\ncount = Integer(params[:count]) rescue nil\nraise ArgumentError, 'count must be a positive integer' unless count&.positive?\nFactoryBot.create_list(:post, count, title: 'X')","typeGuard":"->(n) { n.is_a?(Integer) && n >= 0 }","tryCatchPattern":null,"preventionTips":["Memorize the signature: *_list(name, count, *traits, **overrides) — count is always second.","Prefer *__pair when exactly two records are needed; it takes no count.","In helpers, coerce with Integer(count) before forwarding to *_list."],"tags":["ruby","factory-bot","create-list","arguments","argumenterror"],"backgroundTag":"missing-required-argument","analyzedSha":"18ae8b581bf55de681c8adb5f74d32787fd2157f","analyzedAt":"2026-08-21T18:25:33.545Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}