Testing multiple hosts with the same test using serverspec Testing multiple hosts with the same test using serverspec ruby ruby

Testing multiple hosts with the same test using serverspec


For the first issue, ServerSpec by default will run all your tests. However, since you have a loop that executes a Rake task for each environment, the first environment to have a failure causes the task to fails and so an exception is raised and the rest of your tasks don't run.

I've forked your gist and updated the Rake task to surround it with a begin/rescue.

...begin  desc "Run serverspec to #{host}"  RSpec::Core::RakeTask.new(host) do |t|    ENV['TARGET_HOST'] = host    t.pattern = "spec/base,cfengine3/*_spec.rb"  endrescueend...

For the second problem, it doesn't look like ServerSpec will output which environment the tests are running in. But since the updated Gist shows that the host gets set in the spec_helper.rb we can use that to add an RSpec configuration that sets up an after(:each) and only output the host on errors. The relevant code changes are in a fork of the gist, but basically you'll just need the below snippet in your spec_helper.rb:

RSpec.configure do |c|  c.after(:each) do |example|    if example.exception       puts "Failed on #{host_run_on}"    end  endend