用'执行'写主厨rspec测试

问题描述 投票:0回答:1

在我的.rb文件中,我正在尝试针对这行代码编写规范测试(我没有编写此代码):

execute "lvcreate -L #{node['ami_base']['opt']} -n opt vgpool"

在我的_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

当我尝试:

chef exec rspec....._spec.rb

我收到此错误:

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)>'

我写了很多针对execute的测试,他们都取得了成功。我是否需要修改规范帮助文件?我觉得它是一个命令行输入并创建一个卷,该命令应该是run_execute以外的其他东西,但我在我搜索任何有效的东西时空手而归。

ruby ubuntu rspec chef chefspec
1个回答
0
投票

您不要在规范中使用节点属性,测试的目的是手动扩展它以确保您的代码有效。

© www.soinside.com 2019 - 2024. All rights reserved.