Skip to content

Commit

Permalink
Fix the ItImpl parameters
Browse files Browse the repository at this point in the history
Fixed the ItImpl parameters to make it work correctly with the Skipped
and Pending. I also set the ScriptBlock to empty scriptblock after
validating all parameters. That way the Invoke-Test function interface
is kept strict (it requires a ScriptBlock) while the desired
functionality is kept.  I am not sure if this is hundred percent
correct, because I am not sure where the boundary between Pester and
'Common Testing Framework' should be and what these should and should
not implement.
  • Loading branch information
nohwnd committed Oct 29, 2014
1 parent 930894b commit 61cfd23
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased
- Fix Skipped and Pending
- Fix output format on non-US systems

## 3.1 (October 23, 2014)
- Fix mocking of Get-ItemProperty
- Fix mocking commands with parameters named $FunctionName, $ModuleName or $ArgumentList under some circumstances. [GH-215]
Expand Down
2 changes: 1 addition & 1 deletion Functions/It.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ InModuleScope Pester {
$testState.LeaveTest()

It 'Throws an error if you fail to pass in a test block' {
$scriptBlock = { ItImpl 'Some Name' }
$scriptBlock = { ItImpl -Pester $testState 'Some Name' }
$scriptBlock | Should Throw 'No test script block is provided. (Have you put the open curly brace on the next line?)'
}

Expand Down
16 changes: 14 additions & 2 deletions Functions/It.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,33 @@ about_should

function ItImpl
{
[CmdletBinding(DefaultParameterSetName = 'Normal')]
param(
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true, Position=0)]
[string]$name,
[ScriptBlock] $test = $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)"),
[Parameter(Position = 1)]
[ScriptBlock] $test,
[System.Collections.IDictionary[]] $TestCases,
[Parameter(ParameterSetName = 'Pending')]
[Switch] $Pending,

[Parameter(ParameterSetName = 'Skip')]
[Switch] $Skip,

$Pester,
[scriptblock] $OutputScriptBlock
)

Assert-DescribeInProgress -CommandName It

#unless Skip or Pending is specified you must specify a ScriptBlock to the Test parameter
if (-not ($PSBoundParameters.ContainsKey('test') -or $Skip -or $Pending))
{
throw 'No test script block is provided. (Have you put the open curly brace on the next line?)'
}

#the function is called with Pending or Skipped set the script block if needed
if ($null -eq $test) { $test = {} }

#mark empty Its as Pending
#[String]::IsNullOrWhitespace is not available in .NET version used with PowerShell 2
Expand Down

0 comments on commit 61cfd23

Please sign in to comment.