Code Monkey home page Code Monkey logo

Comments (4)

StefanScherer avatar StefanScherer commented on May 24, 2024

Hm, strange. This happens in AppVeyor, Contains and Not Contains doesn't seem to work.

I run now a Windows container and only install poshspec and in this container it works.

PS C:\projects> .\test.ps1
Describing Files
 [+] File 'test.txt' Should Exist 478ms
 [-] File 'test.txt' Should Not Exist 217ms
   Expected: C:\projects\test.txt to not exist, but it was found
   1: 'C:\projects\test.txt' | Should Not Exist
   at <ScriptBlock>, <No file>: line 1
   at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Poshspec\2.2.1\Private\Invoke-PoshspecExpression.ps1: line 13
 [+] File 'test.txt' Should Contain 'hello' 176ms
 [-] File 'test.txt' Should Contain 'other' 75ms
   Expected: file C:\projects\test.txt to contain {other}
   1: 'C:\projects\test.txt' | Should Contain 'other'
   at <ScriptBlock>, <No file>: line 1
   at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Poshspec\2.2.1\Private\Invoke-PoshspecExpression.ps1: line 13
PS C:\projects> get-module

ModuleType Version    Name                                ExportedCommands                                                             
---------- -------    ----                                ----------------                                                             
Binary     1.0.0.0    CimCmdlets                          {Export-BinaryMiLog, Get-CimAssociatedInstance, Get-CimClass, Get-CimInsta...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}           
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-Authentico...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}                    
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSS...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}    
Script     3.4.0      Pester                              {AfterAll, AfterEach, Assert-MockCalled, Assert-VerifiableMocks...}          
Script     2.2.1      Poshspec                            {AppPool, AuditPolicy, CimObject, DnsHost...}                                
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}        
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PSReadlineKeyHandl...

Any tips what might be the problem in AppVeyor environment?
The other Pester version, AppVeyor seems to have 4.3.1 installed.

from poshspec.

StefanScherer avatar StefanScherer commented on May 24, 2024

It seems to behave different between running it like .\test.ps1 and powershell -File .\test.ps1. The Contains rules behave different in AppVeyor.
Any advisory how to run it predictable in AppVeyor builds?

from poshspec.

cdhunt avatar cdhunt commented on May 24, 2024

PoshSpec is just a Pester abstraction. The Contains assertion was removed in Pester (I don't remember which version). If you use Invoke-Pester against your test file you get all of Pester's functionality: -Exit, -PassTrue, -OutputXml, etc.

Does that help?

from poshspec.

StefanScherer avatar StefanScherer commented on May 24, 2024

Thanks @cdhunt
After some hours "learning the hard way" I solved my problems.
Integrating Pester based things looks hard if you come from Serverspec and used to Linux commands exiting properly. :-)

I have it running using $lastExitCode in our appveyor caller script and Invoke-Pester in the test script that sets up the environment and runs the test.
I first thought I can use $ErrorActionPreference = 'Stop' in one or both of the scripts, but that didn't work. So that was my learning curve to dig deeper into the world of PowerShell and Pester.

from poshspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.