Chefspec 如何在没有更新的情况下对 update_apt_update 进行单元测试

Chefspec how to unit test for update_apt_update without update

我有以下厨师代码:

apt_update 'Ubuntu apt repo update' do
  subscribes :nothing, 'apt_repository[some-repo]', :immediately
end

我正在尝试使用此代码进行测试:

it 'updates apt repo' do
  expect(chef_run).to update_apt_update('Ubuntu apt repo update')
end

失败

expected "apt_update[Ubuntu apt repo update]" with action :update to be in Chef run.

Other apt_update resources: apt_update[Ubuntu apt repo update]

它似乎在尝试断言我的操作是更新的,我该如何让它不假设我的操作?

在 chefspec 中,您已经告诉它期待 update_apt_update 所以它期待来自资源的更新操作。所以,它不是假设你的行为,也不是试图断言任何事情。 chefspec 非常简单,因为它试图避免人们做他们不想做的事情。

在配方部分,请添加您已经在测试的操作。

apt_update 'Ubuntu apt repo update' do
action :update
subscribes :nothing, 'apt_repository[some-repo]', :immediately
end

当我需要帮助时,我总是会从 sethvargo 获取这些 chefspec 示例。

chefspec examples