我已经谷歌了,看来这可以做到,但我显然做错了。
所以我试图运行Dim currentColumn As Integer
Dim columnHeading As String
For currentColumn = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
'CHECK WHETHER TO KEEP THE COLUMN
Select Case columnHeading
Case "Account Name", "Account ID", "Contract ID", "Delivery Date"
'Do nothing
Case Else
'Delete if the cell doesn't contain "string-"
If InStr(1, _
ActiveSheet.UsedRange.Cells(1, currentColumn).Value, "string1-" Or "string2-" Or "string3-", vbBinaryCompare) = 0 Then
ActiveSheet.Columns(currentColumn).Delete
End If
End Select
Next
powershell_script
现在,这些节点属性在属性default.rb
中设置powershell_script 'Unzip' do
code <<-EOH
Expand-Archive -Path 'E:\\apache-tomee-1.7.4-plus.zip' -DestinationPath "E:\\#{node['COOKBOOK']['Product']}-#{node['COOKBOOK']['Region']}-" + count.to_s.rjust(2, "0")"
EOH
guard_interpreter :powershell_script
not_if "Test-Path -Path E:\\#{node['COOKBOOK']['Product']}-#{node['COOKBOOK']['Region']}-01"
end
我遇到问题从那里到应该在spec文件中的内容。
default['COOKBOOK']['Product'] = 'product'
default['COOKBOOK']['Region'] = 'region'
任何人都可以帮我一把吗?
提前致谢。
答案 0 :(得分:0)
首先,您遇到了stub_command
行的问题。你有一行用单引号包围,所以那些属性的插值不会起作用,所以用双引号括起来:
stub_command("Test-Path -Path E:\\#{node['COOKBOOK']['Product']}-#{node['COOKBOOK']['Region']}-01").and_return(true)
现在您将收到此错误:
NameError:
undefined local variable or method `node' for #<RSpec::ExampleGroups::ExampleSoDefault::WhenAllAttributesAreDefaultOnWindows2012R2:0x0000000004066720>
您的节点属性在您的rspec测试中不可用。另外,rspec
会识别已替换属性的not_if
,如下所示:
not_if "Test-Path -Path E:\\product-region-01"
所以你需要存根该命令,如下所示:
require 'spec_helper'
describe 'example-so::default' do
context 'when all attributes are default, on Windows 2012R2' do
let(:chef_run) do
# for a complete list of available platforms and versions see:
# https://github.com/customink/fauxhai/blob/master/PLATFORMS.md
runner = ChefSpec::ServerRunner.new(platform: 'windows', version: '2012R2')
runner.converge(described_recipe)
end
it 'converges successfully' do
stub_command('Test-Path -Path E:\\product-region-01').and_return(true)
expect { chef_run }.to_not raise_error
end
end
end
如果您需要测试多种不同的属性设置,可以set attributes进行适当的测试并针对每组条件运行测试。