【问题标题】:Is there a way to mock Facter::Core::Execution.execute output in ruby?有没有办法在 ruby​​ 中模拟 Facter::Core::Execution.execute 输出?
【发布时间】:2020-05-28 19:27:21
【问题描述】:

我在 ruby​​ 中有一个自定义事实,它使用Facter::Core::Execution.execute 执行系统命令,并根据执行命令的输出将事实设置为 true 或 false。有没有办法可以模拟执行命令的输出来测试它?

【问题讨论】:

  • 你用的是什么测试框架?
  • @maxpleaner 我可以使用 rspec 或 pytest

标签: ruby testing mocking puppet facter


【解决方案1】:

使用 rspec:

expect(Facter::Core::Execution).to receive(:execute).and_return(true)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 2011-07-24
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多