Continue testing multiple hosts even in the event of a failure

I created some serverpec code to run a group of tests on multiple hosts. The problem is that testing stops on the current host if any test fails. I want it to continue to all hosts, even if the test fails.

The 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

Full code: https://gist.github.com/neilhwatson/1d41c696102c01bbb87a

+4
source share
1 answer

This behavior is controlled by RSpec :: Core :: RakeTask # fail_on_error , so to continue working on all hosts, you need to add t.fail_on_error = false. I also think you do not need 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
+7
source

All Articles