module ChefSpec::API::StubsFor

def receive_shell_out(*cmd, stdout: "", stderr: "", exitstatus: 0, **opts)

def receive_shell_out(*cmd, stdout: "", stderr: "", exitstatus: 0, **opts)
  # Ruby does not allow constructing an actual exitstatus object from Ruby code. Really.
  fake_exitstatus = double(exitstatus: exitstatus)
  fake_cmd = Mixlib::ShellOut.new(*cmd)
  fake_cmd.define_singleton_method(:run_command) {} # Do nothing, just in case.
  # Inject our canned data.
  fake_cmd.instance_exec do
    @stdout = stdout
    @stderr = stderr
    @status = fake_exitstatus
  end
  # On newer Chef, we can intercept using the new, better shell_out_compact hook point.
  shell_out_method ||= if HAS_SHELLOUT_COMPACTED.satisfied_by?(Gem::Version.create(Chef::VERSION))
                         :shell_out_compacted
                       else
                         :shell_out
                       end
  with_args = cmd + (opts.empty? ? [any_args] : [hash_including(opts)])
  receive(shell_out_method).with(*with_args).and_return(fake_cmd)
end