factory_girl

https://github.com/thoughtbot/factory_girl

Ruby

A library for setting up Ruby objects as test data.

FactoryGirl::DefinitionProxy#add_attribute

Adds an attribute that should be assigned on generated instances for this
factory.

This method should be called with either a value or block, but not both. If
called with a block, the attribute will be generated "lazily," whenever an
instance is generated. Lazy attribute blocks will not be called if that
attribute is overridden for a specific instance.

When defining lazy attributes, an instance of FactoryGirl::Strategy will
be yielded, allowing associations to be built using the correct build
strategy.

Arguments:
* name: +Symbol+ or +String+
  The name of this attribute. This will be assigned using "name=" for
  generated instances.
* value: +Object+
  If no block is given, this value will be used for this attribute.

Source | Google | Stack overflow

Edit

git clone [email protected]:thoughtbot/factory_girl.git

cd factory_girl

open lib/factory_girl/definition_proxy.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-FactoryGirl--DefinitionProxy-add_attribute-for-pr


# Commit to git

git add lib/factory_girl/definition_proxy.rbgit commit -m "better docs for FactoryGirl::DefinitionProxy#add_attribute"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-FactoryGirl--DefinitionProxy-add_attribute-for-pr

hub pull-request


# Celebrate!