debian-mirror-gitlab/doc/development/testing_guide/testing_rake_tasks.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.3 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
stage: none
group: unassigned
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2018-03-17 18:26:18 +05:30
# Testing Rake tasks
To make testing Rake tasks a little easier, there is a helper that can be included
in lieu of the standard Spec helper. Instead of `require 'spec_helper'`, use
`require 'rake_helper'`. The helper includes `spec_helper` for you, and configures
a few other things to make testing Rake tasks easier.
2021-09-04 01:27:46 +05:30
At a minimum, requiring the Rake helper includes the runtime task helpers, and
includes the `RakeHelpers` Spec support module.
2018-03-17 18:26:18 +05:30
The `RakeHelpers` module exposes a `run_rake_task(<task>)` method to make
2018-10-15 14:42:47 +05:30
executing tasks simple. See `spec/support/helpers/rake_helpers.rb` for all available
2018-03-17 18:26:18 +05:30
methods.
2021-09-04 01:27:46 +05:30
`$stdout` can be redirected by adding `:silence_stdout`.
2018-03-17 18:26:18 +05:30
Example:
```ruby
require 'rake_helper'
2021-09-04 01:27:46 +05:30
describe 'gitlab:shell rake tasks', :silence_stdout do
2018-03-17 18:26:18 +05:30
before do
Rake.application.rake_require 'tasks/gitlab/shell'
stub_warn_user_is_not_gitlab
end
describe 'install task' do
it 'invokes create_hooks task' do
expect(Rake::Task['gitlab:shell:create_hooks']).to receive(:invoke)
run_rake_task('gitlab:shell:install')
end
end
end
```
---
[Return to Testing documentation](index.md)