Closed paraknell closed 6 years ago
Hi @mwtilton,
It looks like the Should Contain
assertion was renamed to Should FileContentMatch
in Pester 4. The Should Contain
assertion is now basically a wrapper around the built-in PowerShell -contains
operator.
Your original test as it was written:
"c:\file.txt" | should contain "some words"
can be changed to this instead to check the contents of a file:
"c:\file.txt" | Should -FileContentMatch "some words"
There's some additional documentation for upgrading from Pester 3 to Pester 4 here:
https://github.com/pester/Pester/wiki/Migrating-from-Pester-3-to-Pester-4
Hope this helps.
M
This seems to have resolved my issue thank you so much! Thanks for the link as well as that seemed to help migrate some old version files as well.
1. General summary
Pester tests fail when you try to see if a file contains a string. i.e
2. My Environment
Win 10 (1803) Pester: 4.3.1 Powershell: 5.1.17134.165 Running in: vsCode and from the CLI
Should return:
3. Expected Behavior
I'm not sure if this is a bug, an issue with my code or an improvement request. This may have also been a removed feature as I know it was working on version 3.4 of pester, or at least the tests were considered passing then. (Might have been a false positive?)
This would be used to test if a file contained a certain custom function, help options hidden in the comments section, special parameters or other internal details to the code. Please let me know if there is another way of doing this.
Also unsure if this is related to:
121
959
960
4.Current Behavior
This is an example I am trying to run:
And it fails but I know the file does contain the EXACT formatting and text of the string provided in the variable $module. I have also split these into separate It blocks to verify that it is in fact an issue with the contain statement and not with the existence of the file. This has also been tested with Match and BeLike with mixed results.
I am testing against the string below:
In these examples:
Output to console:
Be like seems to be the best solution at this point but I need to test it against the whole string and I'm not sure this is the best way of doing things.
5. Possible Solution
Nothing currently.
6. Context
I am trying to ensure that all my files I am using to hold API data actually contain that data. I need to have it know that an xml based string of code exists within that file. This is mainly used on an API for rebooting NAS/Server devices and I need to ensure that the xml code being used is in fact found before running through the rest of the script.