forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changelog: Add -Because parameters to all assertions Fixes pester#312 Add -BeLessOrEqual and -BeGreaterOrEqual Add -Contain (that operates on arrays) Fixes pester#121 Add -BeLikeExactly Add -HaveType alias to -BeOfType Fix assertion messages in -BeOfType Fixes pester#729 Throw argument exception when -BeOfType is given type that is not loaded Add -PassThru to -Throw to get the exception when some is thrown and passes the filters Add -BeTrue to test for truthy values Add -BeFalse to test for falsy values Add -HaveCount to count stuff in collections
- Loading branch information
Showing
39 changed files
with
1,113 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,97 @@ | ||
Set-StrictMode -Version Latest | ||
|
||
InModuleScope Pester { | ||
Describe "PesterBeGreaterThan" { | ||
Describe "Should -BeGreaterThan" { | ||
It "passes if value greater than expected" { | ||
2 | Should BeGreaterThan 1 | ||
2 | Should -BeGreaterThan 1 | ||
2 | Should -GT 1 | ||
} | ||
|
||
It "fails if values equal" { | ||
3 | Should Not BeGreaterThan 3 | ||
3 | Should -Not -BeGreaterThan 3 | ||
3 | Should -Not -GT 3 | ||
{ 3 | Should BeGreaterThan 3 } | Verify-AssertionFailed | ||
{ 3 | Should -BeGreaterThan 3 } | Verify-AssertionFailed | ||
{ 3 | Should -GT 3 } | Verify-AssertionFailed | ||
} | ||
|
||
It "fails if value less than expected" { | ||
4 | Should Not BeGreaterThan 5 | ||
4 | Should -Not -BeGreaterThan 5 | ||
4 | Should -Not -GT 5 | ||
{ 4 | Should BeGreaterThan 5 } | Verify-AssertionFailed | ||
{ 4 | Should -BeGreaterThan 5 } | Verify-AssertionFailed | ||
{ 4 | Should -GT 5 } | Verify-AssertionFailed | ||
} | ||
|
||
It "returns the correct assertion message" { | ||
$err = { 4 | Should -BeGreaterThan 5 -Because 'reason' } | Verify-AssertionFailed | ||
$err.Exception.Message | Verify-Equal 'Expected {5} to be greater than the actual value, because reason, but got {4}.' | ||
} | ||
} | ||
|
||
Describe "Should -Not -BeGreaterThan" { | ||
It "passes if value is lower than the expected value" { | ||
0 | Should Not BeGreaterThan 1 | ||
0 | Should -Not -BeGreaterThan 1 | ||
0 | Should -Not -GT 1 | ||
} | ||
|
||
It "passes if value is equal to the expected value" { | ||
1 | Should Not BeGreaterThan 1 | ||
1 | Should -Not -BeGreaterThan 1 | ||
1 | Should -Not -GT 1 | ||
} | ||
|
||
It "fails if value is greater than the expected value" { | ||
{ 4 | Should Not BeGreaterThan 3 } | Verify-AssertionFailed | ||
{ 4 | Should -Not -BeGreaterThan 3 } | Verify-AssertionFailed | ||
{ 4 | Should -Not -GT 3 } | Verify-AssertionFailed | ||
} | ||
|
||
It "returns the correct assertion message" { | ||
$err = { 6 | Should -Not -BeGreaterThan 5 -Because 'reason' } | Verify-AssertionFailed | ||
$err.Exception.Message | Verify-Equal 'Expected {5} to be less or equal to the actual value, because reason, but got {6}.' | ||
} | ||
} | ||
|
||
Describe "Should -BeLessOrEqual" { | ||
It "passes if value is less than the expected value" { | ||
0 | Should -BeLessOrEqual 1 | ||
0 | Should -LE 1 | ||
} | ||
|
||
It "passes if value is equal to the expected value" { | ||
1 | Should -BeLessOrEqual 1 | ||
1 | Should -LE 1 | ||
} | ||
|
||
It "fails if value is greater than the expected value" { | ||
{ 4 | Should -BeLessOrEqual 3 } | Verify-AssertionFailed | ||
{ 4 | Should -LE 3 } | Verify-AssertionFailed | ||
} | ||
|
||
It "returns the correct assertion message" { | ||
$err = { 6 | Should -BeLessOrEqual 5 -Because 'reason' } | Verify-AssertionFailed | ||
$err.Exception.Message | Verify-Equal 'Expected {5} to be less or equal to the actual value, because reason, but got {6}.' | ||
} | ||
|
||
Describe "Should -Not -BeLessOrEqual" { | ||
It "passes if value greater than expected" { | ||
2 | Should -Not -BeLessOrEqual 1 | ||
2 | Should -Not -LE 1 | ||
} | ||
|
||
It "fails if values equal" { | ||
{ 3 | Should -Not -BeLessOrEqual 3 } | Verify-AssertionFailed | ||
{ 3 | Should -Not -LE 3 } | Verify-AssertionFailed | ||
} | ||
|
||
It "fails if value less than expected" { | ||
{ 4 | Should -Not -BeLessOrEqual 5 } | Verify-AssertionFailed | ||
{ 4 | Should -Not -LE 5 } | Verify-AssertionFailed | ||
} | ||
|
||
It "returns the correct assertion message" { | ||
$err = { 4 | Should -Not -BeLessOrEqual 5 -Because 'reason' } | Verify-AssertionFailed | ||
$err.Exception.Message | Verify-Equal 'Expected {5} to be greater than the actual value, because reason, but got {4}.' | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,54 @@ | ||
function PesterBeGreaterThan($ActualValue, $ExpectedValue, [switch] $Negate) | ||
function PesterBeGreaterThan($ActualValue, $ExpectedValue, [switch] $Negate, [string] $Because) | ||
{ | ||
[bool] $succeeded = $ActualValue -gt $ExpectedValue | ||
if ($Negate) { $succeeded = -not $succeeded } | ||
|
||
$failureMessage = '' | ||
if ($Negate) { | ||
return PesterBeLessOrEqual -ActualValue $ActualValue -ExpectedValue $ExpectedValue -Negate:$false -Because $Because | ||
} | ||
|
||
if (-not $succeeded) | ||
{ | ||
if ($Negate) | ||
{ | ||
$failureMessage = NotPesterBeGreaterThanFailureMessage -ActualValue $ActualValue -ExpectedValue $ExpectedValue | ||
} | ||
else | ||
{ | ||
$failureMessage = PesterBeGreaterThanFailureMessage -ActualValue $ActualValue -ExpectedValue $ExpectedValue | ||
if ($ExpectedValue -ge $ActualValue) { | ||
return New-Object psobject -Property @{ | ||
Succeeded = $false | ||
FailureMessage = "Expected {$ExpectedValue} to be greater than the actual value,$(Format-Because $Because) but got {$ActualValue}." | ||
} | ||
} | ||
|
||
return New-Object psobject -Property @{ | ||
Succeeded = $succeeded | ||
FailureMessage = $failureMessage | ||
Succeeded = $true | ||
} | ||
} | ||
|
||
function PesterBeGreaterThanFailureMessage($ActualValue,$ExpectedValue) | ||
{ | ||
return "Expected {$ActualValue} to be greater than {$ExpectedValue}" | ||
} | ||
|
||
function NotPesterBeGreaterThanFailureMessage($ActualValue,$ExpectedValue) | ||
function PesterBeLessOrEqual($ActualValue, $ExpectedValue, [switch] $Negate, [string] $Because) | ||
{ | ||
return "Expected {$ActualValue} to be less than or equal to {$ExpectedValue}" | ||
if ($Negate) { | ||
return PesterBeGreaterThan -ActualValue $ActualValue -ExpectedValue $ExpectedValue -Negate:$false -Because $Because | ||
} | ||
|
||
if ($ExpectedValue -lt $ActualValue) { | ||
return New-Object psobject -Property @{ | ||
Succeeded = $false | ||
FailureMessage = "Expected {$ExpectedValue} to be less or equal to the actual value,$(Format-Because $Because) but got {$ActualValue}." | ||
} | ||
} | ||
|
||
return New-Object psobject -Property @{ | ||
Succeeded = $true | ||
} | ||
} | ||
|
||
Add-AssertionOperator -Name BeGreaterThan ` | ||
-Test $function:PesterBeGreaterThan ` | ||
-Alias 'GT' | ||
|
||
Add-AssertionOperator -Name BeLessOrEqual ` | ||
-Test $function:PesterBeLessOrEqual ` | ||
-Alias 'LE' | ||
|
||
#keeping tests happy | ||
function PesterBeGreaterThanFailureMessage() { } | ||
function NotPesterBeGreaterThanFailureMessage() { } | ||
|
||
function PesterBeLessOrEqualFailureMessage() { } | ||
function NotPesterBeLessOrEqualFailureMessage() { } | ||
|
||
|
||
|
Oops, something went wrong.