Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for mocking cmdlets with an -ArgumentList parameter #354

Merged
merged 3 commits into from
May 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions Functions/Mock.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,15 @@ Describe 'Mocking commands with potentially ambigious parameter sets' {
Assert-MockCalled SomeFunction -ParameterFilter { $p1 -eq 'Whatever' }
}
}

Describe 'When mocking a command that has an ArgumentList parameter with validation' {
Mock Start-Process { return 'mocked' }

It 'Calls the mock properly' {
$hash = @{ Result = $null }
$scriptBlock = { $hash.Result = Start-Process -FilePath cmd.exe -ArgumentList '/c dir c:\' }

$scriptBlock | Should Not Throw
$hash.Result | Should Be 'mocked'
}
}
6 changes: 3 additions & 3 deletions Functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,10 @@ function MockPrototype {
[string] $IgnoreErrorPreference = 'SilentlyContinue'
}

[object] $ArgumentList = Get-Variable -Name args -ValueOnly -Scope Local -ErrorAction $IgnoreErrorPreference
if ($null -eq $ArgumentList) { $ArgumentList = @() }
[object] ${a r g s} = Get-Variable -Name args -ValueOnly -Scope Local -ErrorAction $IgnoreErrorPreference
if ($null -eq ${a r g s}) { ${a r g s} = @() }

Invoke-Mock -CommandName '#FUNCTIONNAME#' -ModuleName '#MODULENAME#' -BoundParameters $PSBoundParameters -ArgumentList $ArgumentList
Invoke-Mock -CommandName '#FUNCTIONNAME#' -ModuleName '#MODULENAME#' -BoundParameters $PSBoundParameters -ArgumentList ${a r g s}
}

function Invoke-Mock {
Expand Down