Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 9b601ca

Browse files
authored
Merge pull request #25 from GitAMBS/fixtureissue17
Support -Name and -Fixture parameters on Describe blocks
2 parents 417cd91 + 3d6c7ef commit 9b601ca

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Modules/OperationValidation/Diagnostics/Comprehensive/PSGallery.Comprehensive.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Describe "E2E validation of PSGallery" {
1+
Describe "E2E validation of PSGallery" -fixture{
22
BeforeAll {
33
$Repository = "InternalPSGallery"
44
$ModuleName = "FormatTools"

Modules/OperationValidation/Diagnostics/Simple/PSGallery.Simple.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Describe "Simple Validation of PSGallery" {
1+
Describe -name "Simple Validation of PSGallery" {
22
It "The PowerShell Gallery should be responsive" {
33
$request = [System.Net.WebRequest]::Create("http://psget/psgallery")
44
$response = $Request.GetResponse()

Modules/OperationValidation/OperationValidation.psm1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,19 @@ function Get-TestFromScript
8989
}, $true) |
9090
ForEach-Object {
9191
# This is the name of the 'describe' block
92-
$describeName = ($_.CommandElements | Where-Object { $_.StaticType.name -eq 'string' })[1].SafeGetValue()
93-
92+
for ($x = 0; $x -lt $_.CommandElements.Count; $x++)
93+
{
94+
#Name parameter is named
95+
if ($_.CommandElements[$x] -is [System.Management.Automation.Language.CommandParameterAst] -and $_.CommandElements[$x].ParameterName -eq 'Name')
96+
{
97+
$describeName = $_.CommandElements[$x + 1].value
98+
}
99+
#if we have a string without a parameter name, return first hit. Name parameter is at position 0.
100+
ElseIf (($_.CommandElements[$x] -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and ($_.CommandElements[$x - 1] -is [System.Management.Automation.Language.StringConstantExpressionAst]))
101+
{
102+
$describeName = $_.CommandElements[$x].value
103+
}
104+
}
94105
$item = [PSCustomObject][ordered]@{
95106
Name = $describeName
96107
Tags = @()

0 commit comments

Comments
 (0)