-
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from dlwyatt/GlobalFunctionMock
Initial fix for #286
- Loading branch information
Showing
3 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This script exists to create and mock a global function, then exit. The actual behavior | ||
# that we need to test is covered in GlobalMock-B.Tests.ps1, where we make sure that the | ||
# global function was properly restored in its scope. | ||
|
||
$functionName = '01c1a57716fe4005ac1a7bf216f38ad0' | ||
|
||
if (Test-Path Function:\$functionName) | ||
{ | ||
Remove-Item Function:\$functionName -Force -ErrorAction Stop | ||
} | ||
|
||
function global:01c1a57716fe4005ac1a7bf216f38ad0 | ||
{ | ||
return 'Original Function' | ||
} | ||
|
||
function script:Testing | ||
{ | ||
return 'Script scope' | ||
} | ||
|
||
Describe 'Mocking Global Functions - Part One' { | ||
Mock $functionName { | ||
return 'Mocked' | ||
} | ||
|
||
It 'Mocks the global function' { | ||
& $functionName | Should Be 'Mocked' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This test depends on some state set up in GlobalMock-A.Tests.ps1. The behavior we're verifying | ||
# is that global functions that have been mocked are still properly set up even after the test | ||
# script exits its scope. | ||
|
||
$functionName = '01c1a57716fe4005ac1a7bf216f38ad0' | ||
|
||
try | ||
{ | ||
Describe 'Mocking Global Functions - Part Two' { | ||
It 'Restored the global function properly' { | ||
$globalFunctionExists = Test-Path Function:\global:$functionName | ||
$globalFunctionExists | Should Be $true | ||
& $functionName | Should Be 'Original Function' | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
if (Test-Path Function:\$functionName) | ||
{ | ||
Remove-Item Function:\$functionName -Force | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters