Skip to content

Commit cca71cb

Browse files
committed
test: 🧪 Update tests for Initialize-PredefinedVariables
* Refactor test structure for improved readability * Ensure all predefined variables are initialized correctly * Validate that `PLASTER_TemplatePath` and `PLASTER_DestinationPath` match expected values
1 parent 05c01a5 commit cca71cb

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
BeforeDiscovery {
2-
if ($null -eq $env:BHProjectPath) {
3-
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4-
. $path -Task Build
5-
}
6-
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
7-
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
8-
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
9-
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
10-
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
11-
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
12-
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
6+
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
7+
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
8+
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
9+
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
10+
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
11+
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
12+
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
1313
}
1414
Describe 'Initialize-PredefinedVariables' {
15-
InModuleScope $env:BHProjectName {
16-
BeforeDiscovery {
17-
$script:variables = @(
18-
'PLASTER_TemplatePath',
19-
'PLASTER_DestinationPath',
20-
'PLASTER_DestinationName',
21-
'PLASTER_DirSepChar',
22-
'PLASTER_HostName',
23-
'PLASTER_Version',
24-
'PLASTER_Guid1',
25-
'PLASTER_Guid2',
26-
'PLASTER_Guid3',
27-
'PLASTER_Guid4',
28-
'PLASTER_Guid5',
29-
'PLASTER_Date',
30-
'PLASTER_Time',
31-
'PLASTER_Year'
32-
)
33-
foreach ($var in $script:variables) {
34-
if (Get-Variable -Name $var -ErrorAction SilentlyContinue) {
35-
Remove-Variable -Name $var -Scope Script
15+
InModuleScope $env:BHProjectName {
16+
BeforeDiscovery {
17+
$script:variables = @(
18+
'PLASTER_TemplatePath',
19+
'PLASTER_DestinationPath',
20+
'PLASTER_DestinationName',
21+
'PLASTER_DirSepChar',
22+
'PLASTER_HostName',
23+
'PLASTER_Version',
24+
'PLASTER_Guid1',
25+
'PLASTER_Guid2',
26+
'PLASTER_Guid3',
27+
'PLASTER_Guid4',
28+
'PLASTER_Guid5',
29+
'PLASTER_Date',
30+
'PLASTER_Time',
31+
'PLASTER_Year'
32+
)
33+
foreach ($var in $script:variables) {
34+
if (Get-Variable -Name $var -ErrorAction SilentlyContinue) {
35+
Remove-Variable -Name $var -Scope Script
36+
}
37+
}
38+
}
39+
BeforeAll {
40+
$script:examplesPath = Resolve-Path "$env:BHProjectPath/examples/"
41+
$script:destPath = 'Test:\Destination'
42+
$script:output = Initialize-PredefinedVariables -TemplatePath $script:examplesPath -DestPath $script:destPath
43+
}
44+
It 'should not return any output' {
45+
$script:output | Should -BeNullOrEmpty
3646
}
37-
}
38-
}
39-
BeforeAll {
40-
$script:examplesPath = Resolve-Path "$env:BHProjectPath/examples/"
41-
$script:destPath = 'Test:\Destination'
42-
$script:output = Initialize-PredefinedVariables -TemplatePath $script:examplesPath -DestPath $script:destPath
43-
}
44-
It 'should not return any output' {
45-
$script:output | Should -BeNullOrEmpty
46-
}
4747

48-
It "initializes predefined variable <_>" -ForEach $script:variables {
49-
$varValue = Get-Variable -name $_ -Scope Script -ErrorAction SilentlyContinue
50-
$varValue | Should -Not -BeNullOrEmpty
51-
}
48+
It "initializes predefined variable <_>" -ForEach $script:variables {
49+
$varValue = Get-Variable -Name $_ -Scope Script -ErrorAction SilentlyContinue
50+
$varValue | Should -Not -BeNullOrEmpty
51+
}
5252

53-
It 'PLASTER_TemplatePath should match the provided template path' {
54-
$expectedPath = $script:examplesPath.TrimEnd('\', '/')
55-
$actualPath = (Get-Variable -Name 'PLASTER_TemplatePath' -Scope Script).Value
56-
$actualPath | Should -Be $expectedPath
57-
}
53+
It 'PLASTER_TemplatePath should match the provided template path' {
54+
$expectedPath = ($script:examplesPath).ToString().TrimEnd('\', '/')
55+
$actualPath = (Get-Variable -Name 'PLASTER_TemplatePath' -Scope Script).Value
56+
$actualPath | Should -Be $expectedPath
57+
}
5858

59-
It 'PLASTER_DestinationPath should match the provided destination path' {
60-
$expectedPath = $script:destPath.TrimEnd('\', '/')
61-
$actualPath = (Get-Variable -Name 'PLASTER_DestinationPath' -Scope Script).Value
62-
$actualPath | Should -Be $expectedPath
59+
It 'PLASTER_DestinationPath should match the provided destination path' {
60+
$expectedPath = ($script:destPath).ToString().TrimEnd('\', '/')
61+
$actualPath = (Get-Variable -Name 'PLASTER_DestinationPath' -Scope Script).Value
62+
$actualPath | Should -Be $expectedPath
63+
}
6364
}
64-
}
6565
}

0 commit comments

Comments
 (0)