Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 611
Dave Nicolette Avatar asked Jul 24 '18 23:07

Dave Nicolette


1 Answers

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:

  • https://github.com/pester/Pester/wiki/Migrating-from-Pester-3-to-Pester-4
like image 100
Mark Wragg Avatar answered Sep 21 '22 12:09

Mark Wragg