forked from datamapper/dm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPECS
62 lines (46 loc) · 2.13 KB
/
SPECS
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
Reading Specs
=============
Blah blah blah...
Writing Specs
=============
Here are some general dos and don'ts
= DO:
* Write more specs for error conditions than clean conditions.
* Write specs with readability in mind. Somebody knew to DataMapper should be
able to read specs to learn how something works.
* Use existing models that are part of a metaphor.
* Nest describe blocks (2 or 3 levels deep is probably fine).
* Limit a describe block to 10 - 15 examples.
* Group specs by method being tested. (See the 'Ordering Specs' section)
* Use custom matchers.
= DON'T:
* Spec more than one unit of functionality in an example. An example should be
as short as possible (while still remaining readable).
* Spec implementation. Refactoring code should not break specs.
* Declare models in the spec file.
And a final do: Do go against the guidelines if your best judgement tells you
to. These are just guidelines and are obviously not fast rules.
Models
======
Models are declared in separate files as opposed to individual spec files for
two reasons. The first is to improve readability. By creating as few models
as possible and sharing these models throughout the specs, a reader can
become familiar with the models being used quicker. Models also follow a
few simple metaphors, such as a zoo, a blog implementation, etc... Following
metaphors makes it easier for a reader to guess what is going on with respect
to the models.
The second reason is to allow the spec environment to be as pristine as
possible going into an example. Models being loaded from the model directory
are tracked and reloaded before each example. Any changes that might be made
to the model are reset at the end.
Mocks and Stubs
===============
Obviously, mocks and stubs are a powerful feature when it comes to BDD;
however, remember that you are writing specs for behavior and NOT
implementation.
Ordering Specs
==============
Specs aren't much use if nobody can find where anything is, so keeping specs
well organized is critical. Currently, we are trying out the following
structure:
* List guidelines here...