Pester sample script gets "-Be is not a valid Should operator" on Windows 10, works fine on Ubuntu
Asked Answered
E

2

11

New to Pester, installed Powershell and Pester on Ubuntu 16.04 per instructions on the Pester Github page https://github.com/pester/Pester. Executed their sample scripts Get-Planet.Tests.ps1 and Get-Planet.ps1 and it worked as advertised. Tried the same thing on Windows 10 following their instructions, and got "-Be is not a valid Should operator".

Not sure where to look for the problem, as I'm new to Pester and to Powershell as well. It's their own sample, installed per their instructions, with no modifications. Any help will be appreciated.

Eakin answered 24/7, 2018 at 23:36 Comment(3)
IIRC, this is a difference in versions.Worriment
@Worriment How do I check which version of Pester I am running? I tried Invoke-pester --version but that didn't work. Couldn't find anything in the docs either.Dorladorlisa
@Dorladorlisa -- Get-Command *Pester* will give you info about any commands with "Pester" in the name, and includes the Version number.Frijol
A
20

To expand on the other answer, Windows 10 (and Server 2016) come with Pester version 3.4.0 pre-installed. From version 4 of Pester onward some Pester syntax was changed, including the Should assertions which are now provided as parameters (e.g Should Be became Should -Be).

The documentation reflects the newer syntax, hence why it is misleading for older versions of Pester.

You can install the latest version of Pester on your Windows 10 machine, by running the following with an admin-level PowerShell window:

Install-Module -Name Pester -Force -SkipPublisherCheck

To see what else changed between Pester versions 3 and 4, see here:

Anglesey answered 25/7, 2018 at 15:5 Comment(0)
E
3

The problem turned out to be the wrong version of Pester on the Windows 10 system, as suggested by user2864740.

Eakin answered 25/7, 2018 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.