Skip to content

Commit 51865e4

Browse files
committed
Simplify failing test by inlining it and don't check the message as all we should really check is the rule violation
1 parent 0f562df commit 51865e4

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

Tests/Rules/AvoidPositionalParameters.ps1

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
Import-Module PSScriptAnalyzer
2-
$violationMessage = "Cmdlet 'Get-Command' has positional parameter. Please use named parameters instead of positional parameters when calling a command."
3-
$violationName = "PSAvoidUsingPositionalParameters"
4-
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
5-
$violations = Invoke-ScriptAnalyzer $directory\AvoidPositionalParameters.ps1 | Where-Object {$_.RuleName -eq $violationName}
6-
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidPositionalParametersNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
7-
$noViolationsDSC = Invoke-ScriptAnalyzer -ErrorAction SilentlyContinue $directory\serviceconfigdisabled.ps1 | Where-Object {$_.RuleName -eq $violationName}
82

93
Describe "AvoidPositionalParameters" {
4+
BeforeAll {
5+
$directory = $PSScriptRoot
6+
$violationName = "PSAvoidUsingPositionalParameters"
7+
$violation = Invoke-ScriptAnalyzer -ScriptDefinition 'Get-Command "abc" 4 4.3'
8+
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidPositionalParametersNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
9+
$noViolationsDSC = Invoke-ScriptAnalyzer -ErrorAction SilentlyContinue $directory\serviceconfigdisabled.ps1 | Where-Object {$_.RuleName -eq $violationName}
10+
}
1011
Context "When there are violations" {
1112
It "has 1 avoid positional parameters violation" {
12-
$violations.Count | Should -Be 1
13-
}
14-
15-
It "has the correct description message" {
16-
$violations[0].Message | Should -Match $violationMessage
13+
@($violation).Count | Should -Be 1
14+
$violation.RuleName | Should -Be $violationName
1715
}
18-
1916
}
2017

2118
Context "When there are no violations" {
@@ -27,4 +24,4 @@ Describe "AvoidPositionalParameters" {
2724
$noViolationsDSC.Count | Should -Be 0
2825
}
2926
}
30-
}
27+
}

0 commit comments

Comments
 (0)