5

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

耙文件:

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

4

1 回答 1

8

此行为由RSpec::Core::RakeTask#fail_on_error控制,因此为了让它在您需要添加的所有主机上继续运行t.fail_on_error = false。我也认为你不需要rescue

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
于 2015-06-18T14:22:12.183 回答