Skip to content

Commit

Permalink
Allow positional parameter in get-shouldoperator (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
fflaten committed May 16, 2021
1 parent fd68fc1 commit ea079a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/functions/Get-ShouldOperator.ps1
Expand Up @@ -47,6 +47,7 @@ function Get-ShouldOperator {
$RuntimeParameterDictionary = & $SafeCommands['New-Object'] System.Management.Automation.RuntimeDefinedParameterDictionary
$AttributeCollection = & $SafeCommands['New-Object'] System.Collections.ObjectModel.Collection[System.Attribute]
$ParameterAttribute = & $SafeCommands['New-Object'] System.Management.Automation.ParameterAttribute
$ParameterAttribute.Position = 0

$AttributeCollection.Add($ParameterAttribute)

Expand Down
7 changes: 7 additions & 0 deletions tst/functions/Get-ShouldOperator.Tests.ps1
Expand Up @@ -45,6 +45,13 @@ InPesterModuleScope {
Get-ShouldOperator -Name $_ | Should -Not -BeNullOrEmpty -Because "$_ should have help"
}
}
It 'Throws on invalid assertion-name' {
{ Get-ShouldOperator BeHorrible } | Should -Throw -ExceptionType ([System.Management.Automation.ParameterBindingException]) -ErrorId 'ParameterArgumentValidationError,Get-ShouldOperator' -ExpectedMessage "*on parameter 'Name'*does not belong to the set*"
}

It 'Supports positional value' {
{ Get-ShouldOperator Be } | Should -Not -Throw -ErrorId 'PositionalParameterNotFound,Get-ShouldOperators' -Because 'Name-parameter supports values at position 0'
}
}
}
}

0 comments on commit ea079a5

Please sign in to comment.