forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging Describe / Context, updating output for new structure
- Loading branch information
Showing
8 changed files
with
73 additions
and
220 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,15 @@ | ||
function Context { | ||
<# | ||
.SYNOPSIS | ||
Provides logical grouping of It blocks within a single Describe block. Any Mocks defined | ||
inside a Context are removed at the end of the Context scope, as are any files or folders | ||
added to the TestDrive during the Context block's execution. Any BeforeEach or AfterEach | ||
blocks defined inside a Context also only apply to tests within that Context . | ||
.PARAMETER Name | ||
The name of the Context. This is a phrase describing a set of tests within a describe. | ||
.PARAMETER Fixture | ||
Script that is executed. This may include setup specific to the context and one or more It | ||
blocks that validate the expected outcomes. | ||
.EXAMPLE | ||
function Add-Numbers($a, $b) { | ||
return $a + $b | ||
} | ||
Describe "Add-Numbers" { | ||
Context "when root does not exist" { | ||
It "..." { ... } | ||
} | ||
Context "when root does exist" { | ||
It "..." { ... } | ||
It "..." { ... } | ||
It "..." { ... } | ||
} | ||
} | ||
.LINK | ||
Describe | ||
It | ||
BeforeEach | ||
AfterEach | ||
about_Should | ||
about_Mocking | ||
about_TestDrive | ||
#> | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[Parameter(Mandatory = $true, Position = 0)] | ||
[string] $Name, | ||
|
||
[ValidateNotNull()] | ||
[ScriptBlock] $Fixture = $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)") | ||
) | ||
|
||
ContextImpl @PSBoundParameters -Pester $Pester -ContextOutputBlock ${function:Write-Context} -TestOutputBlock ${function:Write-PesterResult} | ||
} | ||
|
||
function ContextImpl | ||
{ | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string] $Name, | ||
[Alias('Tags')] | ||
$Tag=@(), | ||
|
||
[Parameter(Position = 1)] | ||
[ValidateNotNull()] | ||
[ScriptBlock] $Fixture = $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)"), | ||
|
||
$Pester, | ||
[scriptblock] $ContextOutputBlock, | ||
[scriptblock] $TestOutputBlock | ||
[ScriptBlock] $Fixture = $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)") | ||
) | ||
|
||
Assert-DescribeInProgress -CommandName Context | ||
|
||
$Pester.EnterTestGroup($Name, 'Context') | ||
$TestDriveContent = Get-TestDriveChildItem | ||
|
||
if ($null -ne $ContextOutputBlock) | ||
{ | ||
& $ContextOutputBlock $Name | ||
} | ||
|
||
try | ||
{ | ||
Add-SetupAndTeardown -ScriptBlock $Fixture | ||
Invoke-TestGroupSetupBlocks | ||
|
||
do | ||
{ | ||
$null = & $Fixture | ||
} until ($true) | ||
} | ||
catch | ||
{ | ||
$firstStackTraceLine = $_.InvocationInfo.PositionMessage.Trim() -split '\r?\n' | & $SafeCommands['Select-Object'] -First 1 | ||
$Pester.AddTestResult('Error occurred in Context block', "Failed", $null, $_.Exception.Message, $firstStackTraceLine, $null, $null, $_) | ||
|
||
if ($null -ne $TestOutputBlock) | ||
{ | ||
$Pester.TestResult[-1] | & $TestOutputBlock | ||
} | ||
} | ||
finally | ||
{ | ||
Invoke-TestGroupTeardownBlocks | ||
} | ||
|
||
Clear-TestDrive -Exclude ($TestDriveContent | & $SafeCommands['Select-Object'] -ExpandProperty FullName) | ||
Exit-MockScope | ||
|
||
$Pester.LeaveTestGroup($Name, 'Context') | ||
Describe @PSBoundParameters -CommandUsed Context | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.