0
我有一个配方来安装IIS的组件。由于有很多,它是一个数组,填充到windows_feature
安装块。像这样:Chefspec不能迭代数组
strings.each do |st|
windows_feature st do
guard_interpreter :powershell_script
not_if "$ret = Get-WindowsOptionalFeature -Online -FeatureName #{st}; if ($ret.State -eq 'Disabled') { return 'false'} else {return 'true'}"
action :install
end
end
我的关联Chefspec块具有相同的数组内容。块是这样的:
describe 'HEQIIS::IIS' do
let(:chef_run) { ChefSpec::SoloRunner.converge('HEQIIS::IIS') }
strings.each do |st|
it "installs_#{st}" do
stub_command("$ret = Get-WindowsOptionalFeature -Online -FeatureName #{st}; if ($ret.State -eq 'Disabled') { return 'false'} else {return 'true'}").and_return(false)
expect(chef_run).to install_windows_feature("#{st}")
end
end
end
当我在菜谱运行Chefspec,我得到的错误:
HEQIIS::IIS installs_IIS-LegacyScripts
Failure/Error: let(:chef_run) { ChefSpec::SoloRunner.converge('HEQIIS::IIS') }
ChefSpec::Error::CommandNotStubbed:
Executing a real command is disabled. Unregistered command:
command("$ret = Get-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole; if ($ret.State -eq 'Disabled') { return 'false'} else {return 'true'}")
You can stub this command with:
stub_command("$ret = Get-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole; if ($ret.State -eq 'Disabled') { return 'false'} else {return 'true'}").and_return(...)
# ./heqiis/spec/default_spec.rb:70:in `block (2 levels) in <top (required)>'
# ./heqiis/spec/default_spec.rb:75:in `block (3 levels) in <top (required)>'
在错误,在此它显示-Featurename为“WebServerRole”,但它确实是为每一行(30条)。表明它只是在这个阶段迭代第一个项目。结合我肯定使用stub_command块的事实,我不确定它为什么会出错。任何人有任何想法?