[英]Writing chef rspec test using 'execute'
In my .rb file, I am attempting to write a spec test against this line of code (I did not write this code): 在我的.rb文件中,我试图针对此代码行编写规格测试(我未编写此代码):
execute "lvcreate -L #{node['ami_base']['opt']} -n opt vgpool"
In my _spec.rb file, my test looks like this for this particular section of code: 在我的_spec.rb文件中,此特定代码段的测试如下所示:
it 'executes lvcreate... -n opt vgpool' do
expect(chef_run).to run_execute("lvcreate -L #{node['ami_base']['opt']} -n opt vgpool")
end
When I attempt: 当我尝试:
chef exec rspec....._spec.rb
I receive this error: 我收到此错误:
1) ami_base::lvm_drives executes lvcreate... -n opt vgpool
Failure/Error: expect(chef_run).to run_execute("lvcreate -L #{node['ami_base']['opt']} -n opt vgpool")
NameError:
undefined local variable or method `node' for #<RSpec::ExampleGroups::AmiBaseLvmDrives:0x0000000005752268>
# ./spec/unit/recipes/lvm_drives_spec.rb:33:in `block (2 levels) in <top (required)>'
I've written many tests against execute
and they've all been successful. 我编写了许多针对
execute
测试,它们都成功了。 Do I need to modify the spec helper file? 我需要修改规范助手文件吗? I feel like it being a command line input and creating a volume that the command should be something other than run_execute, but i am coming up empty handed in a my searches for anything that works.
我觉得这是一个命令行输入并创建了一个卷,该命令应该是run_execute以外的其他内容,但是我空着手搜索任何有效的东西。
您不会在规范中使用节点属性,测试的重点是手动扩展它以确保您的代码正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.