Closed mwrock closed 12 years ago
I started a discussion on this somewheres... and that was in email (just looked).
The email from awhile back... (Late April 2012):
"My recent presentation on pester (April 2012): http://bit.ly/powershellbdd
You may have noticed I started thinking about putting together a mocking framework, but after quite a bit of thought, I think it might be better as part of pester itself. Typically the testing framework and the mocking framework are completely separate, but in the case of powershell it might be better served as one unit. I started looking into it, but before going further, I'd like to get your thoughts."
Yeah. I agree that in this case it seems to make more sense to bake directly into Pester. Without a proper DI mechanism which is overkill for PS IMHO, having mocking decoupled from the test framework doesn't make sense.
I even started some code on this but never went further.
Did you start a repo or fork for it? Anything you think is worth starting with. I'm not sure when I would start, I want to wrap up the Chocolatey bootstraper (at least a v.1) before starting anything new but I also see this as a fairly smal effort to get in a working state. Then again, I've said that before embarcing on multi month coding projects where I suddenly wonder why I'm googling for calculus formulas.
Note to self: If you are using calculus in a PS mocking framework, you are doing it wrong.
I didn't even make it that far.
I have it sitting uncommitted in a repo - it's not really much at all.
This is now commited. with fd0a9fec57fb052bd63e2a48199e0d901e4a77f0
So I know I am not the first to ever think or mention this, but having done a deep dive into the Chocolatey testing written by @ferventcoder which uses pester and its own rolled mocks, I now have a picture in my head of how this might look. Something like this:
The example uses one of the tests in Chocolatey. It is testing a function called Chocolatey-Install which in turn calls a function Chocolatey-Nuget. The test does not want the real Chocolatey-Nuget which does alot of internet stuff to actually run. The test just wants Chocolatry-Nuget to return the string 'dude' if Chocolatey-Nuget is called with a package name called 'testPackage'.
This would be implemented by Renaming the function called Chocolatey-Nuget to something else and then dynamically creating a function called Chocolatey-Nuget that invokes the mockWith scriptBlock if the param filters are met. At the end of Describe, all renamed mocked functions are renamed back to their original names.
I'd love to submit a pull request for this but wanted to get a discussion started.