Permalink
Browse files

adding new Assert-MockCalled feature: exciting stuff!

  • Loading branch information...
1 parent 7faa656 commit dd7dca288bf5d7258532243687b3f6b6e4936af3 @mwrock mwrock committed Oct 18, 2012
Showing with 29 additions and 1 deletion.
  1. +16 −1 Functions/Mock.Tests.ps1
  2. +13 −0 Functions/Mock.ps1
@@ -158,7 +158,7 @@ Describe "When Creaing a Verifiable Mock that is called" {
$result=$_
}
- It "Should not throw" {
+ It "Assert-VerifiableMocks Should not throw" {
$result.should.be("")
}
}
@@ -176,3 +176,18 @@ Describe "When Creaing a Verifiable Mock with a filter that does not return a bo
$result.should.be("The Parameter Filter must return a boolean")
}
}
+
+Describe "When Calling a filterless mock once with params" {
+ Mock FunctionUnderTest {}
+ FunctionUnderTest "one"
+
+ try {
+ Assert-MockCalled FunctionUnderTest 0
+ } Catch {
+ $result=$_
+ }
+
+ It "Assert-MockCalled 0 Should throw" {
+ $result.Exception.Message.should.be("Expected FunctionUnderTest to be called 0 times")
+ }
+}
View
@@ -1,4 +1,5 @@
$script:mockTable = @{}
+$script:callHistory = @()
function Mock {
@@ -170,14 +171,26 @@ This will not throw an exception because the mock was invoked.
}
}
+function Assert-MockCalled {
+param(
+ [string]$commandName,
+ [switch]$Exactly,
+ [int]$times=1,
+ [ScriptBlock]$parameterFilter = {$True}
+)
+
+}
+
function Clear-Mocks {
$mockTable.Keys | % { Microsoft.PowerShell.Management\Remove-Item function:\$_ }
$mockTable.Clear()
+ $callHistory.Clear()
Get-ChildItem Function: | ? { $_.Name.StartsWith("PesterIsMocking_") } | % {Rename-Item Function:\$_ "script:$($_.Name.Replace('PesterIsMocking_', ''))"}
}
function MockPrototype {
$functionName = $MyInvocation.MyCommand.Name
+ $callHistory += @{CommandName=$functionName;Params=$PSBoundParameters}
$mock=$mockTable.$functionName
$idx=$mock.blocks.Length
while(--$idx -ge 0) {

0 comments on commit dd7dca2

Please sign in to comment.