ruby - 即使失败也继续进行多主机测试

标签 ruby serverspec

我已经构建了一些 serverspec 代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。

Rakefile:

namespace :spec do
  task :all => hosts.map {|h| 'spec:' + h.split('.')[0] }
  hosts.each do |host|
    begin
      desc "Run serverspec to #{host}"
      RSpec::Core::RakeTask.new(host) do |t|
        ENV['TARGET_HOST'] = host
        t.pattern = "spec/cfengine3/*_spec.rb"
      end
    rescue
    end
  end
end

完整代码: https://gist.github.com/neilhwatson/1d41c696102c01bbb87a

最佳答案

此行为由 RSpec::Core::RakeTask#fail_on_error 控制所以为了让它在所有主机上继续,您需要添加 t.fail_on_error = false。我还认为您不需要救援

namespace :spec do
  task :all => hosts.map {|h| 'spec:' + h.split('.')[0] }
  hosts.each do |host|
    desc "Run serverspec to #{host}"
    RSpec::Core::RakeTask.new(host) do |t|
      ENV['TARGET_HOST'] = host
      t.pattern = "spec/cfengine3/*_spec.rb"
      t.fail_on_error = false
    end
  end
end

关于ruby - 即使失败也继续进行多主机测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867597/

相关文章:

ruby-on-rails - 基于客户端的网站的最佳数据库策略(Ruby on Rails)

chef-infra - 在 Chef 中,是否可以将一本 Recipe 的 serverspec 测试包含到另一本 Recipe 中?

ruby - 如何在厨房 serverspec 测试中要求 Recipe 库

windows - Windows 上的 Test-Kitchen serverspec 测试异常

ruby - 为什么 File.read ('/path/to/file' ) 不在 Ruby 文档中?

ruby - 使用 ImageMagick 删除收据图像边框

Ruby 开始和结束 block 的使用

ruby-on-rails - Rails & Papertrail - 在查询中包含以前的版本

ssh - 集成 Terraform 和 Serverspec