Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe and Context fix #174

Merged
merged 1 commit into from
Aug 4, 2014
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
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