635.md 1.2 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# Testing Rake tasks

> 原文:[https://docs.gitlab.com/ee/development/testing_guide/testing_rake_tasks.html](https://docs.gitlab.com/ee/development/testing_guide/testing_rake_tasks.html)

# Testing Rake tasks[](#testing-rake-tasks "Permalink")

为了使测试 Rake 任务更容易一些,可以使用一个辅助程序来代替标准 Spec 辅助程序. 代替`require 'spec_helper'` ,使用`require 'rake_helper'` . 该帮助程序包括为您提供的`spec_helper` ,并配置了一些其他内容以使测试 Rake 任务更加容易.

至少需要 Rake 帮助程序重定向`stdout` ,包括运行时任务帮助程序,并包括`RakeHelpers` Spec 支持模块.

`RakeHelpers`模块公开了`run_rake_task(<task>)`方法以简化执行任务. 有关所有可用方法,请参见`spec/support/helpers/rake_helpers.rb` .

Example:

```
require 'rake_helper'

describe 'gitlab:shell rake tasks' 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 
```

* * *

[Return to Testing documentation](index.html)