Commit 110354db authored by Mike Jang's avatar Mike Jang

Merge branch 'rspec-named-subjects-guidelines' into 'master'

Prefer named subjects in Testing best practices documentation

See merge request gitlab-org/gitlab!42187
parents 2edf1353 72a4ed5a
...@@ -427,9 +427,9 @@ spec itself, but the former is preferred. ...@@ -427,9 +427,9 @@ spec itself, but the former is preferred.
It takes around one second to load tests that are using `fast_spec_helper` It takes around one second to load tests that are using `fast_spec_helper`
instead of 30+ seconds in case of a regular `spec_helper`. instead of 30+ seconds in case of a regular `spec_helper`.
### `let` variables ### `subject` and `let` variables
GitLab's RSpec suite has made extensive use of `let`(along with it strict, non-lazy GitLab's RSpec suite has made extensive use of `let`(along with its strict, non-lazy
version `let!`) variables to reduce duplication. However, this sometimes [comes at the cost of clarity](https://thoughtbot.com/blog/lets-not), version `let!`) variables to reduce duplication. However, this sometimes [comes at the cost of clarity](https://thoughtbot.com/blog/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:
...@@ -448,6 +448,7 @@ so we need to set some guidelines for their use going forward: ...@@ -448,6 +448,7 @@ so we need to set some guidelines for their use going forward:
- `let!` variables should be used only in case if strict evaluation with defined - `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 order is required, otherwise `let` will suffice. Remember that `let` is lazy and won't
be evaluated until it is referenced. be evaluated until it is referenced.
- Use named `subject(:name)` over un-named `subject` in examples, as this gives the subject a contextual name.
### Common test setup ### Common test setup
......
...@@ -287,7 +287,7 @@ Note the following important points: ...@@ -287,7 +287,7 @@ Note the following important points:
- Our test fabricates only what it needs, when it needs it. - Our test fabricates only what it needs, when it needs it.
- The issue is fabricated through the API to save time. - The issue is fabricated through the API to save time.
- GitLab prefers `let()` over instance variables. See - GitLab prefers `let()` over instance variables. See
[best practices](../best_practices.md#let-variables). [best practices](../best_practices.md#subject-and-let-variables).
- `be_closed` is not implemented in `page/project/issue/show.rb` yet, but will be - `be_closed` is not implemented in `page/project/issue/show.rb` yet, but will be
implemented in the next step. implemented in the next step.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment