Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Examples/Gherkin/Gherkin-Scope.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Pester's Gherkin implementation test scope
As a PowerShell test author
I want variables to work across step implementations
So that writing tests will be simple

Scenario: Scope Should Be Easy Part 0
Given I initialize the variable One to "Uno"
When I set the variable One to "Hello World"
Then the variable One should be "Hello World"

Scenario: Scope Should Still Be Easy
Given I initialize the variable Script:Two to "Uno"
When I set the variable Script:Two to "Hello World"
Then the variable Script:Two should be "Hello World"


Scenario: Scope Should Be Easy Part 1
Given I initialize variables One and Script:Two to "Uno" and "Dos"
When I set the variable One to "Hello World"
Then the variable One should be "Hello World"
And the variable Script:Two should be "Dos"

Scenario: Scope Should Be Easy Part 2
Given I initialize variables One and Two to "Uno" and "Dos"
When I set the variable Two to "Goodbye"
Then the variable Two should be "Goodbye"
And the variable One should be "Uno"

Scenario: Scope Should Not Bleed
Then the variable Script:Two should be "Dos"
And the variable One should not exist
70 changes: 70 additions & 0 deletions Examples/Gherkin/VariableScope.Steps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
When 'I (?:set|initialize) the variable (?<Name>[\w:]+) to "(?<Value>[^"]+)"' {
param($Name, $Value)

switch($Name)
{
"One" { $One = $Value }
"Two" { $Two = $Value }
"Script:Two" { $Script:Two = $Value }
}
}

Given 'I initialize variables One and (?<Script>.+:)?Two to "Uno" and "Dos"' {
param($Script)
$One = "Uno"

if($Script) {
$Script:Two = "Dos"
} else {
$Two = "Dos"
}
}


Then 'the variable ([\w:]+) should be "([^"]+)"' {
param($Name, $Value)

$Result = switch($Name)
{
"One" { $One }
"Two" { $Two }
"Script:Two" { $Script:Two }
}
$Result | Should Be $Value
}

Then "the variable ([\w:]+) should not exist" {
param($Name)

switch($Name)
{
"One" {
Test-Path Variable:One | Should Be $False
}
"Two" {
Test-Path Variable:Two | Should Be $False
}
"Script:Two" {
Test-Path Variable:Script:Two | Should Be $False
}
}
}

BeforeEachFeature {
Remove-Variable One -ErrorAction SilentlyContinue
Remove-Variable Two -ErrorAction SilentlyContinue
Remove-Variable Two -Scope Script -ErrorAction SilentlyContinue
}

# Not using this BACKGROUND Given anymore, we're using a BeforeEachFeature instead
# That way we only clear the variable at the beginning of the test
Given "I ensure variables ([\w:]+) and ([\w:]+) are not set" {
param(
[Parameter(ValueFromRemainingArguments=$True)]
[string[]]$names
)

foreach($name in $Names) {
Remove-Variable -Name $Name -ErrorAction SilentlyContinue
}
}
10 changes: 5 additions & 5 deletions Examples/Validator/Validator.Steps.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$global:ValidatorRoot = Split-Path $MyInvocation.MyCommand.Path

BeforeAllFeatures {
BeforeEachFeature {
New-Module -Name ValidatorTest {
. $global:ValidatorRoot\Validator.ps1 -Verbose
} | Import-Module -Scope Global
} | Import-Module -Global
}

AfterAllFeatures {
AfterEachFeature {
Remove-Module ValidatorTest
}

Expand All @@ -26,11 +26,11 @@ Given 'MyValidator' {}

When 'MyValidator is called with (?<word>\w+)' {
param($word)
$script:result = MyValidator $word
$Validation = MyValidator $word
}

Then 'MyValidator should return (?<expected>\w+)' {
param($expected)
$expected = $expected -eq "true"
$result | Should Be $expected
$Validation | Should Be $expected
}
24 changes: 15 additions & 9 deletions Functions/Gherkin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ $job = Start-Job -ArgumentList $scriptRoot -ScriptBlock {
Import-Module $scriptRoot\Pester.psd1 -Force

New-Object psobject -Property @{
Results = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Quiet
Mockery = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Mockery -Quiet
Examples = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Examples -Quiet
Example1 = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Example1 -Quiet
Example2 = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Example2 -Quiet
NamedScenario = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -ScenarioName "When something uses MyValidator" -Quiet
NotMockery = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -ExcludeTag Mockery -Quiet
Results = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Show None
Mockery = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Mockery -Show None
Examples = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Examples -Show None
Example1 = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Example1 -Show None
Example2 = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -Tag Example2 -Show None
NamedScenario = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -ScenarioName "When something uses MyValidator" -Show None
NotMockery = invoke-gherkin (Join-Path $scriptRoot Examples\Validator\Validator.feature) -PassThru -ExcludeTag Mockery -Show None
}
}

Expand Down Expand Up @@ -45,12 +45,18 @@ Describe 'Invoke-Gherkin' {
}

It 'Supports excluding scenarios by tag' {
$gherkin.NotMockery.PassedCount | Should Be $gherkin.NotMockery.TotalCount
$gherkin.NotMockery.PassedCount | Should Be 10
$gherkin.NotMockery.TotalCount | Should BeLessThan $gherkin.Results.TotalCount
($gherkin.NotMockery.TotalCount + $gherkin.Mockery.TotalCount) | Should Be $gherkin.Results.TotalCount
}

It 'Supports running specific scenarios by name' {
$gherkin.NamedScenario.PassedCount | Should Be $gherkin.Mockery.TotalCount
$gherkin.NamedScenario.PassedCount | Should Be 3
}

It 'Outputs the correct number of passed scenarios' {
# Note that each example outputs as a scenario ...
@($gherkin.Results.PassedScenarios).Count | Should Be 3
@($gherkin.NamedScenario.PassedScenarios).Count | Should Be 1
}
}
Loading