首先,我在Ruby 1.9.3p550中使用serverspec 2.3.1和specinfra 2.4.2
我仍在调查问题,但我想如果有人之前遇到过问题,我想在这里提出建议(如果没有遇到问题,我会找出来的,也许下一个遇到问题的人会在Google上找到此答案)。
目标是拥有一个规范文件,其中包含应在测试系统上安装的所有软件。但是,奇怪的是,无论我写什么,我第一次做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用于检测OS的首次运行时,某些东西都没有正确初始化。
好吧,事实证明我很傻,无法正确阅读文档。他们在Serverspec的文档中说,需要在spec_helper中指定Windows操作系统,而我只是从Windows文档中复制/粘贴了示例帮助程序。
现在这是我的帮助文件,请注意以下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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句