2

I have following code in my recipe, which runs bash script that returns users (except root). 1 user per line.

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

Now I managed to mock shell out Here, but I can't figure out why and if it is possible to expect such resources. For instance if command returns

user1
user2

Then following will work

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

But if I add following

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

It will fail, while there isn't any resources in context that I haven't cover. (I am using Chef::Coverage so I know). Thanks

Lukino
  • 1,407
  • 13
  • 14
  • 1
    You not adding a resource to the resource collection, you're instanciating a class within your ruby_block. What happens inside is unknown from the chef run above (unless it raise an exception), according to your code, it could be done as plain ruby in the recipe (if it can be computed at compile time and not at converge) – Tensibai Apr 27 '15 at 07:55

0 Answers0