diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2017-04-26 14:46:26 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-26 14:46:26 +0000 |
commit | 6f5b579f94c4bb3590c56e409434a15b6401afac (patch) | |
tree | b6c1cd04d1e4008151e3a93d9c67bcf5fefdea92 /doc/development/testing.md | |
parent | c7df97710b5b519c8ea1b5bb92ae17579082d3f4 (diff) | |
download | gitlab-ce-6f5b579f94c4bb3590c56e409434a15b6401afac.tar.gz |
Use rspec-set to speed up examples
Diffstat (limited to 'doc/development/testing.md')
-rw-r--r-- | doc/development/testing.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/development/testing.md b/doc/development/testing.md index 2c7154f1dea..9b0b9808827 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -202,6 +202,7 @@ Please consult the [dedicated "Frontend testing" guide](./fe_guide/testing.md). - Try to follow the [Four-Phase Test][four-phase-test] pattern, using newlines to separate phases. - Try to use `Gitlab.config.gitlab.host` rather than hard coding `'localhost'` +- On `before` and `after` hooks, prefer it scoped to `:context` over `:all` [four-phase-test]: https://robots.thoughtbot.com/four-phase-test @@ -225,6 +226,20 @@ so we need to set some guidelines for their use going forward: [lets-not]: https://robots.thoughtbot.com/lets-not +#### `set` variables + +In some cases there is no need to recreate the same object for tests again for +each example. For example, a project is needed to test issues on the same +project, one project will do for the entire file. This can be achieved by using +`set` in the same way you would use `let`. + +`rspec-set` only works on ActiveRecord objects, and before new examples it +reloads or recreates the model, _only_ if needed. That is, when you changed +properties or destroyed the object. + +There is one gotcha; you can't reference a model defined in a `let` block in a +`set` block. + ### Time-sensitive tests [Timecop](https://github.com/travisjeffery/timecop) is available in our |