首先,我正在使用serverspec 2.3.1和specinfra 2.4.2,使用Ruby 1.9.3p550
我仍然正在调查这个问题,但我想我会在这里问一下以防有人遇到问题之前(如果没有,我想出来,也许下一个遇到它的人会发现这个回答谷歌)。
目标是拥有一个spec文件,其中包含应在测试系统上安装的所有软件。但奇怪的是,无论我写什么,第一次it { should be_installed }
,它都会失败。没有例外。
下面的代码显示了我的意思:
require 'acceptance_helper'
describe package('7-Zip 9.22 (x64 edition)') do
it { should be_installed }
end
describe package('7-Zip 9.22 (x64 edition)') do
it { should be_installed }
end
describe package('Zend Server') do
it { should be_installed }
end
describe package('SQL Server 2012 Management Studio') do
it { should be_installed }
end
describe package('Microsoft SQL Server 2012 (64-bit)') do
it { should be_installed }
end
当我运行这个文件时,我会得到第一个测试,说没有安装7-Zip,第二个测试会说它是。我作为第一次测试时所做的任何事都做同样的事情。
Package "7-Zip 9.22 (x64 edition)"
should be installed (FAILED - 1)
Package "7-Zip 9.22 (x64 edition)"
should be installed
Package "Zend Server"
should be installed
Package "SQL Server 2012 Management Studio"
should be installed
Package "Microsoft SQL Server 2012 (64-bit)"
should be installed
Failures:
1) Package "7-Zip 9.22 (x64 edition)" should be installed
Failure/Error: it { should be_installed }
TypeError:
can't convert Symbol into Integer
uname -s
#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">The term 'uname' is not recognized as the name of a cmdlet, function, script fi_x000D__x000A_</S><S S="Error">le, or operable program. Check the spelling of the name, or if a path was inclu_x000D__x000A_</S><S S="Error">ded, verify that the path is correct and try again._x000D__x000A_</S><S S="Error">At line:1 char:6_x000D__x000A_</S><S S="Error">+ uname <<<< -s_x000D__x000A_</S><S S="Error"> + CategoryInfo : ObjectNotFound: (uname:String) [], CommandNotFou _x000D__x000A_</S><S S="Error"> ndException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
# ./spec/acceptance/192.168.0.70/all_required_applications_are_installed_spec.rb:4:in `block (2 levels) in <top (required)>'
Finished in 25.96 seconds (files took 0.99763 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/acceptance/192.168.0.70/all_required_applications_are_installed_spec.rb:4 # Package "7-Zip 9.22 (x64 edition)" should be installed
对我来说不真实的是,只有第一次测试才会失败,所以我真的不确定会发生什么。我会随时调查并更新这篇文章,但是如果有人遇到过这个问题,我真的很想听听你是如何解决这个问题的!
编辑:使用错误消息和ServerSpecs测试Windows上的软件包的方式,我认为命令执行得很糟糕,但事实证明,即使在命令运行之前也会发生错误。至少它看起来像,因为在Intellij IDEA中,当我在specinfra/command/windows/base/package.rb
(exec "(FindInstalledApplication -appName '#{package}' #{version_selection}) -eq $true"
)的第7行放置一个断点时,从未达到断点,测试失败并且它转到下次测试。
编辑2 :管理以更多地隔离问题,似乎发生在specinfra\helper\os.rb
。我是Ruby的新手,所以它有点难以调试,但我猜测在ServerSpec / SpecInfra用于检测操作系统的第一次运行时没有正确初始化。
答案 0 :(得分:3)
嗯,事实证明我很傻,无法正确阅读文档。他们在Serverspec的文档中说,需要在spec_helper中指定Windows操作系统,我只从他们的Windows doc复制/粘贴了示例助手。
现在这是我的帮助文件,请注意set :os
行
require 'serverspec'
require 'winrm'
require 'yaml'
set :backend, :winrm
set :os, :family => 'windows', :release => '2008', :arch => 'x64'
base_path = File.dirname(File.expand_path(__FILE__))
config = YAML.load_file(File.join(base_path, 'config.yml'))
user = 'vagrant'
pass = 'vagrant'
endpoint = "http://#{config['host_ip']}:5985/wsman"
winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true)
winrm.set_timeout 300 # 5 minutes max timeout for any operation
Specinfra.configuration.winrm = winrm