Skip to content

Commit

Permalink
🔧 Fix divide by zero on some systems (#192)
Browse files Browse the repository at this point in the history
* $TotalKoans in stead of $PesterTests.Totalcount so it
is consistent in both conditions.

* Added tests for divide by zero error

* minor changes

* oops
  • Loading branch information
tomlarse authored and vexx32 committed May 31, 2019
1 parent b160923 commit ce875f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PSKoans/Public/Measure-Karma.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
@{
Complete = $true
KoansPassed = $KoansPassed
TotalKoans = $PesterTests.TotalCount
TotalKoans = $TotalKoans
}
}

Expand Down
26 changes: 26 additions & 0 deletions Tests/Functions/Public/Measure-Karma.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,32 @@ Describe 'Measure-Karma' {
Measure-Karma -Topic $Topic
Assert-MockCalled Invoke-Koan -Times @($Topic).Count
}

It 'should not divide by zero if all Koans are completed' {
$KoansCompletedTestLocation = 'TestDrive:{0}PSKoansCompletedTest' -f [System.IO.Path]::DirectorySeparatorChar
$TestFile = Join-Path -Path $KoansCompletedTestLocation -ChildPath 'SingleTopicTest.Koans.Ps1'

New-Item $KoansCompletedTestLocation -ItemType Directory
New-Item $TestFile -ItemType File

@'
using module PSKoans
[Koan(Position = 1)]
param()
Describe 'Koans Test' {
It 'is easy to solve' {
$true | should -be $true
}
}
'@ | Set-Content $TestFile

Set-PSKoanLocation $KoansCompletedTestLocation

{Measure-Karma -Topic SingleTopicTest} | Should -Not -Throw

Set-PSKoanLocation $TestLocation
}
}

Context 'With -Reset Switch' {
Expand Down

0 comments on commit ce875f3

Please sign in to comment.