Method: FactoryBot::Syntax::Methods#generate

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

#generate(*uri_parts, scope: nil) ⇒ Object

Generates and returns the next value in a global or factory sequence.

Arguments:

context: (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(:my_factory, :my_trair, :my_sequence)


120
121
122
123
124
125
126
127
# File 'lib/factory_bot/syntax/methods.rb', line 120

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

  increment_sequence(sequence, scope: scope)
end