forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGherkinHook.Tests.ps1
113 lines (78 loc) · 4.51 KB
/
GherkinHook.Tests.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
if ($PSVersionTable.PSVersion.Major -le 2) { return }
Set-StrictMode -Version Latest
Describe 'Testing Gerkin Hook' {
It 'Generates a function named "BeforeEachFeature" with mandatory Tags and Script parameters' {
$command = &(Get-Module Pester) { Get-Command BeforeEachFeature -Module Pester }
$command | Should Not Be $null
$parameter = $command.Parameters['Tags']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'String[]'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
$parameter = $command.Parameters['Script']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'ScriptBlock'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
}
It 'Generates a function named "BeforeEachScenario" with mandatory Tags and Script parameters' {
$command = &(Get-Module Pester) { Get-Command BeforeEachScenario -Module Pester }
$command | Should Not Be $null
$parameter = $command.Parameters['Tags']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'String[]'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
$parameter = $command.Parameters['Script']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'ScriptBlock'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
}
It 'Generates a function named "AfterEachScenario" with mandatory Tags and Script parameters' {
$command = &(Get-Module Pester) { Get-Command AfterEachScenario -Module Pester }
$command | Should Not Be $null
$parameter = $command.Parameters['Tags']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'String[]'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
$parameter = $command.Parameters['Script']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'ScriptBlock'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
}
It 'Generates a function named "AfterEachFeature" with mandatory Tags and Script parameters' {
$command = &(Get-Module Pester) { Get-Command AfterEachFeature -Module Pester }
$command | Should Not Be $null
$parameter = $command.Parameters['Tags']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'String[]'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
$parameter = $command.Parameters['Script']
$parameter | Should Not Be $null
$parameter.ParameterType.Name | Should Be 'ScriptBlock'
$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory
$isMandatory | Should Be $true
}
It 'Populates the GherkinHooks module variable' {
& ( Get-Module Pester ) {
BeforeEachScenario "I Click" { }
$GherkinHooks["BeforeEachScenario"].Tags
} | Select -Last 1 | Should Be "I Click"
& ( Get-Module Pester ) {
AfterEachFeature "I Click" { }
$GherkinHooks["AfterEachFeature"].Tags
} | Select -Last 1 | Should Be "I Click"
}
}