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
cb275a33
Commit
cb275a33
authored
Oct 19, 2018
by
Artur Martsinkovskyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update best_practices.md let section to also reference let! variables.
parent
c316c804
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
doc/development/testing_guide/best_practices.md
doc/development/testing_guide/best_practices.md
+8
-4
No files found.
doc/development/testing_guide/best_practices.md
View file @
cb275a33
...
@@ -158,12 +158,13 @@ instead of 30+ seconds in case of a regular `spec_helper`.
...
@@ -158,12 +158,13 @@ instead of 30+ seconds in case of a regular `spec_helper`.
### `let` variables
### `let` variables
GitLab's RSpec suite has made extensive use of
`let`
variables to reduce
GitLab's RSpec suite has made extensive use of
`let`
(along with it strict, non-lazy
duplication. However, this sometimes
[
comes at the cost of clarity
][
lets-not
]
,
version
`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:
so we need to set some guidelines for their use going forward:
-
`let`
variables are preferable to instance variables. Local variables are
-
`let!`
variables are preferable to instance variables.
`let`
variables
preferable to
`let`
variables.
are preferable to
`let!`
variables. Local variables are preferable to
`let`
variables.
-
Use
`let`
to reduce duplication throughout an entire spec file.
-
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
-
Don't use
`let`
to define variables used by a single test; define them as
local variables inside the test's
`it`
block.
local variables inside the test's
`it`
block.
...
@@ -173,6 +174,9 @@ so we need to set some guidelines for their use going forward:
...
@@ -173,6 +174,9 @@ so we need to set some guidelines for their use going forward:
-
Try to avoid overriding the definition of one
`let`
variable with another.
-
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.
-
Don't define a
`let`
variable that's only used by the definition of another.
Use a helper method instead.
Use a helper method instead.
-
`let!`
variables should be used only in case if strict evaluation with defined
order is required, otherwise
`let`
will suffice. Remember that
`let`
is lazy and won't
be evaluated until it is referenced.
[
lets-not
]:
https://robots.thoughtbot.com/lets-not
[
lets-not
]:
https://robots.thoughtbot.com/lets-not
...
...
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