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

Add test for update to Add-PoshGitToProfile #452

Merged
merged 3 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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