Skip to content

Commit ffc0af6

Browse files
author
petru
committed
refr: Refactor test files
Remove warnings when importing the PesteExtensions module
1 parent 5b65653 commit ffc0af6

File tree

7 files changed

+89
-12
lines changed

7 files changed

+89
-12
lines changed

src/PesterExtensions/Public/Mock-EnvironmentVariable.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Mock-EnvironmentVariable {
1010

1111
[Parameter(Mandatory = $false)]
1212
[System.EnvironmentVariableTarget]
13-
$Target = [System.EnvironmentVariableTarget]::Process,
13+
$Targets = [EnvironmentVariableTarget]::Process,
1414

1515
[Parameter(Mandatory = $true, Position = 1)]
1616
[ScriptBlock]
@@ -59,7 +59,7 @@ function Mock-EnvironmentVariable {
5959
.PARAMETER Fixture
6060
The code to be executed.
6161
62-
.PARAMETER Target
62+
.PARAMETER Targets
6363
Specifies that user environment variable should also be managed.
6464
#>
6565
}

tests/PesterExtensions/PesterExtensions.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ param(
33
)
44

55
BeforeAll {
6-
Import-Module -Name PesterExtensions
6+
Import-Module -Name PesterExtensions -DisableNameChecking
77
$ModulePath = "$(Get-ScriptPath -Path $PSCommandPath -Extension Manifest)"
88
Remove-Module -Name PesterExtensions
99

1010
$script:ModuleInfo = Test-ModuleManifest -Path $ModulePath
1111

12-
Import-Module $ModulePath
12+
Import-Module $ModulePath -DisableNameChecking
1313
$script:ImportedModule = Get-Module 'PesterExtensions'
1414
}
1515

@@ -73,7 +73,7 @@ Describe 'Check functions' -ForEach @(
7373
Parameters = @(
7474
@{ Parameter = 'Variable'; Mandatory = $true }
7575
@{ Parameter = 'Value'; Mandatory = $false }
76-
@{ Parameter = 'Target'; Mandatory = $false }
76+
@{ Parameter = 'Targets'; Mandatory = $false }
7777
@{ Parameter = 'Fixture'; Mandatory = $true }
7878
)
7979
}

tests/PesterExtensions/Private/PathUtilities.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name PesterExtensions
2+
Import-Module -Name PesterExtensions -DisableNameChecking
33
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
44
Remove-Module -Name PesterExtensions
55
}

tests/PesterExtensions/Public/Get-ProjectRoot.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name PesterExtensions
2+
Import-Module -Name PesterExtensions -DisableNameChecking
33
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
44
Remove-Module -Name PesterExtensions
55
}

tests/PesterExtensions/Public/Get-ScriptPath.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name PesterExtensions
2+
Import-Module -Name PesterExtensions -DisableNameChecking
33
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
44
Remove-Module -Name PesterExtensions
55
}

tests/PesterExtensions/Public/Mock-EnvironmentVariable.Tests.ps1

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name PesterExtensions
2+
Import-Module -Name PesterExtensions -DisableNameChecking
33
. "$(Get-ScriptPath -Path $PSCommandPath)"
44
Remove-Module -Name PesterExtensions
55
}
@@ -96,6 +96,83 @@ Describe 'Check env mocking' -ForEach @(
9696
}
9797
}
9898

99+
# Describe 'Check env mocking' -ForEach @(
100+
# @{
101+
# InitialValue = 'Initial Value';
102+
# MockedValue = 'Mocked Value';
103+
# ValueInsideTheScript = 'Mocked Value';
104+
# TargetsToSet = @([EnvironmentVariableTarget]::Process)
105+
# TargetNotToSet = ''
106+
# Script = { }
107+
# }
108+
# @{
109+
# InitialValue = $null;
110+
# MockedValue = 'Mocked Value';
111+
# ValueInsideTheScript = 'Mocked Value';
112+
# Script = { }
113+
# }
114+
# @{
115+
# InitialValue = 'Initial Value';
116+
# MockedValue = $null;
117+
# ValueInsideTheScript = 'Initial Value';
118+
# Script = { }
119+
# }
120+
# @{
121+
# Script = { }
122+
# }
123+
# @{
124+
# InitialValue = 'Initial Value';
125+
# MockedValue = 'Mocked Value';
126+
# ValueInsideTheScript = 'Mocked Value';
127+
# Script = {
128+
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
129+
# }
130+
# }
131+
# @{
132+
# InitialValue = 'Initial Value';
133+
# MockedValue = $null;
134+
# ValueInsideTheScript = 'Initial Value';
135+
# Script = {
136+
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
137+
# }
138+
# }
139+
# @{
140+
# InitialValue = $null;
141+
# MockedValue = 'Mocked Value';
142+
# ValueInsideTheScript = 'Mocked Value';
143+
# Script = {
144+
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
145+
# }
146+
# }
147+
# @{
148+
# InitialValue = $null;
149+
# MockedValue = $null;
150+
# ValueInsideTheScript = $null;
151+
# Script = {
152+
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
153+
# }
154+
# }
155+
# ) {
156+
# BeforeAll {
157+
# $environmentVariableName = "test_$(New-Guid)"
158+
# [Environment]::SetEnvironmentVariable($environmentVariableName, $InitialValue)
159+
# }
160+
# It 'Test' {
161+
# Mock-EnvironmentVariable `
162+
# -Variable $environmentVariableName `
163+
# -Value $MockedValue {
164+
# [Environment]::GetEnvironmentVariable($environmentVariableName) | Should -Be $ValueInsideTheScript
165+
# Invoke-Command -ScriptBlock $script -ArgumentList $environmentVariableName
166+
# }
167+
# [Environment]::GetEnvironmentVariable($environmentVariableName) | Should -Be $InitialValue
168+
# }
169+
# AfterAll {
170+
# [Environment]::SetEnvironmentVariable($environmentVariableName, $null)
171+
# }
172+
# }
173+
174+
175+
99176
Describe 'Should throw' -ForEach @(
100177
@{
101178
InitialValue = 'Initial Value';

tests/PesterExtensions/Public/Test-SemanticVersionUpdate.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BeforeAll {
2-
Import-Module -Name PesterExtensions
2+
Import-Module -Name PesterExtensions -DisableNameChecking
33
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
44
Remove-Module -Name PesterExtensions
55
}
@@ -56,7 +56,7 @@ Describe 'Returns true' {
5656
@{Current = '1.1.1'; Next = '1.2.0' }
5757
@{Current = '1.1.1'; Next = '2.0.0' }
5858
) {
59-
Test-SemanticVersionUpdate -Current $Current -Next $Next | Should -BeTrue
59+
Test-SemanticVersionUpdate -current $Current -Next $Next | Should -BeTrue
6060
}
6161
}
6262

@@ -1392,6 +1392,6 @@ Describe 'Returns false' {
13921392
@{ Current = '5.5.5'; Next = '10.10.10' }
13931393

13941394
) {
1395-
Test-SemanticVersionUpdate -Current $Current -Next $Next | Should -BeFalse
1395+
Test-SemanticVersionUpdate -current $Current -Next $Next | Should -BeFalse
13961396
}
13971397
}

0 commit comments

Comments
 (0)