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

Make Clear-Host optional for Measure-Karma #142

Merged
merged 3 commits into from
Mar 29, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions PSKoans/Public/Measure-Karma.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@

[Parameter(Mandatory, ParameterSetName = "Reset")]
[switch]
$Reset
$Reset,

[Parameter()]
[Alias()]
[switch]
$ClearScreen
)
switch ($PSCmdlet.ParameterSetName) {
'ListKoans' {
Expand All @@ -90,7 +95,7 @@
ArgumentList = '"{0}"' -f (Get-PSKoanLocation)
NoNewWindow = $true
}
Start-Process @VSCodeSplat
Start-Process @VSCodeSplat
}
elseif (Get-Command -Name 'code' -ErrorAction SilentlyContinue) {
$VSCodeSplat = @{
Expand All @@ -105,7 +110,9 @@
}
}
"Default" {
Clear-Host
if ($ClearScreen) {
Clear-Host
}

Show-MeditationPrompt -Greeting

Expand Down
30 changes: 29 additions & 1 deletion Tests/Functions/Public/Measure-Karma.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ Describe 'Measure-Karma' {
Measure-Karma | Should -Be $null
}

It 'should write the meditation prompts' {
Assert-MockCalled Show-MeditationPrompt -Times 2
}

It 'should Invoke-Pester on each of the koans' {
$ValidKoans = Get-PSKoanLocation | Get-ChildItem -Recurse -Filter '*.Koans.ps1' |
Get-Command {$_.FullName} |
Where-Object {$_.ScriptBlock.Attributes.TypeID -match 'Koan'}

Assert-MockCalled Invoke-Koan -Times ($ValidKoans.Count)
}
}

Context 'With -ClearScreen Switch' {
BeforeAll {
Mock Clear-Host {}
Mock Show-MeditationPrompt -ModuleName 'PSKoans' {}
Mock Invoke-Koan -ModuleName 'PSKoans' {}

$TestLocation = 'TestDrive:{0}PSKoans' -f [System.IO.Path]::DirectorySeparatorChar
Set-PSKoanLocation -Path $TestLocation

Initialize-KoanDirectory -Confirm:$false
}

It 'should not produce output' {
Measure-Karma -ClearScreen | Should -Be $null
}

It 'should clear the screen' {
Assert-MockCalled Clear-Host -Times 1
}
Expand Down Expand Up @@ -52,7 +81,6 @@ Describe 'Measure-Karma' {
}

It 'should display only the greeting prompt' {
Assert-MockCalled Clear-Host
Assert-MockCalled Show-MeditationPrompt -Times 1
}

Expand Down