rubytestingmockingpuppetfacter

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


I have a custom fact in ruby that uses Facter::Core::Execution.execute to execute a system command and sets the fact to true or false based on the output of the execute command. Is there a way I could mock the output of the execute command to test it?


Solution

  • Using rspec:

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