我有一台包含serverspec测试的测试机器。这是一台ubuntu机器,我想在Windows机器上使用WinRM运行测试。
执行测试时,它会立即失败,看起来它试图在本地运行测试而不是远程主机。
我现在已经在spec_helper.rb中对主机名进行了硬编码,但我会发布Rakefile以获得完整性
Rake文件:
<<set>>
MYHOSTNAME )
require 'rake'
require 'rspec/core/rake_task'
hosts = %w(
Spec_helper.rb
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
Sample_spec.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
这是失败的输出
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