removed extra material that was more suited for end-to-end test scenarios, allowing for easier exposure of the real bug- which is likely with Get-Variable
This commit is contained in:
parent
2569e481fb
commit
45047efd97
3 changed files with 16 additions and 117 deletions
|
@ -86,7 +86,6 @@
|
|||
|
||||
Context "Scope Tests" {
|
||||
# This will violate the DRY principle. Tread softly.
|
||||
|
||||
It "Should be able to get a global scope variable using the global switch" {
|
||||
New-Variable globalVar -Value 1 -Scope global -Force
|
||||
|
||||
|
@ -100,10 +99,11 @@ Context "Scope Tests" {
|
|||
}
|
||||
|
||||
It "Should be able to get a global variable using the script scope switch" {
|
||||
{
|
||||
New-Variable globalVar -Value 1 -Scope global -Force
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
{ New-Variable globalVar -Value 1 -Scope global -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script | Out-Host
|
||||
|
||||
$(Get-Variable -Name globalVar -Scope script).Value }| Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get an item locally using the local switch" {
|
||||
|
|
|
@ -168,66 +168,16 @@
|
|||
}
|
||||
|
||||
Context "Scope Tests" {
|
||||
# This will violate the DRY principle. Tread softly.
|
||||
# We use the -Force switch here because we are testing global variable creation
|
||||
|
||||
It "Should be able to get a global scope variable using the global switch" {
|
||||
New-Variable globalVar -Value 1 -Scope global -Force
|
||||
|
||||
(Get-Variable -Name globalVar -Scope global)[0].Value | Should Be 1
|
||||
It "Should be able to create a global scope variable using the global switch" {
|
||||
{ New-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not be able to set a global scope variable using the local switch" {
|
||||
Set-Variable globalVar -Value 1 -Scope global -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue | Should Throw
|
||||
It "Should be able to create a local scope variable using the local switch" {
|
||||
{ New-Variable localVar -Value 1 -Scope local -Force } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to set a global variable using the script scope switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope global -Force
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get an item locally using the local switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope local -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope local
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get an item locally using the global switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope local -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope global
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not be able to get a local variable using the script scope switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope local -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get a script variable created using the script switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope script -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to set a global script variable that was created using the script scope switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope script -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
It "Should be able to create a script scope variable using the script switch" {
|
||||
{ New-Variable scriptVar -Value 1 -Scope script -Force } | Should Not Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
Describe "Set-Variable" {
|
||||
It "Should create a new variable with no parameters" {
|
||||
{ Set-Variable testVar } | Should Not Throw
|
||||
|
||||
{ Get-Variable testVar } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should assign a value to a variable it has to create" {
|
||||
|
@ -67,65 +65,16 @@
|
|||
}
|
||||
|
||||
Context "Scope Tests" {
|
||||
# This will violate the DRY principle. Tread softly.
|
||||
|
||||
It "Should be able to get a global scope variable using the global switch" {
|
||||
Set-Variable globalVar -Value 1 -Scope global -Force
|
||||
|
||||
(Get-Variable -Name globalVar -Scope global)[0].Value | Should Be 1
|
||||
}
|
||||
|
||||
It "Should not be able to set a global scope variable using the local switch" {
|
||||
Set-Variable globalVar -Value 1 -Scope global -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope local -ErrorAction SilentlyContinue | Should Throw
|
||||
It "Should be able to set a global scope variable using the global switch" {
|
||||
{ Set-Variable globalVar -Value 1 -Scope global -Force } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to set a global variable using the script scope switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope global -Force
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
{ Set-Variable globalVar -Value 1 -Scope script -Force } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get an item locally using the local switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope local -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope local
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get an item locally using the global switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope local -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope global
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not be able to get a local variable using the script scope switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope local -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to get a script variable created using the script switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope script -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to set a global script variable that was created using the script scope switch" {
|
||||
{
|
||||
Set-Variable globalVar -Value 1 -Scope script -Force
|
||||
|
||||
Get-Variable -Name globalVar -Scope script
|
||||
} | Should Not Throw
|
||||
It "Should be able to set an item locally using the local switch" {
|
||||
{ Set-Variable globalVar -Value 1 -Scope local -Force } | Should Not Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue