@@ -5,31 +5,51 @@ BeforeAll {
55}
66
77Describe ' Mock an environment variable' {
8- BeforeAll {
9- $script :environmentVariable = " test$ ( New-Guid ) "
10- $script :InitialValue = ' Some value here and there'
8+ Describe ' Code is called' {
9+ BeforeAll {
10+ $script :EnvironmentVariableName = " test$ ( New-Guid ) "
11+ $script :EnvironmentVariable = " env:${environmentVariableName} "
12+ $script :InitialValue = ' Some value here and there'
13+ }
14+
15+ It ' Code is called' {
16+ $script :InitialValue = ' Some value here and there'
17+ $script :called = $false
18+ Mock- EnvironmentVariable - Variable $environmentVariableName - Value $InitialValue {
19+ $script :called = $true
20+ }
21+ $script :called | Should - BeTrue
22+ }
1123
24+ AfterAll {
25+ Remove-Item `
26+ - Path $EnvironmentVariable `
27+ - Recurse `
28+ - Force `
29+ - ErrorAction Ignore
30+ }
1231 }
13- It ' Code is called' {
14- $script :environmentVariable = " test$ ( New-Guid ) "
15- $script :InitialValue = ' Some value here and there'
16- $script :called = $false
17- Mock- EnvironmentVariable - Variable $environmentVariable - Value $InitialValue {
18- $script :called = $true
19- }
20- $script :called | Should - BeTrue
21- }
32+ Describe ' Environment variable is set up' {
33+ BeforeAll {
34+ $script :environmentVariable = " test$ ( New-Guid ) "
35+ $script :InitialValue = ' Some value here and there'
36+ }
37+
38+ It ' Environment variable is set up' {
39+ $environmentVariable = " test$ ( New-Guid ) "
40+ $InitialValue = ' Some value here and there'
41+ Test-Path - Path $environmentVariable | Should - BeFalse
42+ Mock- EnvironmentVariable - Variable $environmentVariable - Value $InitialValue {
43+ (Get-ChildItem - Path " env:${environmentVariable} " ).Value | Should - Be $InitialValue
44+ }
45+ Test-Path - Path $environmentVariable | Should - BeFalse
46+ }
2247
23- It ' Environment variable is set up' {
24- $environmentVariable = " test$ ( New-Guid ) "
25- $InitialValue = ' Some value here and there'
26- Test-Path - Path $environmentVariable | Should - BeFalse
27- Mock- EnvironmentVariable - Variable $environmentVariable - Value $InitialValue {
28- (Get-ChildItem - Path " env:${environmentVariable} " ).Value | Should - Be $InitialValue
29- }
30- Test-Path - Path $environmentVariable | Should - BeFalse
31- }
48+ AfterAll {
3249
50+ }
51+ }
52+
3353 Describe ' Environment variable is set' {
3454 BeforeAll {
3555 $script :environmentVariableName = " test$ ( New-Guid ) "
@@ -167,4 +187,27 @@ Describe 'Mock an environment variable' {
167187 - ErrorAction Ignore
168188 }
169189 }
190+
191+ Describe ' Set up environment variable is cleared up' {
192+ BeforeAll {
193+ $environmentVariableName = " test$ ( New-Guid ) "
194+ $script :environmentVariable = " env:${environmentVariableName} "
195+ }
196+
197+ It ' Set up environment variable is cleared up' {
198+ Mock- EnvironmentVariable `
199+ - Variable $environmentVariableName {
200+ New-Item - Path $environmentVariable - Value ' Some value'
201+ }
202+ Test-Path - Path $environmentVariable | Should - BeFalse
203+ }
204+
205+ AfterAll {
206+ Remove-Item `
207+ - Path $environmentVariable `
208+ - Recurse `
209+ - Force `
210+ - ErrorAction Ignore
211+ }
212+ }
170213}
0 commit comments