Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
starting mocking...so exciting!!
  • Loading branch information
mwrock committed Oct 22, 2012
1 parent b103a3d commit 84d5acb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Functions/Mock.Tests.ps1
@@ -0,0 +1,16 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"

function FunctionUnderTest {
return "I am a real world test"
}

Describe "When calling Mock" {
Mock FunctionUnderTest {return}

It "Should rename function under test" {
$rename = gci function:PesterIsMocking_FunctionUnderTest
$rename.Count.should.be(1)
}
}
19 changes: 19 additions & 0 deletions Functions/Mock.ps1
@@ -0,0 +1,19 @@
function Mock ([string]$function, [ScriptBlock]$mockWith, [switch]$verifiable, [HashTable]$parameterFilters = @{})
{
# If verifiable, add to a verifiable hashtable
# Rename existing function
# Create New Function to invoke Script Block
# Mocked function should redirect to real function if param filters are not met
# param filters are met, mark in the verifiable table
}

function Assert-VerifiableMocks {
# Check that the Verifiables have all been called
# if not, throw
}

function Clear-Mocks {
# Called at the end of Describe
# Clears the Verifiable table
# Renames all renamed mocks back to original names
}
2 changes: 1 addition & 1 deletion Pester.psm1
Expand Up @@ -88,5 +88,5 @@ function New-Fixture($path, $name) {
Create-File "$path\$name.Tests.ps1" $fixture_code
}

Export-ModuleMember Describe, Context, It, In
Export-ModuleMember Describe, Context, It, In, Mock, Assert-VerifiableMocks
Export-ModuleMember Invoke-Pester, New-Fixture

0 comments on commit 84d5acb

Please sign in to comment.