Testing Rake tasks

原文:https://docs.gitlab.com/ee/development/testing_guide/testing_rake_tasks.html

Testing Rake tasks

为了使测试 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

Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2021-03-27 13:48:25

results matching ""

    No results matching ""