Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$TestDrive does not work in v5.0.2 #1620

Closed
LambdaEcho opened this issue Jun 29, 2020 · 4 comments
Closed

$TestDrive does not work in v5.0.2 #1620

LambdaEcho opened this issue Jun 29, 2020 · 4 comments
Milestone

Comments

@LambdaEcho
Copy link

1. General summary of the issue

The examples on https://pester.dev/docs/usage/testdrive how to use $TestDrive does not work in v5.0.2, anymore! But, in v4.7.3 everything works as described.

2. Describe Your Environment

PowerShell version: 5.1.19640.1
OS version: Microsoft Windows NT 10.0.19640.1

3. Expected Behavior

The $TestDrive feature should work again.

4.Current Behavior

Repro:

  1. TestDrive.Test.ps1 contains example from https://pester.dev/docs/usage/testdrive
  2. Invoke-Pester .\TestDrive.Test.ps1
Starting discovery in 1 files.
Set-Content : Cannot find drive. A drive with the name 'TestDrive' does not exist.
At C:\_devtest\TestDrive.Test.ps1:7 char:5
+     Set-Content $testPath -value "my test text."
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (TestDrive:String) [Set-Content], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetContentCommand

Add-Content : Cannot find drive. A drive with the name 'TestDrive' does not exist.
At C:\_devtest\TestDrive.Test.ps1:2 char:5
+     Add-Content $path -Value $footer
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (TestDrive:String) [Add-Content], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.AddContentCommand

Get-Content : Cannot find drive. A drive with the name 'TestDrive' does not exist.
At C:\_devtest\TestDrive.Test.ps1:9 char:15
+     $result = Get-Content $testPath
+               ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (TestDrive:String) [Get-Content], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Discovery finished in 1.09s.
[-] Add-Footer.adds a footer 1.33s (1.14s|197ms)
 Expected strings to be the same, but they were different.
 Expected length: 20
 Actual length:   0
 Strings differ at index 0.
 Expected: 'my test text.-Footer'
 But was:  ''
 at (-join $result) | Should -Be "my test text.-Footer", C:\_devtest\TestDrive.Test.ps1:12
 at <ScriptBlock>, C:\_devtest\TestDrive.Test.ps1:12
Tests completed in 4.85s
Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0

5. Possible Solution

Downgrade Pester to v4.7.3.

@DenisNedl
Copy link

DenisNedl commented Jun 29, 2020

This guide is for version 4.x only and outdated with version 5.0. There were some braking changes implemented with 5.0. Please see https://github.com/pester/Pester#discovery--run in particular.
TL;DR: Don't put any code in the "Describe" block. Put it into the "It" block.

Edit: If you need some code for all tests, put it into "BeforeAll" or "BeforeEach".

@LambdaEcho
Copy link
Author

This guide is for version 4.x only and outdated with version 5.0. There were some braking changes implemented with 5.0. Please see https://github.com/pester/Pester#discovery--run in particular.
TL;DR: Don't put any code in the "Describe" block. Put it into the "It" block.

Edit: If you need some code for all tests, put it into "BeforeAll" or "BeforeEach".

Thank you very much! That solved my issue!

@DarkLite1
Copy link
Contributor

Strugling a bit with this too. In the old Pester I had a structure like this:

Describe 'send an error mail to tha admin when' {
    In $testDrive {
    Context 'when things go wrong {
     it 'gets tested' {

How is something like this translated to the new Pester? I can't seem to get it right and there's no example on the page.

@DenisNedl
Copy link

image

As you can see "In" executes a script from a given path. That means you got code outside your "It" block -> bad.
I'm not sure what you want to accomplish, but maybe try this:

Describe 'send an error mail to tha admin when' {
    Context 'when things go wrong {
        It 'gets tested' {
            In $testDrive {
                <your code>
                ...

@nohwnd nohwnd reopened this Sep 8, 2020
@nohwnd nohwnd added this to the 5.0.x milestone Sep 8, 2020
@nohwnd nohwnd modified the milestones: 5.0.x, 5.1 Sep 20, 2020
@nohwnd nohwnd closed this as completed Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants