首先,我使用 serverspec 2.3.1 和 specinfra 2.4.2,以及 Ruby 1.9.3p550
我仍在调查这个问题,但我想我会在这里问一下,以防有人以前遇到过这个问题(如果没有,我想通了,也许下一个遇到它的人会在谷歌上找到这个答案)。
目标是拥有一个包含应安装在测试系统上的所有软件的规范文件。奇怪的是,无论我写什么,我第一次写,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 is not installed 而第二个测试会说它是。我作为第一个测试所做的任何事情都是一样的。
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 用于检测操作系统的任何东西时,某些东西都没有正确初始化。