Skip to content
Jon Wagner edited this page Feb 18, 2013 · 1 revision

PSate with PSMock

PSate works really well with PSMock. If you have PSMock installed as a global module, or already imported into the current session, PSate will automatically enable mocks and create a new MockContext around each test context. That means the mocks in your TestSetup code will have the scope that you would expect.

Describing "Calculator" {
    Given "two numbers" {
        TestSetup {
            Mock Add-Numbers { param ([int]$a, [int]$b) $a + $b }

            $x = 1
            $y = 2
            $z = 3
        }

        It "adds properly" {
            Add-Numbers $x $y | Should Be $z
        }
    }
}

In this case, Add-Numbers is mocked for the duration of the Given "two numbers" block. The mock is automatically removed at the end of the block.