Module FactoryGirl::Syntax::Vintage::Factory
In: lib/factory_girl/syntax/vintage.rb

Methods

alias   attributes_for   build   create   default_strategy   define   next   sequence   stub  

Public Class methods

Defines a new alias for attributes.

Arguments:

  • pattern: Regexp A pattern that will be matched against attributes when looking for aliases. Contents captured in the pattern can be used in the alias.
  • replace: String The alias that results from the matched pattern. Captured strings can be substituted like with +String#sub+.

Example:

  Factory.alias /(.*)_confirmation/, '\1'

factory_girl starts with aliases for foreign keys, so that a :user association can be overridden by a :user_id parameter:

  Factory.define :post do |p|
    p.association :user
  end

  # The user association will not be built in this example. The user_id
  # will be used instead.
  Factory(:post, :user_id => 1)

Alias for FactoryGirl.attributes_for

Alias for FactoryGirl.build

Alias for FactoryGirl.create

Executes the default strategy for the given factory. This is usually create, but it can be overridden for each factory.

DEPRECATED

Use create instead.

Arguments:

  • name: Symbol or String The name of the factory that should be used.
  • overrides: Hash Attributes to overwrite for this instance.

Returns: Object The result of the default strategy.

Defines a new factory that can be used by the build strategies (create and build) to build new objects.

Arguments:

  • name: Symbol or String A unique name used to identify this factory.
  • options: Hash

Options:

  • class: Symbol, Class, or String The class that will be used when generating instances for this factory. If not specified, the class will be guessed from the factory name.
  • parent: Symbol The parent factory. If specified, the attributes from the parent factory will be copied to the current one with an ability to override them.
  • default_strategy: Symbol DEPRECATED. The strategy that will be used by the Factory shortcut method. Defaults to :create.

Yields: Factory The newly created factory.

Generates and returns the next value in a sequence.

Arguments:

  name: (Symbol)
    The name of the sequence that a value should be generated for.

Returns:

  The next value in the sequence. (Object)

Defines a new sequence that can be used to generate unique values in a specific format.

Arguments:

  name: (Symbol)
    A unique name for this sequence. This name will be referenced when
    calling next to generate new values from this sequence.
  block: (Proc)
    The code to generate each value in the sequence. This block will be
    called with a unique number each time a value in the sequence is to be
    generated. The block should return the generated value for the
    sequence.

Example:

  Factory.sequence(:email) {|n| "somebody_#{n}@example.com" }

Alias for FactoryGirl.build_stubbed.

[Validate]