Skip to content

Commit

Permalink
Merge pull request pester#276 from dlwyatt/BetterErrorMessage
Browse files Browse the repository at this point in the history
Improved error message in InModuleScope
  • Loading branch information
dlwyatt committed Feb 2, 2015
2 parents 4c389c7 + 8239211 commit e1de410
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added line information to test failure output in Should assertion failures. [GH-266]
- Added support for passing named parameters or positional arguments to test scripts, and for calling test scripts that are not named *.Tests.ps1. [GH-272]
- Made Pester compliant with StrictMode. [GH-274]
- Improved error message when InModuleScope finds multiple modules loaded with the same name. [GH-276]

## 3.3.5 (January 23, 2015)
- Updated tests to allow PRs to be automatically tested, with status updates to GitHub, by our CI server.
Expand Down
9 changes: 8 additions & 1 deletion Functions/InModuleScope.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ function InModuleScope

try
{
$module = Get-Module -Name $ModuleName -All -ErrorAction Stop
$modules = @(Get-Module -Name $ModuleName -All -ErrorAction Stop)
}
catch
{
throw "No module named '$ModuleName' is currently loaded."
}

if ($modules.Count -gt 1)
{
throw "Multiple modules named '$ModuleName' are currently loaded. Make sure to remove any extra copies of the module from your session before testing."
}

$module = $modules[0]

$originalState = $Pester.SessionState
$originalScriptBlockScope = Get-ScriptBlockScope -ScriptBlock $ScriptBlock

Expand Down

0 comments on commit e1de410

Please sign in to comment.