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.

Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
Dave Nicolette
  • 171
  • 1
  • 9
  • IIRC, this is a difference in versions. – user2864740 Jul 24 '18 at 23:59
  • @user2864740 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. – kkuilla Oct 22 '19 at 11:46
  • @kkuilla -- `Get-Command *Pester*` will give you info about any commands with "Pester" in the name, and includes the Version number. – Leon Bambrick May 08 '23 at 01:56

2 Answers2

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:

Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
3

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

Dave Nicolette
  • 171
  • 1
  • 9