Skip to content

Commit

Permalink
✅ Update tests
Browse files Browse the repository at this point in the history
- Update Get-Karma tests to ensure variable is set
- Update Show-Karma tests to ensure variable
is properly used and subsequently cleared.
  • Loading branch information
vexx32 committed Jan 29, 2020
1 parent a7437a9 commit 3b7b5f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Tests/Functions/Public/Get-Karma.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ InModuleScope 'PSKoans' {
It 'should Invoke-Pester on koans until it fails a test' {
Assert-MockCalled Invoke-Koan -Times 1
}

It 'should populate the $script:CurrentTopic variable' {
$script:CurrentTopic | Should -BeOfType [hashtable]
$script:CurrentTopic.Count | Should -Be 4
@('Name', 'Completed', 'Total', 'CurrentLine') | Should -BeIn $script:CurrentTopic.Keys
}
}

Context 'With Nonexistent Koans Folder / No Koans Found' {
Expand Down
30 changes: 22 additions & 8 deletions Tests/Functions/Public/Show-Karma.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ Describe 'Show-Karma' {
$StartingLocation = Get-PSKoanLocation
Set-PSKoanLocation -Path "$TestDrive/Koans"

$EditorSetting = Get-PSKoanSetting -Name Editor

Reset-PSKoan -Confirm:$false
}

AfterAll {
Set-PSKoanLocation -Path $StartingLocation
Set-PSKoanSetting -Name Editor -Value $EditorSetting
}

InModuleScope 'PSKoans' {
Expand Down Expand Up @@ -117,7 +120,6 @@ Describe 'Show-Karma' {
Context 'With Nonexistent Koans Folder / No Koans Found' {
BeforeAll {
Mock Show-MeditationPrompt -ModuleName 'PSKoans' { }
Mock Measure-Koan -ModuleName 'PSKoans' { }
Mock Get-PSKoan -ModuleName 'PSKoans' { }
Mock Update-PSKoan -ModuleName 'PSKoans' { throw 'Prevent recursion' }
Mock Write-Warning
Expand All @@ -126,6 +128,10 @@ Describe 'Show-Karma' {
Mock New-Item
}

BeforeEach {
$script:CurrentTopic = $null
}

It 'should attempt to populate koans and then recurse to reassess' {
{ Show-Karma } | Should -Throw -ExpectedMessage 'Prevent recursion'
}
Expand Down Expand Up @@ -229,6 +235,13 @@ Describe 'Show-Karma' {
@{ Editor = $FilePath; Arguments = $ArgumentList }
}
Mock Get-Karma -ModuleName 'PSKoans' {
$script:CurrentTopic = @{
Name = 'TestTopic'
Completed = 0
Total = 4
CurrentLine = 1
}

[PSCustomObject]@{
PSTypeName = 'PSKoans.Result'
Meditation = 'TestMeditation'
Expand All @@ -237,17 +250,12 @@ Describe 'Show-Karma' {
Describe = 'TestDescribe'
Expectation = 'ExpectedTest'
It = 'TestIt'
CurrentTopic = [PSCustomObject]@{
Name = 'TestTopic"'
Completed = 0
Total = 4
CurrentLine = 1
}
CurrentTopic = [PSCustomObject]$script:CurrentTopic
}
}
Mock Get-PSKoan {
[PSCustomObject]@{ Path = $TestFile.FullName }
}
} -ParameterFilter { $Topic -eq 'TestTopic' }
}

AfterAll {
Expand All @@ -269,6 +277,8 @@ Describe 'Show-Karma' {

Assert-MockCalled Get-Command -Times 1
Assert-MockCalled Start-Process -Times 1

$script:CurrentTopic | Should -BeNullOrEmpty
}

It 'invokes the set editor with unknown editor chosen' {
Expand All @@ -284,6 +294,8 @@ Describe 'Show-Karma' {

Assert-MockCalled Get-Command -Times 1
Assert-MockCalled Start-Process -Times 1

$script:CurrentTopic | Should -BeNullOrEmpty
}

It 'opens the file directly when selected editor is unavailable' {
Expand All @@ -293,6 +305,8 @@ Describe 'Show-Karma' {

Assert-MockCalled Get-Command -Times 1 -ParameterFilter { $Name -eq "missing_editor" }
Assert-MockCalled Invoke-Item -Times 1

$script:CurrentTopic | Should -BeNullOrEmpty
}
}

Expand Down

0 comments on commit 3b7b5f0

Please sign in to comment.