Examples/Validator/Validator.Steps.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$global:ValidatorRoot = Split-Path $MyInvocation.MyCommand.Path

BeforeEachFeature {
    New-Module -Name ValidatorTest {
        . $global:ValidatorRoot\Validator.ps1 -Verbose
    } | Import-Module -Global
}

AfterEachFeature {
    Remove-Module ValidatorTest
}

Given 'MyValidator is mocked to return True' {
    Mock MyValidator -Module ValidatorTest -MockWith { return $true }
}

When 'Someone calls something that uses MyValidator' {
    Invoke-SomethingThatUsesMyValidator "false"
}

Then 'MyValidator gets called once' {
    Assert-MockCalled -Module ValidatorTest MyValidator 1
}

Given 'MyValidator' {}

When 'MyValidator is called with (?<word>\w+)' {
    param($word)
    $Validation = MyValidator $word
}

Then 'MyValidator should return (?<expected>\w+)' {
    param($expected)
    $expected = $expected -eq "true"
    $Validation | Should Be $expected
}