rubyrspecchefspec

How to write chef spec for following cookbook?


This is my recipe.rb:

require 'mixlib/shellout'
require "pry"

find = Mixlib::ShellOut.new("echo hostname -I")
find.run_command.stdout

What should I write it in my spec?


Solution

  • You don't need the echo command to get the output. you can directly run the command through mixlib/shellout and get then get the command output from stdout.

    require 'mixlib/shellout'
    
    find = Mixlib::ShellOut.new("hostname -I")
    find.run_command.stdout