Issue while learning TestDrive functionality

40 views
Skip to first unread message

Citizen Earth

unread,
Oct 8, 2022, 4:00:15 PM10/8/22
to Pester
I am using below code , and seeing error , please advice and correct me. Thanks in advance.

Import-Module -Name pester -force
describe 'Set-File changes the file provided' {
    BeforeAll{

    function Set-File {
    param(
    [string]$FilePath
    )
    $fileContents = Get-Content -Path $FilePath -Raw
    $replacement = $fileContents -replace 'foo','bar'
    Set-Content -Path $FilePath -Value $replacement -NoNewLine
        }
    }
    BeforeEach{
            $testFilePath = TestDrive:\testFile.txt
            Add-Content -Path $testFilePath -Value 'foo bar foo bar' -NoNewLine
            Set-File -FilePath $testFilePath
        }


    it 'replaces foo with bar' {
       
        (Get-Content -Path $testFilePath -Raw) | Should -Be 'bar bar bar bar'
    }
}

************************************************************************************
Error:


Starting discovery in 1 files.

Starting discovery in 1 files.

Starting discovery in 1 files.

Starting discovery in 1 files.

Starting discovery in 1 files.

Starting discovery in 1 files.
[-] Discovery in C:\temp\Pester\TestD.Tests.ps1 failed with:
System.Management.Automation.RuntimeException: The script failed due to call depth overflow. ---> System.Management.Automation.ScriptCallDepthException: The script failed due to call depth overflow.
   at System.Management.Automation.ExecutionContext.CheckStackDepth()
   at System.Management.Automation.CommandProcessorBase.DoExecute()

Reply all
Reply to author
Forward
0 new messages