Skip to content

Allow Pester 6, and replace Assert-MockCalled - #146

Open
nohwnd wants to merge 2 commits into
PoshCode:mainfrom
nohwnd:pester6
Open

nohwnd wants to merge 2 commits into
PoshCode:mainfrom
nohwnd:pester6

Conversation

@nohwnd

@nohwnd nohwnd commented Dec 2, 2026 •

Copy link
Copy Markdown

build.requires.psd1 caps Pester at :[5.0, 6.0), so ModuleFast never installs 6.x. Widening the range alone does not work: Pester 6 removed Assert-MockCalled, and 5 test files use it 20 times.

This does both. The range becomes :[5.0, 7.0), the assertions become Should -Invoke. That command exists in Pester 5 too, so the range stays wide and the tests run on either version.

Tests/Private/ImportBase64Module.Tests.ps1 needed more than a rename:

$PSDefaultParameterValues = @{
    "Mock:ModuleName"              = "ModuleBuilder"
    "Assert-MockCalled:ModuleName" = "ModuleBuilder"
}

Should -Invoke is the Should command, so the matching key is "Should:ModuleName", which would hit every Should call in the file. The two call sites pass -ModuleName ModuleBuilder instead.

-Times 0 keeps its meaning. Pester treats it as exact even without -Exactly (Mock.ps1: $matchingCalls.Count -ne $Times -and ($Exactly -or ($Times -eq 0))), so the two -Times 0 assertions in CopyReadMe.Tests.ps1 still mean "never called".

Full Tests directory on macOS, each version in its own process: 235 passed and 0 failed on 5.9.1, the same on 6.2.0. I could not run it on Windows, CI only triggers on main.

  • test.ps1 requires MaximumVersion 4.999 and calls Invoke-Pester -Show / -PesterOption, both gone since Pester 5. Separate change?
  • Templates/Dotnet/ModuleBuilderModule/RequiredModules.psd1 pins [4.7.2, 5.0), so generated modules still get Pester 4.

🤖

`build.requires.psd1` capped Pester at `:[5.0, 6.0)`, so ModuleFast never
installed 6.x. Widening the range to `:[5.0, 7.0)` is not enough on its own,
because Pester 6 removed `Assert-MockCalled`, which 5 test files used 20 times.
Those are now `Should -Invoke`, which exists in Pester 5 as well, so the tests
run unchanged on both.

`Tests/Private/ImportBase64Module.Tests.ps1` needed more than a rename. It set
`"Assert-MockCalled:ModuleName"` in `$PSDefaultParameterValues`, and the
equivalent key for the new command would be `"Should:ModuleName"`, which would
apply to every `Should` call in the file. The two call sites pass
`-ModuleName ModuleBuilder` explicitly instead.

🤖
The comment claimed a "Should:ModuleName" default would apply to every Should
call, as if that were a hazard. It does apply to every call, and it is harmless:
-ModuleName belongs to the Invoke and InvokeVerifiable parameter sets, and the
other sets ignore the default. A plain `1 | Should -Be 1` passes with the key
set, on 5.9.1 and on 6.2.0, and gaelcolas/Sampler's own test template sets it on
purpose.

Passing -ModuleName on the two Should -Invoke calls is still the clearer choice,
so the code is unchanged. Only the reason was wrong.

🤖
@nohwnd

nohwnd commented Dec 2, 2026

Copy link
Copy Markdown
Author

Correcting myself on the comment I put in Tests/Private/ImportBase64Module.Tests.ps1. It said a "Should:ModuleName" default would apply to every Should call in the file, implying that is a problem. It does apply to every call, and it is harmless: -ModuleName belongs to the Invoke and InvokeVerifiable parameter sets, and the other sets ignore the default. With the key set, 1 | Should -Be 1 passes on 5.9.1 and on 6.2.0, and Sampler's own test template sets it deliberately.

Passing -ModuleName on the two Should -Invoke calls is still clearer, so the code is the same. 95bbc7d fixes the reason in the comment. 235 passed, 0 failed on 6.2.0 after it.

🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant