Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lettuce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
lettuce
Commits
d15a09b3
Commit
d15a09b3
authored
Sep 22, 2013
by
Grégory Salvan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document syntactic sugar
parent
70d06603
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
2 deletions
+87
-2
docs/tutorial/simple.rst
+87
-2
No files found.
docs/tutorial/simple.rst
View file @
d15a09b3
...
...
@@ -37,7 +37,7 @@ Let's choose a problem to lettuce:
**Given a number, what is its factorial?**
.. Note::
The factorial of a positive integer n, denoted by n!, is the
product of all positive integers less than or equal to n. The
factorial of 0 is 1
...
...
@@ -96,7 +96,7 @@ Start describing the expected behaviour of factorial in ``zero.feature`` using E
--------------------------
Now let's define the steps of the scenario, so Lettuce can
understand the behaviour description. Create the ``steps.py`` file which will contain
understand the behaviour description. Create the ``steps.py`` file which will contain
python code describing the steps.
Python:
...
...
@@ -415,4 +415,89 @@ forth round
All steps should be repeated as long as you can keep doing them - the
quality of your software depends on these.
****************
Syntactic sugar
****************
Available for versions > 0.2.19
Steps sentence can now be given by function name or doc.
=========================================================
To take a step sentence from function name or doc,
just decorate it with "@step" without argument.
These two steps below, are identicals than the example above.
.. highlight:: python
::
from lettuce import *
@step
def have_the_number(step, number):
'I have the number (\d+)'
world.number = int(number)
@step
def i_compute_its_factorial(step):
world.number = factorial(world.number)
Steps can be grouped in class decorated with "@steps"
======================================================
.. highlight:: python
::
from lettuce import world, steps
@steps
class FactorialSteps(object):
"""Methods in exclude or starting with _ will not be considered as step"""
exclude = ['set_number', 'get_number']
def __init__(self, environs):
self.environs = environs
def set_number(self, value):
self.environs.number = int(value)
def get_number(self):
return self.environs.number
def _assert_number_is(self, expected, msg="Got %d"):
number = self.get_number()
assert number == expected, msg % number
def have_the_number(self, step, number):
'''I have the number (\d+)'''
self.set_number(number)
def i_compute_its_factorial(self, step):
number = self.get_number()
self.set_number(factorial(number))
def check_number(self, step, expected):
'''I see the number (\d+)'''
self._assert_number_is(int(expected))
# Important!
# Steps are added only when you instanciate the "@steps" decorated class
# Internally decorator "@steps" build a closure with __init__
FactorialSteps(world)
def factorial(number):
number = int(number)
if (number == 0) or (number == 1):
return 1
else:
return number*factorial(number-1)
Have a nice lettuce...! ;)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment