-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Should -Throw and Should -Not -Throw integration tests
- Loading branch information
Showing
4 changed files
with
104 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Describe 'Should -Not -Throw' { | ||
Context 'When the tests are negated' { | ||
It 'Should convert `Should -Not -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage'' -ActualValue { $null = 1 + 1 }` correctly' { | ||
Should -Not -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' -ActualValue { | ||
$null = 1 + 1 | ||
} | ||
} | ||
|
||
It 'Should convert `{ $null = 1 + 1 } | Should -Not -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage''` correctly' { | ||
{ | ||
$null = 1 + 1 | ||
} | Should -Not -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' | ||
} | ||
|
||
It 'Should convert `$scriptBlock | Should -Not -Throw` correctly' { | ||
$scriptBlock = { | ||
$null = 1 + 1 | ||
} | ||
|
||
$scriptBlock | Should -Not -Throw | ||
} | ||
|
||
It 'Should convert `{ $null = 1 + 1 } | Should -Not -Throw -Because ''BecauseString''` correctly' { | ||
# Intentionally having everything on one line to test the conversion. | ||
{ $null = 1 + 1 } | Should -Not -Throw -Because 'BecauseString' | ||
} | ||
|
||
It 'Should convert `{ $null = 1 + 1 } | Should -Not -Throw -Because ''BecauseString'' -ExpectedMessage ''ExpectedString''` correctly' { | ||
# Intentionally splitting over two lines to test the conversion. | ||
{ $null = 1 + 1 } | | ||
Should -Not -Throw -Because 'BecauseString' -ExpectedMessage 'ExpectedString' | ||
} | ||
|
||
It 'Should convert `''$null = 1 + 1'' | ForEach-Object { [scriptblock]::Create($_) } | Should -Throw -Not` correctly' { | ||
# Intentionally splitting over three lines to test the conversion. | ||
'$null = 1 + 1' | | ||
ForEach-Object { [scriptblock]::Create($_) } | | ||
Should -Throw -Not | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Describe 'Should -Throw' { | ||
Context 'When the tests are affirming' { | ||
It 'Should convert `Should -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage'' -ActualValue { Write-Error -Message ''MockErrorMessage'' -ErrorId ''MockErrorId'' -Category ''InvalidOperation'' -TargetObject ''MockTargetObject'' -ErrorAction ''Stop'' }` correctly' { | ||
Should -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' -ActualValue { | ||
Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' | ||
} | ||
} | ||
|
||
It 'Should convert `Should -Throw -Because ''BecauseString'' -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -ExpectedMessage ''MockErrorMessage''` correctly' { | ||
{ | ||
Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' | ||
} | Should -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' | ||
} | ||
|
||
It 'Should convert `$scriptBlock | Should -Throw` correctly' { | ||
$scriptBlock = { throw 'mock error' } | ||
|
||
$scriptBlock | Should -Throw | ||
} | ||
|
||
It 'Should convert `{ throw ''myMessage'' } | Should -Throw -Because ''BecauseString''` correctly' { | ||
{ throw 'myMessage' } | Should -Throw -Because 'BecauseString' | ||
} | ||
|
||
It 'Should convert `{ throw ''myMessage'' } | Should -Throw -Because ''BecauseString'' -ExpectedMessage ''ExpectedString''` correctly' { | ||
{ throw 'myMessage' } | | ||
Should -Throw -Because 'BecauseString' -ExpectedMessage 'myMessage' | ||
} | ||
|
||
It 'Should convert `"throw ''five''" | ForEach-Object { [scriptblock]::Create($_) } | Should -Throw -Not` correctly' { | ||
"throw 'five'" | | ||
ForEach-Object { [scriptblock]::Create($_) } | | ||
Should -Throw | ||
} | ||
|
||
It 'Should convert `Should -Throw ''MockErrorMessage'' ''MockErrorId'' ([System.Exception]) ''BecauseString''` correctly' { | ||
{ | ||
Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' | ||
} | Should -Throw 'MockErrorMessage' 'MockErrorId' ([System.Exception]) 'BecauseString' | ||
} | ||
|
||
It 'Should convert `Should -Throw ''MockErrorMessage'' ''MockErrorId'' ([System.Exception])` correctly' { | ||
{ | ||
Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' | ||
} | Should -Throw 'MockErrorMessage' 'MockErrorId' ([System.Exception]) | ||
} | ||
|
||
It 'Should convert `Should -Throw ''MockErrorMessage'' ''MockErrorId''` correctly' { | ||
{ | ||
Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' | ||
} | Should -Throw 'MockErrorMessage' 'MockErrorId' | ||
} | ||
|
||
It 'Should convert `Should -Throw ''MockErrorMessage''` correctly' { | ||
{ | ||
Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' | ||
} | Should -Throw 'MockErrorMessage' | ||
} | ||
} | ||
} |
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