Skip to content

Commit

Permalink
Simplify missing profile parent test
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Mar 3, 2017
1 parent 1720116 commit a6eaa43
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions test/Utils.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Describe 'Utils Function Tests' {
$profilePath = [System.IO.Path]::GetTempFileName()
}
AfterEach {
Remove-Item $profilePath -ErrorAction SilentlyContinue
Remove-Item $profilePath -Recurse -ErrorAction SilentlyContinue
}
It 'Creates profile file if it does not exist that imports absolute path' {
Mock Get-PSModulePath {
Expand Down Expand Up @@ -49,33 +49,17 @@ Describe 'Utils Function Tests' {
@($content)[1] | Should BeExactly "Import-Module posh-git"
}
It 'Creates profile file if the profile dir does not exist' {
$temp = [System.IO.Path]::GetTempPath();
$parentDir = Join-Path $temp ([System.Guid]::NewGuid())
Mock Get-PSModulePath {
return @(
'C:\Users\Keith\Documents\WindowsPowerShell\Modules',
'C:\Program Files\WindowsPowerShell\Modules',
'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\',
"$parentDir")
}
# Use $profilePath as missing parent directory (auto-cleanup)
$parentPath = $profilePath
Remove-Item -LiteralPath $profilePath
Test-Path -LiteralPath $profilePath | Should Be $false

$profPath = Join-Path $parentDir profile.ps1
Test-Path -LiteralPath $profPath | Should Be $false
$childProfilePath = Join-Path $parentPath profile.ps1

try {
Add-PoshGitToProfile $profPath $parentDir
Add-PoshGitToProfile $childProfilePath

Test-Path -LiteralPath $profPath | Should Be $true
Get-FileEncoding $profPath | Should Be 'utf8'
$content = Get-Content $profPath
$content.Count | Should Be 2
@($content)[1] | Should BeExactly "Import-Module posh-git"
}
finally {
if (Test-Path -LiteralPath $parentDir) {
Remove-Item $parentDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
Test-Path -LiteralPath $childProfilePath | Should Be $true
$childProfilePath | Should Contain "^Import-Module .*posh-git"
}

It 'Does not modify profile that already refers to posh-git' {
Expand Down

0 comments on commit a6eaa43

Please sign in to comment.