Last active
October 14, 2024 15:13
-
-
Save markwragg/7afe4615aef97a9fed80441ffcb0e646 to your computer and use it in GitHub Desktop.
Redirect Out-File to write to TestDrive: during Pester execution
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
BeforeAll { | |
$OutFile = Get-Command -Name 'Out-File' | |
Mock Out-File -ParameterFilter { $FilePath -match 'file.txt' } -MockWith { | |
$InputObject = $PesterBoundParameters['InputObject'] | |
& $OutFile -InputObject $InputObject -FilePath (Join-Path $TestDrive 'file.txt') | |
} | |
} | |
It 'Should update the file with the expected values' { | |
$FilePath = (Join-Path $TestDrive 'file.txt') | |
$FilePath | Should -FileContentMatch 'expectedstring1' | |
$FilePath | Should -FileContentMatch 'expectedstring2' | |
$FilePath | Should -FileContentMatch 'expectedstring3' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment