-
Notifications
You must be signed in to change notification settings - Fork 3
Managing Mocks
Jon Wagner edited this page Feb 8, 2013
·
1 revision
First, make sure you have imported the PSMock module and enabled mocking in your script:
Import-Module PSMock
Enable-Mock | iex
function Hello { param ([string] $who) "Hello, $who" }
You can remove all of the mocks for a function with Remove-Mock.
Mock Hello { "goodbye" }
Hello # "goodbye"
Remove-Mock Hello
Hello # "Hello, "
If you create more than one case for a mock, you can remove them individually if you name them:
Mock Hello { } -When { $who -eq 'bob' } -Name Bob
Mock Hello { "Howdy!" }
Hello bob # nothing
Remove-Mock Hello -Case Bob
Hello bob # "Howdy!"
You can clear all mocks in the current mock context with Clear-Mocks.
Mock Hello { "goodbye" }
Hello # "goodbye"
Clear-Mocks
Hello # "Hello, "
If you force import the PSMock module, it will clear all mocks and mock contexts.
Import-Module PSMock -Force
# bye bye mocks