Skip to content

Commit

Permalink
Merge pull request #174 from dlwyatt/DescribeFix
Browse files Browse the repository at this point in the history
Describe and Context fix
  • Loading branch information
dlwyatt committed Aug 4, 2014
2 parents 985f20f + 1ecfbc6 commit 6ca02f6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Functions/Context.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Set-StrictMode -Version Latest

Describe 'Testing Context' {
It 'Has a non-mandatory fixture parameter which throws the proper error message if missing' {
$command = Get-Command Context -Module Pester
$command | Should Not Be $null

$parameter = $command.Parameters['Fixture']
$parameter | Should Not Be $null

$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory

$isMandatory | Should Be $false

{ Context Bogus } | Should Throw 'No test script block is provided'
}
}
4 changes: 2 additions & 2 deletions Functions/Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ param(
[Parameter(Mandatory = $true)]
$name,

[Parameter(Mandatory = $true)]
[ScriptBlock] $fixture
[ValidateNotNull()]
[ScriptBlock] $fixture = $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)")
)
$Pester.EnterContext($name)
$TestDriveContent = Get-TestDriveChildItem
Expand Down
18 changes: 18 additions & 0 deletions Functions/Describe.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Set-StrictMode -Version Latest

Describe 'Testing Describe' {
It 'Has a non-mandatory fixture parameter which throws the proper error message if missing' {
$command = Get-Command Describe -Module Pester
$command | Should Not Be $null

$parameter = $command.Parameters['Fixture']
$parameter | Should Not Be $null

$attribute = $parameter.Attributes | Where-Object { $_.TypeId -eq [System.Management.Automation.ParameterAttribute] }
$isMandatory = $null -ne $attribute -and $attribute.Mandatory

$isMandatory | Should Be $false

{ Describe Bogus } | Should Throw 'No test script block is provided'
}
}
3 changes: 2 additions & 1 deletion Functions/Describe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ about_TestDrive
param(
[Parameter(Mandatory = $true, Position = 0)] $name,
$tags=@(),
[Parameter(Mandatory = $true, Position = 1)]
[Parameter(Position = 1)]
[ValidateNotNull()]
[ScriptBlock] $fixture = $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)")
)

Expand Down

0 comments on commit 6ca02f6

Please sign in to comment.