Method: FactoryBot::Syntax::Methods#generate_list

Defined in:
lib/factory_bot/syntax/methods.rb

#generate_list(*uri_parts, count, scope: nil) ⇒ Object

Generates and returns the list of values in a global or factory sequence.

Arguments:

uri_parts: (Array of Symbols)
  The definition context of the sequence, with the sequence name
  as the final entry
scope: (object)(optional)
  The object the sequence should be evaluated within

Returns:

The next value in the sequence. (Object)

Example:

generate_list(:my_factory, :my_trair, :my_sequence, 5)


144
145
146
147
148
149
150
151
152
# File 'lib/factory_bot/syntax/methods.rb', line 144

def generate_list(*uri_parts, count, scope: nil)
  uri = FactoryBot::UriManager.build_uri(uri_parts)
  sequence = Sequence.find_by_uri(uri) ||
    raise(KeyError, "Sequence not registered: '#{uri}'")

  (1..count).map do
    increment_sequence(sequence, scope: scope)
  end
end