pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.08k stars 470 forks source link

PowerShell 3.4.6 is loaded when a renamed function is called under Pester 4.0.7 #880

Closed it-praktyk closed 7 years ago

it-praktyk commented 7 years ago

The breaking changes introduced by #860 in Pester 4.0.7, means renaming of functions

I propose to add additional functions (with plural names like they were in Pester 3.4.6 with warning/error (?) message about breaking change or deprecation.

Pester v. 4.0.7 only


<OUTPUT_PARTIALLY_OMMITTED>

  Describing DynamicParam blocks in other scopes
    [-] Properly evaluates dynamic parameters when called from another scope 411ms
      CommandNotFoundException: The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      CmdletInvocationException: The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      at CallingFunction, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1376
      at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1394
    [-] Properly evaluates dynamic parameters when called from another scope when the call is from a ValidateScript block 230ms
      CommandNotFoundException: The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      CmdletInvocationException: The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      ParameterBindingValidationException: Cannot validate argument on parameter 'Whatever'. Cannot retrieve the dynamic parameters for the cmdlet. The term 'Get-MockDynamicParameters' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1398

  Describing Parameter Filters and Common Parameters
    [+] Applies common parameters correctly when testing the parameter filter 106ms

<OUTPUT_PARTIALLY_OMMITTED>

Tests completed in 14.51s
Tests Passed: 139, Failed: 2, Skipped: 0, Pending: 0, Inconclusive: 0

Pester v. 3.4.6 available too


<OUTPUT_PARTIALLY_OMMITTED>

  Describing DynamicParam blocks in other scopes
    [-] Properly evaluates dynamic parameters when called from another scope 845ms
      RuntimeException: Cannot index into a null array.
      at FindMock, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.6\Functions\Mock.ps1: line 966
      at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.6\Functions\Mock.ps1: line 876
      at <ScriptBlock><Begin>, <No file>: line 30
      at CallingFunction, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1376
      at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1394
    [-] Properly evaluates dynamic parameters when called from another scope when the call is from a ValidateScript block 86ms
      RuntimeException: Cannot index into a null array.
      CmdletInvocationException: Cannot index into a null array.
      ParameterBindingValidationException: Cannot validate argument on parameter 'Whatever'. Cannot index into a null array.
      at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1398
Describing Parameter Filters and Common Parameters
 [+] Applies common parameters correctly when testing the parameter filter 114ms

<OUTPUT_PARTIALLY_OMMITTED>

Describing Naming conflicts in mocked functions
   Context parameter named Metadata
    [+] Works with commands with parameter named Metadata 114ms
   Context parameter named Keys
    [-] Works with command with parameter named Keys 126ms
      ParameterBindingException: A parameter cannot be found that matches parameter name 'Keys'.
      at Test-ParameterFilter, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.6\Functions\Mock.ps1: line 1125
      at FindMatchingBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.6\Functions\Mock.ps1: line 999
      at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.6\Functions\Mock.ps1: line 901
      at <ScriptBlock><Process>, <No file>: line 66
      at Wrapper, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1825
      at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1829
Describing Passing unbound script blocks as mocks
 [-] Does not produce an error 178ms
   RuntimeException: '-Not' is not a valid Should operator.
   at Get-TestResult, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.6\Functions\Assertions\Should.ps1: line 42
   at <ScriptBlock>, <FOLDER_PATH>\Pester\Functions\Mock.Tests.ps1: line 1840

<OUTPUT_PARTIALLY_OMMITTED>

Tests completed in 9.69s
Tests Passed: 99, Failed: 2, Skipped: 0, Pending: 0, Inconclusive: 0
nohwnd commented 7 years ago

Like this? (are the Get and Set really necessary? Dave removed them from the migration guide because they are "internal". And I also don't know why would anyone ever use them in their tests, but on the other hand it is public api.

function Throw-RenamedFunction ($NewName) { 
    throw "This command has been renamed to '$NewName' please update your usage. For more information see: https://github.com/pester/Pester/wiki/Migrating-from-Pester-3-to-Pester-4" }
function Assert-VerifiableMocks { Throw-RenamedFunction -NewName 'Assert-VerifiableMock' }
function Get-MockDynamicParameters { Throw-RenamedFunction -NewName 'Get-MockDynamicParameters' }
function Set-DynamicParameterVariables { Throw-RenamedFunction -NewName 'Set-DynamicParameterVariable' }
Blackbaud-ShaydeNofziger commented 7 years ago

Currently seeing a similar issue wherein the first call to Assert-VerifiableMocks gives

RuntimeException: The Assert-VerifiableMocks command may only be used from a Pester test script.

However all subsequent calls to Assert-VerifiableMocks in the same manner succeed. Does this sound related or should I open a new issue?

The exception doesn't make much sense because we are running from a Pester test script...

nohwnd commented 7 years ago

@Blackbaud-ShaydeNofziger Which version of Pester are you using?

Blackbaud-ShaydeNofziger commented 7 years ago

@nohwnd 4.0.7, but it seems it falls back to 4.0.6, presumably because the plural command no longer exists.

it-praktyk commented 7 years ago

Please

I expected that after you will have loaded two versions of Pester.

Blackbaud-ShaydeNofziger commented 7 years ago

@it-praktyk D'oh! Thank you....

nohwnd commented 7 years ago

Yup, same problem. @it-praktyk see the hot news :D

it-praktyk commented 7 years ago

@nohwnd, I like it!