Commit 75ce65df authored by Markus Koller's avatar Markus Koller

Merge branch 'caalberts-ee-extension-spec-guideline' into 'master'

Document unit test guidelines for EE features

See merge request gitlab-org/gitlab!39309
parents 41cc47c4 84048a75
...@@ -56,6 +56,12 @@ This works because for every path that is present in CE's eager-load/auto-load ...@@ -56,6 +56,12 @@ This works because for every path that is present in CE's eager-load/auto-load
paths, we add the same `ee/`-prepended path in [`config/application.rb`](https://gitlab.com/gitlab-org/gitlab/blob/925d3d4ebc7a2c72964ce97623ae41b8af12538d/config/application.rb#L42-52). paths, we add the same `ee/`-prepended path in [`config/application.rb`](https://gitlab.com/gitlab-org/gitlab/blob/925d3d4ebc7a2c72964ce97623ae41b8af12538d/config/application.rb#L42-52).
This also applies to views. This also applies to views.
#### Testing EE-only features
To test an EE class that doesn't exist in CE, create the spec file as you normally
would in the `ee/spec` directory, but without the second `ee/` subdirectory.
For example, a class `ee/app/models/vulnerability.rb` would have its tests in `ee/spec/models/vulnerability_spec.rb`.
### EE features based on CE features ### EE features based on CE features
For features that build on existing CE features, write a module in the `EE` For features that build on existing CE features, write a module in the `EE`
...@@ -96,6 +102,21 @@ This is also not just applied to models. Here's a list of other examples: ...@@ -96,6 +102,21 @@ This is also not just applied to models. Here's a list of other examples:
- `ee/app/validators/ee/foo_attr_validator.rb` - `ee/app/validators/ee/foo_attr_validator.rb`
- `ee/app/workers/ee/foo_worker.rb` - `ee/app/workers/ee/foo_worker.rb`
#### Testing EE features based on CE features
To test an `EE` namespaced module that extends a CE class with EE features,
create the spec file as you normally would in the `ee/spec` directory, including the second `ee/` subdirectory.
For example, an extension `ee/app/models/ee/user.rb` would have its tests in `ee/app/models/ee/user_spec.rb`.
In the `RSpec.describe` call, use the CE class name where the EE module would be used.
For example, in `ee/app/models/ee/user_spec.rb`, the test would start with:
```ruby
RSpec.describe User do
describe 'ee feature added through extension'
end
```
#### Overriding CE methods #### Overriding CE methods
To override a method present in the CE codebase, use `prepend`. It To override a method present in the CE codebase, use `prepend`. It
......
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