2

我的食谱中有以下代码,它运行返回用户(root 除外)的 bash 脚本。每行 1 个用户。

ruby_block "Delete users" do
   action  :run
   block do
      users = Mixlib::ShellOut.new("whatever command with lines containing users").run_command.stdout
      users.each_line do |user|
         ex = Chef::Resource::Execute.new("Removing User: #{user}", run_context)
         ex.command "remove user"
         ex.run_action(:run)
      end
   end
end

现在我设法模拟 shell 了Here,但我不知道为什么以及是否可以期待这样的资源。例如,如果命令返回

user1
user2

然后以下将起作用

allow(shellout).to receive("whatever command with lines containing users").and_return("user1")
expect(chef_run).to run_ruby_block('Delete users')

但是如果我添加以下内容

expect(chef_run).to run_execute('Removing User: user1')

它会失败,而在上下文中没有我没有涵盖的任何资源。(我正在使用 Chef::Coverage 所以我知道)。谢谢

4

0 回答 0