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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
fe919f95
Commit
fe919f95
authored
Mar 29, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document the new 'spec/fast_spec_helper.rb' file
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
d2aee809
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
5 deletions
+31
-5
doc/development/testing_guide/best_practices.md
doc/development/testing_guide/best_practices.md
+31
-5
No files found.
doc/development/testing_guide/best_practices.md
View file @
fe919f95
...
...
@@ -90,6 +90,25 @@ Finished in 34.51 seconds (files took 0.76702 seconds to load)
Note:
`live_debug`
only works on javascript enabled specs.
### Fast unit tests
Some classes are well-isolated from Rails and you should be able to test them
without the overhead added by the Rails environment and Bundler's
`:default`
group's gem loading. In these cases, you can
`require 'fast_spec_helper'`
instead of
`require 'spec_helper'`
in your test file, and your test should run
really fast since:
-
Gems loading is skipped
-
Rails app boot is skipped
-
Gitlab::Shell and Gitaly setup are skipped
-
Test repositories setup are skipped
Note that in some cases, you might have to add some
`require_dependency 'foo'`
in your file under test since Rails autoloading is not available in these cases.
This shouldn't be a problem since explicitely listing dependencies should be
considered a good practice anyway.
### `let` variables
GitLab's RSpec suite has made extensive use of
`let`
variables to reduce
...
...
@@ -281,14 +300,13 @@ All fixtures should be be placed under `spec/fixtures/`.
RSpec config files are files that change the RSpec config (i.e.
`RSpec.configure do |config|`
blocks). They should be placed under
`spec/support/
config/
`
.
`spec/support/`
.
Each file should be related to a specific domain, e.g.
`spec/support/c
onfig/capybara.rb`
,
`spec/support/config
/carrierwave.rb`
, etc.
`spec/support/c
apybara.rb`
,
`spec/support
/carrierwave.rb`
, etc.
Helpers can be included in the
`spec/support/config/rspec.rb`
file. If a
helpers module applies only to a certain kind of specs, it should add modifiers
to the
`config.include`
call. For instance if
If a helpers module applies only to a certain kind of specs, it should add
modifiers to the
`config.include`
call. For instance if
`spec/support/helpers/cycle_analytics_helpers.rb`
applies to
`:lib`
and
`type: :model`
specs only, you would write the following:
...
...
@@ -299,6 +317,14 @@ RSpec.configure do |config|
end
```
If a config file only consists of
`config.include`
, you can add these
`config.include`
directly in
`spec/spec_helper.rb`
.
For very generic helpers, consider including them in the
`spec/support/rspec.rb`
file which is used by the
`spec/fast_spec_helper.rb`
file. See
[
Fast unit tests
](
#fast-unit-tests
)
for more details about the
`spec/fast_spec_helper.rb`
file.
---
[
Return to Testing documentation
](
index.md
)
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