Skip to content

Commit 4f05350

Browse files
authored
Rename TestCases parameter to ForEach (#2311)
1 parent bb175b4 commit 4f05350

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/functions/Context.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
# [Switch] $Focus,
8383
[Switch] $Skip,
8484

85+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '', Justification = 'ForEach is not used in Foreach-Object loop')]
8586
$ForEach
8687
)
8788

src/functions/Describe.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
# [Switch] $Focus,
9191
[Switch] $Skip,
9292

93+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '', Justification = 'ForEach is not used in Foreach-Object loop')]
9394
$ForEach
9495
)
9596

src/functions/It.ps1

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
commenting out a test, because the test remains listed in the output. Use the Strict parameter
3939
of Invoke-Pester to force all skipped tests to fail.
4040
41-
.PARAMETER TestCases
42-
Optional array of hashtable (or any IDictionary) objects. If this parameter is used,
43-
Pester will call the test script block once for each table in the TestCases array,
44-
splatting the dictionary to the test script block as input. If you want the name of
45-
the test to appear differently for each test case, you can embed tokens into the Name
41+
.PARAMETER ForEach
42+
(Formerly called TestCases.) Optional array of hashtable (or any IDictionary) objects.
43+
If this parameter is used, Pester will call the test script block once for each table in
44+
the ForEach array, splatting the dictionary to the test script block as input. If you want
45+
the name of the test to appear differently for each test case, you can embed tokens into the Name
4646
parameter with the syntax 'Adds numbers <A> and <B>' (assuming you have keys named A and B
47-
in your TestCases hashtables.)
47+
in your ForEach hashtables.)
4848
4949
.PARAMETER Tag
5050
Optional parameter containing an array of strings. When calling Invoke-Pester,
@@ -97,14 +97,14 @@
9797
@{ a = 'two'; b = 'three'; expectedResult = 'twothree' }
9898
)
9999
100-
It 'Correctly adds <a> and <b> to get <expectedResult>' -TestCases $testCases {
100+
It 'Correctly adds <a> and <b> to get <expectedResult>' -ForEach $testCases {
101101
$sum = Add-Numbers $a $b
102102
$sum | Should -Be $expectedResult
103103
}
104104
}
105105
```
106106
107-
Using It with -TestCases to run the same tests with different parameters and expected results.
107+
Using It with -ForEach to run the same tests with different parameters and expected results.
108108
Each hashtable in the `$testCases`-array generates one tests to a total of four. Each key-value pair in the
109109
current hashtable are made available as variables inside It.
110110
@@ -128,8 +128,9 @@
128128
[Parameter(Position = 1)]
129129
[ScriptBlock] $Test,
130130

131-
[Alias("ForEach")]
132-
[object[]] $TestCases,
131+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '', Justification = 'ForEach is not used in Foreach-Object loop')]
132+
[Alias("TestCases")]
133+
[object[]] $ForEach,
133134

134135
[String[]] $Tag,
135136

@@ -162,9 +163,9 @@
162163
}
163164
}
164165

165-
if ($PSBoundParameters.ContainsKey('TestCases')) {
166-
if ($null -ne $TestCases -and 0 -lt @($TestCases).Count) {
167-
New-ParametrizedTest -Name $Name -ScriptBlock $Test -StartLine $MyInvocation.ScriptLineNumber -Data $TestCases -Tag $Tag -Focus:$Focus -Skip:$Skip
166+
if ($PSBoundParameters.ContainsKey('ForEach')) {
167+
if ($null -ne $ForEach -and 0 -lt @($ForEach).Count) {
168+
New-ParametrizedTest -Name $Name -ScriptBlock $Test -StartLine $MyInvocation.ScriptLineNumber -Data $ForEach -Tag $Tag -Focus:$Focus -Skip:$Skip
168169
}
169170
else {
170171
# @() or $null is provided do nothing

0 commit comments

Comments
 (0)