Skip to content

Commit

Permalink
🐛 Check for PSKoan directory before opening (#274)
Browse files Browse the repository at this point in the history
* Check for PSKoan directory before opening

* Add initial versions of 'Meditate' switch tests

* Add more mocks and asserts to '-Meditate' switch test
  • Loading branch information
usrme authored and vexx32 committed Oct 6, 2019
1 parent b9a2415 commit 3fb8b44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PSKoans/Public/Show-Karma.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function Show-Karma {
Get-PSKoan @GetParams
}
'OpenFolder' {
Write-Verbose "Checking existence of koans folder"
if (-not (Test-Path (Get-PSKoanLocation))) {
Write-Verbose "Koans folder does not exist. Initiating full reset..."
Update-PSKoan -Confirm:$false
}

Write-Verbose "Opening koans folder"
if ( $env:PSKoans_EditorPreference -eq 'code-insiders' -and (Get-Command -Name 'code-insiders' -ErrorAction SilentlyContinue) ) {
$VSCodeSplat = @{
Expand Down
21 changes: 21 additions & 0 deletions Tests/Functions/Public/Show-Karma.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,26 @@ Describe 'Show-Karma' {
}
}
}

Context 'With -Meditate Switch' {

Context 'PSKoans directory does not exist' {
BeforeAll {
Mock Test-Path { $false }
Mock Update-PSKoan
Mock Get-Command { $false }
Mock Invoke-Item
}

It 'should create PSKoans directory' {
Show-Karma -Meditate

Assert-MockCalled Test-Path -Times 1
Assert-MockCalled Update-PSKoan -Times 1
Assert-MockCalled Get-Command -Times 1
Assert-MockCalled Invoke-Item -Times 1
}
}
}
}
}

0 comments on commit 3fb8b44

Please sign in to comment.