Support injecting mock functionality into modules

Add mock registry for a single module.
This commit is contained in:
Michael Miller 2022-12-18 19:04:50 -07:00
parent a3c55dfa47
commit 8f80b10fc1
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 64 additions and 1 deletions

View file

@ -205,6 +205,25 @@ Spectator.describe "Mocks Docs" do
runnable = mock(Runnable2, command: "echo foo")
expect(runnable.run_one).to eq("Running echo foo")
end
context "Injecting Mocks" do
module MyFileUtils
def self.rm_rf(path)
true
end
end
inject_mock MyFileUtils do
stub def self.rm_rf(path)
"Simulating deletion of #{path}"
false
end
end
specify do
expect(MyFileUtils.rm_rf("/")).to be_false
end
end
end
context "Injecting Mocks" do