Skip to content
Closed
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
23 changes: 22 additions & 1 deletion Examples/Gherkin/Gherkin-ScenarioData.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Pester displays scenario data in the console
| 1 | 1 | 2 |
| 2 | 2 | 4 |
And a single column data table:
| PropNames |
| PropertyNames |
| ModuleVersion |
| GUID |
| Author |
Expand All @@ -36,3 +36,24 @@ Feature: Pester displays scenario data in the console
| PrivateData.PSData.Tags |
When this scenario is run
Then the tables are displayed correctly in the console

Scenario: Can classify steps as undefined
Given this step definition does not have an implementation
When this scenario is run
Then all of these steps are classified as undefined

Scenario Outline: Pester can display scenario example tables to the console

Given a number '<x>' and a numbxer '<y>'
When I add them together
Then I should get '<result>'

Examples: Elementary, my dear Watson
| x | y | result |
| 1 | 1 | 2 |
| 2 | 2 | 4 |

Scenario: Now for something a little bit different
| x | y | result |
| 1 | 2 | 3 |
| 2 | 3 | 5 |
4 changes: 2 additions & 2 deletions Examples/Gherkin/JustForReporting1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Feature: A test feature for reporting 1

Given step_<given>
And and_<given>
When step_<when>
When step_<when>
And and_<when>
Then step_<then>
Then step_<then>
And and_<then>

Examples: Examples 1
Expand Down
10 changes: 8 additions & 2 deletions Examples/Gherkin/ScenarioData.Steps.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
Given "the following DocString:?" {
param([string]$DocString)

#throw
Set-StepPending
$DocString | Should -Not -BeNull
}

When "this scenario is run" { }
When "this scenario is run" { #Set-StepPending
}

Then "the DocString is displayed in the console" { }

GherkinStep "a (square|rectangular|single column) data table:?" { param($table) }
Then "the tables are displayed correctly in the console" { }

Given "a number '(\d+)' and a number '(\d+)" { param([int]$x, [int]$y) }
When "I add them together" { }
Then "I should get '(\d+)" { param([int]$result) }
70 changes: 70 additions & 0 deletions Functions/Assertions/Set-StepPending.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function New-UndefinedStepErrorRecord ([string] $File, [string] $Line, [string] $LineText) {
$exception = New-Object Exception "No matching step definition found."
$errorID = 'PesterUndefinedGherkinStep'
$errorCategory = [Management.Automation.ErrorCategory]::InvalidResult
# we use ErrorRecord.TargetObject to pass structured information about the error to a reporting system.
$targetObject = @{Message = $Message; File = $File; Line = $Line; LineText = $LineText}
$errorRecord = New-Object Management.Automation.ErrorRecord $exception, $errorID, $errorCategory, $targetObject
return $errorRecord
}

function New-PendingStepErrorRecord ([string] $File, [string] $Line, [string] $LineText) {
$exception = New-Object Exception "# TODO: (Pester::Pending)"
$errorID = 'PesterPendingGherkinStep'
$errorCategory = [Management.Automation.ErrorCategory]::InvalidResult
# we use ErrorRecord.TargetObject to pass structured information about the error to a reporting system.
$targetObject = @{Message = $Message; File = $File; Line = $Line; LineText = $LineText}
$errorRecord = New-Object Management.Automation.ErrorRecord $exception, $errorID, $errorCategory, $targetObject
return $errorRecord
}

