Consider the following test.
RSpec.describe Commands::StartRecording do
it "spawns one recording process per camera" do
expect(ProcessManager).to receive(:spawn).with(/camera_11/).and_return(123)
expect(ProcessManager).to receive(:spawn).with(/camera_22/).and_return(456)
allow(ProcessManager).to receive(:exists?).with(123).and_return(true)
allow(ProcessManager).to receive(:exists?).with(456).and_return(true)
result = Commands::StartRecording.(cameras: [11, 22])
expect(result).to be_successful
end
# (more tests here)
end
I will be using RSpec in this article, but the concept applies equally well to Minitest.
This test checks that Commands::StartRecording spawns multiple processes via ProcessManager.
We don’t want to actually spawn any processes during testing, so methods on ProcessManager have been mocked out using RSpec Mocks.
There are a few problems with this test.