I'm trying to write some tests using PowerShell, Pester and Gherkin but I'm struggling to work out how I can test against multiple values.
For example, I could use Get-Service to check the status of a Windows service. If I want to check if it is running, I could say:
When I check my service
Then the status is "Running"
OK, nice and simple. What I really want to be able to do is say:
When I check my service
Then the status is "Stopped" or "Disabled"
I could do this by passing multiple parameters to the step file, i.e.
'the status is "(.*)" or "(.*)"'
but I want it to be neater than that and more re-usable - this is just a simple example but for real scenarios I'd have to build a step for one parameter, two, three, etc.
It'd be much nicer to be able to pass them across from the feature file and have a simple step definition. This may not be the 'best' way to do BDD but bear with me.
In my head, what I want to do is pass an array from the feature file with a list of the acceptable values, something like:
When I check my service
Then the status is ""Stopped","Disabled""
and then my step has something like:
'the status is <myarray>'
$actualvalue | Should -BeIn <myarray>
I know this isn't valid code but you get the idea. I tried implementing this idea but couldn't get it to work, I can't pass an array even if I define the parameter as one in the step file.
I also tried looking at Data Tables but I had no luck there either.
Another attempt using Examples also failed - I can make it run each test in turn but not one OR the other.
Does anyone have any suggestions for how this could be best achieved? As I said, ignore the specific example, it's the logic I'm interested in - how to test for one thing OR another thing OR another and if any are true then it's a pass.