Optional Extras¶
Factory Boy Integration¶
Aloe integration with factory_boy to create objects from factories.
Remember when writing BDD tests to describe the behavior you want and not just use Aloe as a syntax for writing complex tests (that defeats the point of BDD). Hide the complexity of setting up the objects in your factory or write a custom step.
To activate these steps import aloe.steps.factoryboy
into your
steps/__init__.py
.
-
aloe.steps.factoryboy.
step_from_factory
(factory)¶ Decorator to register a
factory.Factory
as an Aloe step:Given/And I have (a/an/n) object(s)An optional table can be passed containing attributes that would be passed as kwargs to
factory.Factory.create()
. Multiple rows or a number of objects can be passed to create more than one object. If a number of objects is requested, at most one row can be given, passed as kwargs tofactory.Factory.create_batch()
.The name of the object and its plural can be specified as:
_verbose_name
and_verbose_name_plural
attributes on the factory;- If the factory creates a Django model, and its name corresponds to the
model class name (e.g.
UserFactory
andUser
),verbose_name
andverbose_name_plural
of the model;
If neither is specified, the object name is inferred from the factory class name.
Example:
@step_from_factory class RandomUserFactory(factory.Factory): '''See Factory Boy docs''' class Meta: model = models.User first_name = factory.Faker('first_name') last_name = factory.Faker('last_name') _verbose_name = "random user"
Given I have a random user # Then I have created 1 user: Lucy Murray (a random name) Given I have 10 random users # Then I have created 10 users with different random names Given I have random users: | first_name | last_name | | Danielle | Madeley | | Alexey | Kotlyarov | # Then I have created 2 users: Danni and Alexey Given I have 10 random users: | first_name | | Joe | # Then I have created 10 users all with the first name Joe
Sphinx Extensions¶
Extensions to Sphinx for documenting Aloe packages.
Add these extensions to your Sphinx conf.py
:
extensions = [
'sphinx.ext.autodoc',
'aloe_sphinx.gerkindomain',
'aloe_sphinx.autosteps',
]
Gherkin Domain¶
-
aloe_sphinx.gherkindomain
The Gherkin Domain for Sphinx provides additional directives for documenting steps using Sphinx.
-
.. gherkin:restep::
Sentence regex
¶ Provide the documentation for a Gherkin regular expression step.
For example:
.. gherkin:restep:: (?:Given|When|And) I visit the supermarket I am at the supermarket.
Is rendered as:
- Step (?:Given|When|And) I visit the supermarket
I am at the supermarket.
Steps Autodocumenter¶
-
aloe_sphinx.autosteps
An autodocumenter for Aloe steps built on top of sphinx.ext.autodoc
.
This extension will identify functions decorated with step()
(including
private functions) and expose them in your documentation with their step
sentence.