diff options
author | Rémy Coutable <remy@rymai.me> | 2018-10-22 06:47:58 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-10-22 06:47:58 +0000 |
commit | 173b1436b1622b85d4a81e3577c6492cbb93a8b8 (patch) | |
tree | ea436e074580db35cf499dd0ee3fdd03f5433188 /doc | |
parent | 38a9cc730982dbac2c5e83a1d1a97e1cba910a7f (diff) | |
parent | 2953798e7e57aecbceb2dcb3a9e0178d179336a5 (diff) | |
download | gitlab-ce-173b1436b1622b85d4a81e3577c6492cbb93a8b8.tar.gz |
Merge branch '51366-custom-repos-trait-docs' into 'master'
Document the :repository and :custom_repo traits
Closes #51366
See merge request gitlab-org/gitlab-ce!22480
Diffstat (limited to 'doc')
-rw-r--r-- | doc/development/testing_guide/best_practices.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index 440c812f0b4..7727bd74c3c 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -472,6 +472,37 @@ GitLab uses [factory_bot] as a test fixture replacement. All fixtures should be be placed under `spec/fixtures/`. +### Repositories + +Testing some functionality, e.g., merging a merge request, requires a git +repository with a certain state to be present in the test environment. GitLab +maintains the [gitlab-test](https://gitlab.com/gitlab-org/gitlab-test) +repository for certain common cases - you can ensure a copy of the repository is +used with the `:repository` trait for project factories: + +```ruby +let(:project) { create(:project, :repository) } +``` + +Where you can, consider using the `:custom_repo` trait instead of `:repository`. +This allows you to specify exactly what files will appear in the `master` branch +of the project's repository. For example: + +```ruby +let(:project) do + create( + :project, :custom_repo, + files: { + 'README.md' => 'Content here', + 'foo/bar/baz.txt' => 'More content here' + } + ) +end +``` + +This will create a repository containing two files, with default permissions and +the specified content. + ### Config RSpec config files are files that change the RSpec config (i.e. |