This repository was archived by the owner on May 12, 2021. It is now read-only.
forked from timbertson/pea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-pea.xml
More file actions
211 lines (177 loc) · 8.06 KB
/
Copy pathpython-pea.xml
File metadata and controls
211 lines (177 loc) · 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?xml version="1.0" ?>
<?xml-stylesheet type='text/xsl' href='interface.xsl'?>
<interface uri="http://gfxmonk.net/dist/0install/python-pea.xml" xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
<name>python-pea</name>
<summary>minimal BDD library for python</summary>
<description>
pea - The tiniest green vegetable.
-------------------------------------
**pea** is a minimal BDD framework for python, in the style of ruby's `cucumber`_ and
python's `lettuce`_. It aims to help you write the same kind of tests - but in straight-up
python code, without all the parsing and indirection and other hoops to jump through. It's
a lot like ruby's `coulda`_.
Benefits of cucumber-style testing include:
- You write your tests in clear, english language without inline code
- Your tests are human-readable, and hopefully human-editable
- You can re-use steps with confidence, because they all do exactly what
they say on the tin
Benefits of ``pea`` over ``lettuce``, ``cucumber``, etc:
- It's a really trivial library (thus the name). It doesn't do very much,
so it probably doesn't have many bugs
- Your features are just python code:
- No "BDD language parser" needed
- No regular expressions
- Stack traces make sense
- Syntax highlighting
- You can use `ctags`_ to jump between test & implementation, as well as
for method completion
- Managing and renaming functions is much easier than managing regexes
- You can use whatever abstractions you like
- You can use rich python objects as arguments, instead of parsing strings
- It doesn't need its own test runner; so you can just use `nose`_ to run it
alongside your unit tests
So how do I use it?
--------------------------------------
Here's a minimal example::
from pea import *
@step
def I_go_to_the_store():
world.location='store'
world.cart = []
@step
def I_buy_some(item):
world.cart.append(item)
@step
def I_go_home():
world.location = 'home'
@step
def I_have_some_delicious(item):
assert item in world.cart
world.assertEquals(world.location, 'home')
# --------------------
class TestShopping(TestCase):
def test_buying_some_peas(self):
Given.I_go_to_the_store()
When.I_buy_some('peas')
And.I_go_home()
Then.I_have_some_delicious('peas')
... and when you run it (with nosetests, in verbose mode):
.. image:: http://gfxmonk.net/dist/0install/pea/screenshot.png
Typically you would put your steps in a separate python module (or many),
but it's your choice.
Basics:
^^^^^^^
- ``@step`` adds your function to pea's registry of steps, which allows
them to be called via ``Given``, ``When``, ``And``, and ``Then``.
- To re-use a step from inside another step, just call the function!
Stuff to remember:
^^^^^^^^^^^^^^^^^^
- Make sure you inherit from ``pea.TestCase`` (and call ``super`` from ``setUp``/``tearDown``),
as it takes care of resetting the ``world`` between tests.
- You can use ``TestCase`` assertion methods on the world, too
- e.g. ``world.assertEquals(expected, actual)``
Pea works well with `rednose`_
.. _cucumber: http://cukes.info/
.. _coulda: https://github.com/elight/coulda
.. _lettuce: https://github.com/gabrielfalcao/lettuce/
.. _ctags: http://ctags.sourceforge.net/
.. _nose: http://somethingaboutorange.com/mrl/projects/nose/1.0.0/
.. _rednose: https://github.com/gfxmonk/rednose/tree
</description>
<rich-description xmlns="http://gfxmonk.net/dist/0install">
<div xmlns="http://www.w3.org/1999/xhtml">
<div id="pea---the-tiniest-green-vegetable.">
<h1>pea - The tiniest green vegetable.</h1>
<p><strong>pea</strong> is a minimal BDD framework for python, in the style of ruby's <a href="http://cukes.info/">cucumber</a> and python's <a href="https://github.com/gabrielfalcao/lettuce/">lettuce</a>. It aims to help you write the same kind of tests - but in straight-up python code, without all the parsing and indirection and other hoops to jump through. It's a lot like ruby's <a href="https://github.com/elight/coulda">coulda</a>.</p>
<p>Benefits of cucumber-style testing include:</p>
<ul>
<li>You write your tests in clear, english language without inline code</li>
<li>Your tests are human-readable, and hopefully human-editable</li>
<li>You can re-use steps with confidence, because they all do exactly what they say on the tin</li>
</ul>
<p>Benefits of <code>pea</code> over <code>lettuce</code>, <code>cucumber</code>, etc:</p>
<ul>
<li>
<p>It's a really trivial library (thus the name). It doesn't do very much, so it probably doesn't have many bugs</p>
</li>
<li>
<p>Your features are just python code:</p>
<ul>
<li>No "BDD language parser" needed</li>
<li>No regular expressions</li>
<li>Stack traces make sense</li>
<li>Syntax highlighting</li>
<li>You can use <a href="http://ctags.sourceforge.net/">ctags</a> to jump between test & implementation, as well as for method completion</li>
<li>Managing and renaming functions is much easier than managing regexes</li>
<li>You can use whatever abstractions you like</li>
<li>You can use rich python objects as arguments, instead of parsing strings</li>
</ul>
</li>
<li>
<p>It doesn't need its own test runner; so you can just use <a href="http://somethingaboutorange.com/mrl/projects/nose/1.0.0/">nose</a> to run it alongside your unit tests</p>
</li>
</ul>
</div>
<div id="so-how-do-i-use-it">
<h1>So how do I use it?</h1>
<p>Here's a minimal example:</p>
<pre><code>from pea import *
@step
def I_go_to_the_store():
world.location='store'
world.cart = []
@step
def I_buy_some(item):
world.cart.append(item)
@step
def I_go_home():
world.location = 'home'
@step
def I_have_some_delicious(item):
assert item in world.cart
world.assertEquals(world.location, 'home')
# --------------------
class TestShopping(TestCase):
def test_buying_some_peas(self):
Given.I_go_to_the_store()
When.I_buy_some('peas')
And.I_go_home()
Then.I_have_some_delicious('peas')
</code></pre>
<p>... and when you run it (with nosetests, in verbose mode):</p>
<img alt="image" src="http://gfxmonk.net/dist/0install/pea/screenshot.png"/>
<p>Typically you would put your steps in a separate python module (or many), but it's your choice.</p>
<div id="basics:">
<h2>Basics:</h2>
<ul>
<li><code>@step</code> adds your function to pea's registry of steps, which allows them to be called via <code>Given</code>, <code>When</code>, <code>And</code>, and <code>Then</code>.</li>
<li>To re-use a step from inside another step, just call the function!</li>
</ul>
</div>
<div id="stuff-to-remember:">
<h2>Stuff to remember:</h2>
<ul>
<li>Make sure you inherit from <code>pea.TestCase</code> (and call <code>super</code> from <code>setUp</code>/<code>tearDown</code>), as it takes care of resetting the <code>world</code> between tests.</li>
<li>You can use <code>TestCase</code> assertion methods on the world, too<ul><li>e.g. <code>world.assertEquals(expected, actual)</code></li></ul></li>
</ul>
<p>Pea works well with <a href="https://github.com/gfxmonk/rednose/tree">rednose</a></p>
</div>
</div>
</div>
</rich-description>
<group>
<command name="run">
<runner interface="http://gfxmonk.net/dist/0install/nosetests-plugin-resolver.xml"/>
</command>
<command name="test" path='.'>
<requires interface="http://gfxmonk.net/dist/0install/rednose.xml"/>
<runner interface="http://gfxmonk.net/dist/0install/nosetests-plugin-resolver.xml"/>
</command>
<environment mode="prepend" name="NOSETESTS_PLUGINS" value="pea/PeaFormatter"/>
<environment insert="" mode="prepend" name="PYTHONPATH"/>
<implementation id="sha1new=eef73fda258ffb1f76588ba12aae6bee0812e355" released="2011-01-30" version="0.1">
<manifest-digest sha256="4d18a8e38749b3f4b3a9ad5f217ae69233864f331f650ae8e583e86fa7a0af1f"/>
<archive href="http://gfxmonk.net/dist/0install/python-pea/python-pea-0.1.tgz" size="4370"/>
</implementation>
</group>
</interface>