Skip to content

Commit

Permalink
Merge pull request #452 from dahlbyk/rkeithhill/add-pester-test-for-c…
Browse files Browse the repository at this point in the history
…reate-profile-dir

Add test for update to Add-PoshGitToProfile
  • Loading branch information
dahlbyk committed Mar 3, 2017
2 parents 7f3a7fb + 02cfb34 commit 88416ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ function Add-PoshGitToProfile {

# Make sure the PowerShell profile directory exists
$profileDir = Split-Path $profilePath -Parent
if (!(Test-Path -LiteralPath $profileDir)) {
if (!(Test-Path -LiteralPath $profileDir)) {
if ($PSCmdlet.ShouldProcess($profileDir, "Create current user PowerShell profile directory")) {
New-Item $profileDir -ItemType Directory -Verbose:$VerbosePreference > $null
New-Item $profileDir -ItemType Directory -Force -Verbose:$VerbosePreference > $null
}
}

Expand Down
14 changes: 13 additions & 1 deletion 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 @@ -48,6 +48,18 @@ Describe 'Utils Function Tests' {
$content.Count | Should Be 2
@($content)[1] | Should BeExactly "Import-Module posh-git"
}
It 'Creates profile file if the profile dir does not exist' {
# Use $profilePath as missing parent directory (auto-cleanup)
Remove-Item -LiteralPath $profilePath
Test-Path -LiteralPath $profilePath | Should Be $false

$childProfilePath = Join-Path $profilePath profile.ps1

Add-PoshGitToProfile $childProfilePath

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' {
$profileContent = @'
Import-Module PSCX
Expand Down

0 comments on commit 88416ba

Please sign in to comment.