function Set-StepPending {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing this function and adding a -Pending parameter to GherkinStep in Gherkin.ps1. See #1.

<#

.SYNOPSIS
Set-StepPending used inside Step Definition blocks will cause those steps to be
considered as pending.

.DESCRIPTION
If Set-StepPending is used inside a step definition block, the test will be
considered as Pending. It's not a passed result, nor a failed result,
but something in between. It indicates that the results of the test could not
be verified. A step definition with a Pending result will be considered as
Inconclusive when output to the NUnitXml report, unless overridden by
specifying pending and inconclusive tests as failed.

.EXAMPLE

Invoke-Gherkin

Given "this step is not yet implemented" {

Set-StepPending

}

The test result.

Scenario: Tests with steps using Set-StepPending are pending
[?] Given this step is not yet implemented 96ms
# TODO: (Pester::Pending)
at C:\Users\<SOME_FOLDER>\features\Example.Steps.ps1: line 10
at C:\Users\<SOME_FOLDER>\features\MyNewFeature.feature: line 10
[!] When something else 0ms
[!] Then this should happen 0ms

1 scenario (1 pending)
3 steps (2 skipped, 1 pending)
Tests completed in 408ms

#>
[CmdletBinding()]
param ( )

Assert-DescribeInProgress -CommandName Set-StepPending
$lineText = $MyInvocation.Line.TrimEnd($([System.Environment]::NewLine))
$line = $MyInvocation.ScriptLineNumber
$file = $MyInvocation.ScriptName

throw ( New-PendingStepErrorRecord -File $file -Line $line -LineText $lineText)
}
15 changes: 7 additions & 8 deletions Functions/Gherkin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Describe "When displaying PesterResults in the console" -Tag Gherkin {
Import-Module $scriptRoot\Pester.psd1 -Force

New-Object psobject -Property @{
Results = Invoke-Gherkin (Join-Path $scriptRoot Examples\Gherkin\Gherkin-PesterResultShowsFeatureAndScenarioNames.feature) -PassThru -Show None
Results = Invoke-Gherkin (Join-Path $scriptRoot Examples\Gherkin\Gherkin-PesterResultShowsFeatureAndScenarioNames.feature) -PassThru -Show None #-HideStepData
}
}

Expand All @@ -302,7 +302,6 @@ Describe "When displaying PesterResults in the console" -Tag Gherkin {
'The Pester test report shows scenario names with examples [Failing Scenario (inconclusive) 1]'
)
}

}

Describe "Check test results of steps" -Tag Gherkin {
Expand All @@ -313,7 +312,7 @@ Describe "Check test results of steps" -Tag Gherkin {
Import-Module $scriptRoot\Pester.psd1 -Force

New-Object psobject -Property @{
Results = Invoke-Gherkin (Join-Path $scriptRoot Examples\Gherkin\Gherkin-PesterResultShowsFeatureAndScenarioNames.feature) -PassThru -Show None
Results = Invoke-Gherkin (Join-Path $scriptRoot Examples\Gherkin\Gherkin-PesterResultShowsFeatureAndScenarioNames.feature) -PassThru -Show None -HideStepData
}
}

Expand Down Expand Up @@ -369,19 +368,19 @@ Describe "Check test results of steps" -Tag Gherkin {
}

It "Test result 11 is correct" {
$testResults[10] | Should -Be 'Inconclusive'
$testResults[10] | Should -Be 'Skipped'
}

It "Test result 12 is correct" {
$testResults[11] | Should -Be 'Inconclusive'
$testResults[11] | Should -Be 'Skipped'
}

It "Test result 13 is correct" {
$testResults[12] | Should -Be 'Inconclusive'
}

It "Test result 14 is correct" {
$testResults[13] | Should -Be 'Inconclusive'
$testResults[13] | Should -Be 'Passed'
}

It "Test result 15 is correct" {
Expand All @@ -402,7 +401,7 @@ Describe "A generated NUnit report" -Tag Gherkin {
Import-Module $scriptRoot\Pester.psd1 -Force

New-Object psobject -Property @{
Results = Invoke-Gherkin (Join-Path $scriptRoot Examples\Gherkin\JustForReporting*.feature) -PassThru -Show None -OutputFile $reportFile
Results = Invoke-Gherkin (Join-Path $scriptRoot Examples\Gherkin\JustForReporting*.feature) -PassThru -Show None -OutputFile $reportFile -HideStepData
}
}

Expand Down Expand Up @@ -522,7 +521,7 @@ Describe "A generated NUnit report" -Tag Gherkin {
Get-XmlValue "($scenario2Examples1StepsXPath/@result)[3]" | Should -Be "Success"
Get-XmlValue "($scenario2Examples1StepsXPath/@result)[4]" | Should -Be "Success"
Get-XmlValue "($scenario2Examples1StepsXPath/@result)[5]" | Should -Be "Failure"
Get-XmlValue "($scenario2Examples1StepsXPath/@result)[6]" | Should -Be "Inconclusive"
Get-XmlValue "($scenario2Examples1StepsXPath/@result)[6]" | Should -Be "Ignored"

Get-XmlInnerText "$scenario2Examples1StepsXPath[5]/failure/message" | Should -Be "An example error in the then clause"
if ($expectFeatureFileNameInStackTrace) {
Expand Down
Loading