Testing Rake tasks
To make testing Rake tasks a little easier:
- Use RSpec’s metadata tag
type: :task
or - Place your spec in
spec/tasks
oree/spec/tasks
By doing so, RakeHelpers
is included which exposes a run_rake_task(<task>)
method to make executing tasks possible.
See spec/support/helpers/rake_helpers.rb
for all available methods.
$stdout
can be redirected by adding :silence_stdout
.
Example:
require 'spec_helper'
describe 'gitlab:shell rake tasks', :silence_stdout do
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
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support