Skip to content

Commit b7ab018

Browse files
Update examples-module to use Pester 5 (#3214)
This resolves #3049. Only real changes needed were wrapping the initialization in a `BeforeAll` block and changing `Be` to `-Be`.
1 parent 8700ee0 commit b7ab018

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

examples/Tests/PathProcessing.Tests.ps1

+35-32
Original file line numberDiff line numberDiff line change
@@ -8,102 +8,105 @@
88
# test task runner defined in .vscode\tasks.json.
99

1010
# This (empty) file is required by some of the tests.
11-
$null = New-Item -Path "$PSScriptRoot\foo[1].txt" -Force
1211

13-
Import-Module $PSScriptRoot\..\SampleModule.psd1
12+
BeforeAll {
13+
$null = New-Item -Path "$PSScriptRoot\foo[1].txt" -Force
1414

15-
$WorkspaceRoot = Convert-Path $PSScriptRoot/..
16-
Set-Location $WorkspaceRoot
15+
Import-Module $PSScriptRoot\..\SampleModule.psd1
16+
17+
$WorkspaceRoot = Convert-Path $PSScriptRoot/..
18+
Set-Location $WorkspaceRoot
19+
}
1720

1821
Describe 'Verify Path Processing for Non-existing Paths Allowed Impl' {
1922
It 'Processes non-wildcard absolute path to non-existing file via -Path param' {
20-
New-File -Path $WorkspaceRoot\ReadmeNew.md | Should Be "$WorkspaceRoot\READMENew.md"
23+
New-File -Path $WorkspaceRoot\ReadmeNew.md | Should -Be "$WorkspaceRoot\READMENew.md"
2124
}
2225
It 'Processes multiple absolute paths via -Path param' {
2326
New-File -Path $WorkspaceRoot\Readme.md, $WorkspaceRoot\XYZZY.ps1 |
24-
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
27+
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
2528
}
2629
It 'Processes relative path via -Path param' {
27-
New-File -Path ..\Examples\READMENew.md | Should Be "$WorkspaceRoot\READMENew.md"
30+
New-File -Path ..\Examples\READMENew.md | Should -Be "$WorkspaceRoot\READMENew.md"
2831
}
2932
It 'Processes multiple relative path via -Path param' {
3033
New-File -Path ..\Examples\README.md, XYZZY.ps1 |
31-
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
34+
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
3235
}
3336

3437
It 'Should accept pipeline input to Path' {
35-
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | New-File | Should Be "$PSScriptRoot\foo[1].txt"
38+
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | New-File | Should -Be "$PSScriptRoot\foo[1].txt"
3639
}
3740
}
3841

3942
Describe 'Verify Path Processing for NO Wildcards Allowed Impl' {
4043
It 'Processes non-wildcard absolute path via -Path param' {
41-
Import-FileNoWildcard -Path $WorkspaceRoot\Readme.md | Should Be "$WorkspaceRoot\README.md"
44+
Import-FileNoWildcard -Path $WorkspaceRoot\Readme.md | Should -Be "$WorkspaceRoot\README.md"
4245
}
4346
It 'Processes multiple absolute paths via -Path param' {
4447
Import-FileNoWildcard -Path $WorkspaceRoot\Readme.md, $WorkspaceRoot\PathProcessingWildcards.ps1 |
45-
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
48+
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
4649
}
4750
It 'Processes relative path via -Path param' {
48-
Import-FileNoWildcard -Path ..\examples\README.md | Should Be "$WorkspaceRoot\README.md"
51+
Import-FileNoWildcard -Path ..\examples\README.md | Should -Be "$WorkspaceRoot\README.md"
4952
}
5053
It 'Processes multiple relative path via -Path param' {
5154
Import-FileNoWildcard -Path ..\examples\README.md, .vscode\launch.json |
52-
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
55+
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
5356
}
5457

5558
It 'Should accept pipeline input to Path' {
56-
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileNoWildcard | Should Be "$PSScriptRoot\foo[1].txt"
59+
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileNoWildcard | Should -Be "$PSScriptRoot\foo[1].txt"
5760
}
5861
}
5962

6063
Describe 'Verify Path Processing for Wildcards Allowed Impl' {
6164
It 'Processes non-wildcard absolute path via -Path param' {
62-
Import-FileWildcard -Path $WorkspaceRoot\Readme.md | Should Be "$WorkspaceRoot\README.md"
65+
Import-FileWildcard -Path $WorkspaceRoot\Readme.md | Should -Be "$WorkspaceRoot\README.md"
6366
}
6467
It 'Processes multiple absolute paths via -Path param' {
6568
Import-FileWildcard -Path $WorkspaceRoot\Readme.md, $WorkspaceRoot\PathProcessingWildcards.ps1 |
66-
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
69+
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
6770
}
6871
It 'Processes wildcard absolute path via -Path param' {
6972
$files = Import-FileWildcard -Path $WorkspaceRoot\*.psd1
70-
$files.Count | Should Be 2
71-
$files[0] | Should Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
72-
$files[1] | Should Be "$WorkspaceRoot\SampleModule.psd1"
73+
$files.Count | Should -Be 2
74+
$files[0] | Should -Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
75+
$files[1] | Should -Be "$WorkspaceRoot\SampleModule.psd1"
7376
}
7477
It 'Processes wildcard relative path via -Path param' {
7578
$files = Import-FileWildcard -Path *.psd1
76-
$files.Count | Should Be 2
77-
$files[0] | Should Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
78-
$files[1] | Should Be "$WorkspaceRoot\SampleModule.psd1"
79+
$files.Count | Should -Be 2
80+
$files[0] | Should -Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
81+
$files[1] | Should -Be "$WorkspaceRoot\SampleModule.psd1"
7982
}
8083
It 'Processes relative path via -Path param' {
81-
Import-FileWildcard -Path ..\examples\README.md | Should Be "$WorkspaceRoot\README.md"
84+
Import-FileWildcard -Path ..\examples\README.md | Should -Be "$WorkspaceRoot\README.md"
8285
}
8386
It 'Processes multiple relative path via -Path param' {
8487
Import-FileWildcard -Path ..\examples\README.md, .vscode\launch.json |
85-
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
88+
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
8689
}
8790

88-
It 'DefaultParameterSet should be Path' {
91+
It 'DefaultParameterSet should -be Path' {
8992
$files = Import-FileWildcard *.psd1
90-
$files.Count | Should Be 2
91-
$files[0] | Should Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
92-
$files[1] | Should Be "$WorkspaceRoot\SampleModule.psd1"
93+
$files.Count | Should -Be 2
94+
$files[0] | Should -Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
95+
$files[1] | Should -Be "$WorkspaceRoot\SampleModule.psd1"
9396
}
9497

9598
It 'Should process absolute literal paths via -LiteralPath param'{
96-
Import-FileWildcard -LiteralPath "$PSScriptRoot\foo[1].txt" | Should Be "$PSScriptRoot\foo[1].txt"
99+
Import-FileWildcard -LiteralPath "$PSScriptRoot\foo[1].txt" | Should -Be "$PSScriptRoot\foo[1].txt"
97100
}
98101
It 'Should process relative literal paths via -LiteralPath param'{
99-
Import-FileWildcard -LiteralPath "..\examples\Tests\foo[1].txt" | Should Be "$PSScriptRoot\foo[1].txt"
102+
Import-FileWildcard -LiteralPath "..\examples\Tests\foo[1].txt" | Should -Be "$PSScriptRoot\foo[1].txt"
100103
}
101104
It 'Should process multiple literal paths via -LiteralPath param'{
102105
Import-FileWildcard -LiteralPath "..\examples\Tests\foo[1].txt", "$WorkspaceRoot\README.md" |
103-
Should Be @("$PSScriptRoot\foo[1].txt", "$WorkspaceRoot\README.md")
106+
Should -Be @("$PSScriptRoot\foo[1].txt", "$WorkspaceRoot\README.md")
104107
}
105108

106109
It 'Should accept pipeline input to LiteralPath' {
107-
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileWildcard | Should Be "$PSScriptRoot\foo[1].txt"
110+
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileWildcard | Should -Be "$PSScriptRoot\foo[1].txt"
108111
}
109112
}

examples/Tests/SampleModule.Tests.ps1

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
$ModuleManifestName = 'SampleModule.psd1'
2-
Import-Module $PSScriptRoot\..\$ModuleManifestName
3-
1+
BeforeAll {
2+
$ModuleManifestName = 'SampleModule.psd1'
3+
Import-Module $PSScriptRoot\..\$ModuleManifestName
4+
}
45
Describe 'Module Manifest Tests' {
56
It 'Passes Test-ModuleManifest' {
67
Test-ModuleManifest -Path $PSScriptRoot\..\$ModuleManifestName
7-
$? | Should Be $true
8+
$? | Should -Be $true
89
}
910
}

0 commit comments

Comments
 (0)