有没有办法在 ruby 中模拟 Facter::Core::Execution.execute 输出?

Is there a way to mock Facter::Core::Execution.execute output in ruby?

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

使用rspec:

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