Skip to content

Commit 52f4682

Browse files
committed
tests: Refactor tests
Remove duplications from testing the functions
1 parent b30b82d commit 52f4682

File tree

4 files changed

+56
-114
lines changed

4 files changed

+56
-114
lines changed

src/PesterExtensions/Public/Test-SemanticVersionUpdate.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ function Test-SemanticVersionUpdate {
1818
[version]"$(${major} + 1).0.0"
1919
)
2020
return $ValidVersions -contains $Next
21+
22+
<#
23+
.PARAMETER current
24+
Some documentation here and there
25+
26+
.PARAMETER Next
27+
Some documentation here and there
28+
#>
2129
}

tests/PesterExtensions/PesterExtensions.Get-ProjectRoot.Tests.ps1

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/PesterExtensions/PesterExtensions.Get-ScriptPath.Tests.ps1

Lines changed: 0 additions & 58 deletions
This file was deleted.

tests/PesterExtensions/PesterExtensions.Tests.ps1

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ param(
22
[version]$Version
33
)
44

5-
6-
BeforeDiscovery {
7-
$CommandNames = @(
8-
'Get-ScriptPath',
9-
'Get-ProjectRoot',
10-
'Test-SemanticVersionUpdate'
11-
) | Sort-Object
12-
$script:Commands = foreach ($command in $CommandNames) { @{ Command = $command } }
13-
$script:Stupid = @( @{CommandNames = $CommandNames } )
14-
}
15-
165
BeforeAll {
176
Import-Module -Name PesterExtensions
187
$ModulePath = "$(Get-ScriptPath -Path $PSCommandPath -Extension Manifest)"
@@ -25,8 +14,6 @@ BeforeAll {
2514
}
2615

2716
Describe 'All the important fields are not empty' {
28-
BeforeAll {
29-
}
3017
It '<property> should not be null' -TestCases @(
3118
@{ Property = 'Path' }
3219
@{ Property = 'Description' }
@@ -55,18 +42,57 @@ Describe 'Validate the version' {
5542
}
5643
}
5744

58-
Describe 'Exported functions' {
59-
Context 'stupid' -ForEach $stupid {
60-
It 'Module manifest contains all the exported commands' {
61-
$ModuleInfo.ExportedCommands.Keys | Sort-Object | Should -Be $CommandNames
45+
Describe 'Check functions' -ForEach @(
46+
@{
47+
CommandName = 'Get-ScriptPath';
48+
Verb = 'Get';
49+
Noun = 'ScriptPath';
50+
Parameters = @(
51+
@{Parameter = 'Path'; Mandatory = $true }
52+
@{Parameter = 'Extension'; Mandatory = $false }
53+
@{Parameter = 'SourceDirectory'; Mandatory = $false }
54+
@{Parameter = 'TestsDirectory'; Mandatory = $false }
55+
)
56+
}
57+
@{
58+
CommandName = 'Get-ProjectRoot';
59+
Verb = 'Get';
60+
Noun = 'ProjectRoot';
61+
Parameters = @(
62+
@{Parameter = 'Path'; Mandatory = $true }
63+
@{Parameter = 'ProjectsRoot'; Mandatory = $false }
64+
@{Parameter = 'Name'; Mandatory = $false }
65+
@{Parameter = 'Markers'; Mandatory = $false }
66+
)
67+
}
68+
@{
69+
CommandName = 'Test-SemanticVersionUpdate';
70+
Verb = 'Test';
71+
Noun = 'SemanticVersionUpdate';
72+
Parameters = @(
73+
@{Parameter = 'Current'; Mandatory = $true }
74+
@{Parameter = 'Next'; Mandatory = $true }
75+
)
76+
}
77+
) {
78+
BeforeAll {
79+
$script:Command = Get-Command $CommandName
80+
}
81+
It 'Module manifest contains <commandName>' {
82+
$ModuleInfo.ExportedCommands.Keys | Should -Contain $CommandName
83+
}
84+
It 'Imported Module contains <commandName>' {
85+
$ImportedModule.ExportedCommands.Keys | Should -Contain $CommandName
86+
}
87+
Describe '<parameter>' -ForEach $Parameters {
88+
It '<CommandName> contains <parameter>' {
89+
$command | Should -HaveParameter $parameter -Mandatory:$mandatory
6290
}
63-
It 'Imported Module contains all the exported commands' {
64-
$ImportedModule.ExportedCommands.Keys | Sort-Object | Should -Be $CommandNames
91+
It '<parameter> should be documented' {
92+
$help = Get-Help $CommandName -Parameter $parameter
93+
$help.Description | Should -Not -BeNullOrEmpty -Because "$parameter should have description"
6594
}
6695
}
67-
It '<command> is exported' -TestCases $Commands {
68-
Get-Command -Name $command -ErrorAction Ignore | Should -Not -Be $null -Because "$command function should be exporeted"
69-
}
7096
}
7197

7298
AfterAll {

0 commit comments

Comments
 (0)