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

Mock fix #362

Merged
merged 2 commits into from
May 27, 2015
Merged

Mock fix #362

merged 2 commits into from
May 27, 2015

Conversation

dlwyatt
Copy link
Member

@dlwyatt dlwyatt commented May 26, 2015

New tests and bug fixes to address #361 .

Two bugs here.  One, if a mock exists but no blocks match their parameter filter, the original command is called from Pester's session state instead of from the session state of the original caller of the mock.  This can sometimes cause bugs in people's scripts.

Second, inside of Mock / Validate-Command, calls are being made to Get-Content in such a way that if the test author mocks it, Pester's internals wind up triggering the mock (because it runs code in their module scope.)  This can also lead to errors.
There's still a potential gotcha here if a non-advanced function is mocked, and there are no matching parameter filters.  In that case, there's no $PSCmdlet variable in the mock bootstrap function, and I don't know how else to find the caller's SessionState object.  In that circumstance, I opted to execute the original command from the scope where the mock is defined, which should be correct most of the time.
dlwyatt added a commit that referenced this pull request May 27, 2015
@dlwyatt dlwyatt merged commit 508f9cb into pester:master May 27, 2015
@dlwyatt dlwyatt deleted the MockFix branch May 27, 2015 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant