Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created December 15, 2018 22:59
Show Gist options
  • Save nohwnd/1894a8dd9d599f5ed6324112d391bbfd to your computer and use it in GitHub Desktop.
Save nohwnd/1894a8dd9d599f5ed6324112d391bbfd to your computer and use it in GitHub Desktop.
Visible scopes in Pester
Get-Module Pester, A, B | Remove-Module
Import-Module C:\Projects\Pester_main\Pester.psd1
New-Module A { } | Import-Module
New-Module B {
function Greet ($Name) { Hello -Name $Name }
function Hello ($Name) { "Hello, $Name" }
Export-ModuleMember -Function WrapWrapWrap, Greet
} | Import-Module
Describe "I" {
Context "see" {
It "scopes" {
Mock Hello -ModuleName B
InModuleScope -ModuleName A {
Greet -Name "Jakub"
}
$jakub = "Jakub"
Assert-MockCalled Hello `
-ModuleName B `
-ParameterFilter { $Name -eq $jakub }
}
}
}
Describing I
Invoking scriptblock from location 'Describe Fixture' in state 'Caller - Captured in InModuleScope (40034187))', 0 scopes deep:
{
Context "see" {
It "scopes" {
Mock Hello -ModuleName B
InModuleScope -ModuleName A {
Greet -Name "Jakub"
}
$jakub = "Jakub"
Assert-MockCalled Hello `
-ModuleName B `
-ParameterFilter { $Name -eq $jakub }
}
}
}
Context see
Invoking scriptblock from location 'Describe Fixture' in state 'Caller - Captured in InModuleScope (40034187))', 1 scopes deep:
{
It "scopes" {
Mock Hello -ModuleName B
InModuleScope -ModuleName A {
Greet -Name "Jakub"
}
$jakub = "Jakub"
Assert-MockCalled Hello `
-ModuleName B `
-ParameterFilter { $Name -eq $jakub }
}
}
Invoking scriptblock from location 'It' in state 'Caller - Captured in InModuleScope (40034187))', 2 scopes deep:
{
Mock Hello -ModuleName B
InModuleScope -ModuleName A {
Greet -Name "Jakub"
}
$jakub = "Jakub"
Assert-MockCalled Hello `
-ModuleName B `
-ParameterFilter { $Name -eq $jakub }
}
Getting scope from ScriptBlock 'Pester (2094961))'
Unbinding ScriptBlock from 'Pester (2094961))'
Setting ScriptBlock state from source state 'Unbound ScriptBlock from Mock (Unbound)' to 'Module - B (57377476))'
Getting scope from ScriptBlock 'Caller - Captured in InModuleScope (40034187))'
Setting ScriptBlock state from source state 'Caller - Captured in InModuleScope (40034187))' to 'Module - A (29730157))'
Invoking scriptblock from location 'InModuleScope' in state 'Module - A (29730157))', 0 scopes deep:
{
Greet -Name "Jakub"
}
Unbinding ScriptBlock from 'Pester (2094961))'
Setting ScriptBlock state from source state 'Unbound ScriptBlock from Test-ParameterFilter (Unbound)' to 'Module - A (29730157))'
Invoking scriptblock from location 'Mock - Parameter filter' in state 'Module - A (29730157))', 1 scopes deep:
{
param (${Name})
Set-StrictMode -Off
$True
}
Setting ScriptBlock state from source state 'Pester (2094961))' to 'Module - B (57377476))'
Invoking scriptblock from location 'Mock - of command Hellofrom module B' in state 'Module - B (57377476))', 2 scopes deep:
{
}
Invoking scriptblock from location 'Mock - of command Hello' in state 'Module - B (57377476))', 3 scopes deep:
{
}
Setting ScriptBlock state from source state 'Module - A (29730157))' to 'Caller - Captured in InModuleScope (40034187))'
Unbinding ScriptBlock from 'Caller - Captured in InModuleScope (40034187))'
Setting ScriptBlock state from source state 'Unbound ScriptBlock from Test-ParameterFilter (Unbound)' to 'Caller - Captured in InModuleScope (40034187))'
Invoking scriptblock from location 'Mock - Parameter filter' in state 'Caller - Captured in InModuleScope (40034187))', 3 scopes deep:
{
param (${Name})
Set-StrictMode -Off
$Name -eq $jakub
}
[+] scopes 155ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment