Hello again,
today I refactored some code I have inherited.
I was a little proud as a managed to use the powershell piping to filter an array of patters through an array of values,
where the non matching pattern are selected.
As I love testing and here so pester, i wrote my pester tests,
which in th end leads to a surprise.
I already have found out that its kind of hard to learn about powershells implicit conversions from and to arrays.
That is also true in petes tests, so that this is passing.
Describe "Arrays" {
it "why passing" {
@(1,1,1) | should be @(1,2)
1,1,1 | should be 1,2
}
}
So how do i test my filtering function correctly with pester as it operates on arrays ?
Just wanna throw in a suggestion which you might be helpful:
For debug purposes i created a little function to serialise simple structured Objects (Array, hashtable).
This uses newlines to reveal the structure by indentation.
The name and functionallity are copied from ruby.
iE
inspect @(1,2) | Should Be @"
@(
1,
2)
"@
This could be refactored into a matcher, like
@(1,1,2) | should inspect "@(1,1,2)"
which would then be helpful to test such functionalitiy described above.
Frank