Permalink
Browse files

starting mocking...so exciting!!

  • Loading branch information...
1 parent b103a3d commit 84d5acbab1d809a121378048908dd2a8b2dfefc9 @mwrock mwrock committed Sep 23, 2012
Showing with 36 additions and 1 deletion.
  1. +16 −0 Functions/Mock.Tests.ps1
  2. +19 −0 Functions/Mock.ps1
  3. +1 −1 Pester.psm1
@@ -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)
+ }
+}
View
@@ -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
+}
View
@@ -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.