pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.11k stars 473 forks source link

RuntimeException: 'Contain' is not a valid Should operator #877

Closed splatteredbits closed 6 years ago

splatteredbits commented 7 years ago

Just upgraded to Pester 4.0.7 (from 4.0.6) and it looks like the Contain operator is gone:

    It 'Should Overwrite Existing File' {
        Set-Content -Path $tempFile -Value 'Hello world!'
        $tempFile | Should Contain "Hello world!"
        Save-WebUrl -Url 'http://www.google.com' -FilePath $tempFile
        $tempFile | Should Not Contain 'Hello world!'
    }

results in this failure:

    [-] Should Overwrite Existing File 25ms
      RuntimeException: 'Contain' is not a valid Should operator.
      at Should<Begin>, F:\Build\Arc\Modules\Pester\Functions\Assertions\Should.ps1: line 109
      at <ScriptBlock>, F:\Build\Arc\WhsAutomation\Test\Save-WebUrl.Tests.ps1: line 45
alx9r commented 7 years ago

@Splatteredbits You are right. That change is noted in the release notes under "Breaking Changes".

alx9r commented 7 years ago

The Pester 3 to 4 migration guide recommends the following:

replace all occurrences of any Contain assertion with FileContentMatch.

I haven't had to do that myself, but there's even a script in that guide to help automate that process.

splatteredbits commented 7 years ago

My problem isn't that this changed, but that it changed between 4.0.6 and 4.0.7.

alx9r commented 7 years ago

As I understand it, 4.0.6 was marked with "-rc" which means it is pre-release per semver clause 9. That clause includes the following text:

...A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. ...

nohwnd commented 7 years ago

@splatteredbits It is our fault, partially. We cannot push pre-releases to PSGalllery, because it does not support it. We always talked about 4.0.0-rc - 4.0.6-rc as being release candidate, even though for PSGallery it was a released version. I also took time to share that 4.0.7 will have breaking changes on every major powershell channel to give people time to prepare their servers before the version with breaking changes hits them (or before version 4 hits them). I then waited at least two days, and posted reminders, and provided migration guide. That is as much as I could do.

Correctly the first released version would be 4.0.0 and the previous ones would be 4.0.0-rc1-6, but psgallery does not support that :/

To help us out, please write an angry email to PSGallery people :) Or we can start publishing Ester - experimental Pester. Dibz on that name btw.

it-praktyk commented 7 years ago

Now, when was explained why/when/what changed I assume that we can mark the issue as a "Waiting for closure". It will be closed after 7 days.

alx9r commented 7 years ago

@Nohwnd @splatteredbits It looks like there is a draft RFC for the PowerShell gallery limitation.. It looks like the place for feedback is the associated issue.

alx9r commented 7 years ago

@it-praktyk I think this sort of issue should probably be marked with "Resolution-External" similar to the way that tag gets used on other projects like PowerShell/PowerShell.

splatteredbits commented 7 years ago

Hmm. I would prefer, then, that you not publish prerelease versions to the Gallery until it supports prerelease versions. I use the gallery too, and don't like how it doesn't support them. Use nuget.org or publish to GitHub. Maybe someone needs to write a GitHub provider.

it-praktyk commented 7 years ago

I understand your concerns. In the next few days (?), we start a discussion about maintenance model of Pester. Your issue will also be dealt with.

alx9r commented 7 years ago

It looks like PowerShell Gallery may soon have pre-release semantics. I have opened #889 to pursue that solution. Assuming pre-release semantics comes to fruition we should be able to avoid this problem in the future.

@splatteredbits Thanks for opening this issue. I think it has precipitated some real progress.

it-praktyk commented 6 years ago

Now, when pre-release versions are supported by PowerShell Gallery and Pester is published in this mode too, I assume that we can close the issue.