I have a test machine that contains a serverspec test. This is a ubuntu machine and I want to run the test using WinRM against a windows machine.
when executing the test it immediately fails, it looks like it is trying to run the test locally and not against the remote host.
I have hardcoded the hostname in the spec_helper.rb for now but I will post the Rakefile for completness
Rakefile:
require 'rake'
require 'rspec/core/rake_task'
hosts = %w(
MyHostName )
task :spec => 'spec:all'
task :default => :spec
namespace :spec do
task :all => hosts.map {|h| 'spec:' + h.split('.')[0] }
hosts.each do |host|
short_name = host.split('.')[0]
role = short_name.match(/[^0-9]+/)[0]
desc "Run serverspec to #{host}"
RSpec::Core::RakeTask.new(short_name) do |t|
ENV['TARGET_HOST'] = host
t.pattern = "spec/base/*_spec.rb"
end
end
end
Spec_helper.rb
require 'serverspec'
require 'winrm'
set :backend, :winrm
user = "Packer"
pass = "Drj33l1n9"
endpoint = "http://hostname:5985/wsman"
opts = {
user: user,
password: pass,
endpoint: endpoint,
operation_timeout: 30,
}
winrm = WinRM::Connection.new ( opts)
Specinfra.configuration.winrm = winrm
Sample_spec.rb
require 'spec_helper'
set :os, :family => 'windows'
describe file('c:/windows') do
it { should be_directory }
end
describe file('c:/temp/testfile.txt') do
it { should be_file }
end
describe service('Schedule') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
it { should have_start_mode("Automatic") }
end
describe port(139) do
it { should be_listening }
end
describe user('Administrator') do
it { should exist }
it { should belong_to_group('Administrators')}
end
this is the output of the failures
/usr/bin/ruby2.3 -I/var/lib/gems/2.3.0/gems/rspec-support-3.5.0/lib:/var/lib/gems/2.3.0/gems/rspec-core-3.5.4/lib /var/lib/gems/2.3.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/base/\*_spec.rb
File "c:/windows"
should be directory (FAILED - 1)
File "c:/temp/testfile.txt"
should be file (FAILED - 2)