【问题标题】:How to write chef spec for following cookbook如何为以下食谱编写厨师规格
【发布时间】:2021-08-16 10:00:11
【问题描述】:

这是我的食谱.rb

require 'mixlib/shellout'
require "pry"

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

我应该在我的规范中写什么?

【问题讨论】:

  • 您希望规范测试什么?是否执行了某个命令?某件事已被打印到 STDOUT?顺便说一句,我不确定这是否符合您的期望......它实际上是在打印字符串 "hostname -I";它实际上并没有运行hostname 命令。我不认为你打算在那里写echo
  • 我想运行这个命令并显示标准输出

标签: ruby rspec chefspec


【解决方案1】:

您不需要 echo 命令来获取输出。可以直接通过mixlib/shellout运行命令,然后获取stdout的命令输出。

require 'mixlib/shellout'

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多