2020-10-30 14:08:56 -04:00
---
stage: none
group: unassigned
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-30 14:08:56 -04:00
---
2017-11-01 11:56:40 -04:00
# Testing Rake tasks
2017-10-11 01:59:34 -04:00
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-06-08 11:10:00 -04:00
At a minimum, requiring the Rake helper includes the runtime task helpers, and
includes the `RakeHelpers` Spec support module.
2017-10-11 01:59:34 -04:00
The `RakeHelpers` module exposes a `run_rake_task(<task>)` method to make
2018-03-29 05:47:54 -04:00
executing tasks simple. See `spec/support/helpers/rake_helpers.rb` for all available
2017-10-11 01:59:34 -04:00
methods.
2021-06-08 11:10:00 -04:00
`$stdout` can be redirected by adding `:silence_stdout` .
2017-10-11 01:59:34 -04:00
Example:
```ruby
require 'rake_helper'
2021-06-08 11:10:00 -04:00
describe 'gitlab:shell rake tasks', :silence_stdout do
2017-10-11 01:59:34 -04:00
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 )