Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2e83b562
Commit
2e83b562
authored
Apr 01, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a section about `let` to the Testing guide
[ci skip]
parent
60f4081e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
doc/development/testing.md
doc/development/testing.md
+25
-4
No files found.
doc/development/testing.md
View file @
2e83b562
...
...
@@ -11,8 +11,7 @@ importance.
## Factories
GitLab uses [factory_girl] as a test
fixture replacement.
GitLab uses [factory_girl] as a test fixture replacement.
-
Factory definitions live in
`spec/factories/`
, named using the pluralization
of their corresponding model (
`User`
factories are defined in
`users.rb`
).
...
...
@@ -65,8 +64,30 @@ the command line via `bundle exec teaspoon`, or via a web browser at
-
Don't
`describe`
symbols (see
[
Gotchas
](
gotchas.md#dont-describe-symbols
)
).
-
Prefer
`not_to`
to
`to_not`
.
-
Try to match the ordering of tests to the ordering within the class.
-
Try to follow the
[
Four-Phase Test
](
https://robots.thoughtbot.com/four-phase-test
)
pattern, using newlines to separate phases.
-
Try to follow the
[
Four-Phase Test
][
four-phase-test
]
pattern, using newlines
to separate phases.
[
four-phase-test
]:
https://robots.thoughtbot.com/four-phase-test
### `let` variables
GitLab's RSpec suite has made extensive use of
`let`
variables to reduce
duplication. However, this sometimes
[
comes at the cost of clarity
][
lets-not
]
,
so we need to set some guidelines for their use going forward:
-
`let`
variables are preferable to instance variables. Local variables are
preferable to
`let`
variables.
-
Use
`let`
to reduce duplication throughout an entire spec file.
-
Don't use
`let`
to define variables used by a single test; define them as
local variables inside the test's
`it`
block.
-
Don't define a
`let`
variable inside the top-level
`describe`
block that's
only used in a more deeply-nested
`context`
or
`describe`
block. Keep the
definition as close as possible to where it's used.
-
Try to avoid overriding the definition of one
`let`
variable with another.
-
Don't define a
`let`
variable that's only used by the definition of another.
Use a helper method instead.
[
lets-not
]:
https://robots.thoughtbot.com/lets-not
### Test speed
...
...
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