Skip to content

Commit

Permalink
Fix Should -BeOfType integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Aug 1, 2024
1 parent cec4e57 commit 76cef4c
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
95 changes: 95 additions & 0 deletions tests/Integration/Syntax/v5/ShouldBeOfType.v5.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Describe 'Should -BeOfType' {
Context 'When the tests are affirming' {
It 'Should convert `Should -BeOfType ''System.String''` correctly' {
'AnyString' | Should -BeOfType 'System.String'
}

It 'Should convert `Should -BeOfType [System.String]` correctly' {
'AnyString' | Should -BeOfType [System.String]
}

It 'Should convert `Should -BeOfType [System.String] ''BecauseString''` correctly' {
'AnyString' | Should -BeOfType [System.String] 'BecauseString'
}


It 'Should convert `Should -ActualValue ''AnyString'' [System.String] -BeOfType ''BecauseString''` correctly' {
Should -ActualValue 'AnyString' [System.String] -BeOfType 'BecauseString'
}

It 'Should convert `Should -ActualValue ''AnyString'' [System.String] -BeOfType -Because ''BecauseString''` correctly' {
Should -ActualValue 'AnyString' [System.String] -BeOfType 'BecauseString'
}

It 'Should convert `Should -ActualValue ''AnyString'' -ExpectedValue [System.String] -BeOfType -Because ''BecauseString''` correctly' {
Should -ActualValue 'AnyString' -ExpectedValue [System.String] -BeOfType -Because 'BecauseString'
}

It 'Should convert `Should -BeOfType [System.String] -ActualValue ''AnyString''` correctly' {
Should -BeOfType [System.String] -ActualValue 'AnyString'
}

It 'Should convert `Should -ExpectedValue [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' {
Should -ExpectedValue [System.String] -ActualValue 'AnyString' -BeOfType
}

It 'Should convert `Should -Not:$false -ExpectedValue [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' {
Should -Not:$false -ExpectedValue [System.String] -ActualValue 'AnyString' -BeOfType
}

It 'Should convert `Should -BeOfType (Get-Something)` correctly' {
function Get-MyType
{
return ([System.String])
}

'AnyString' | Should -BeOfType (Get-MyType)
}
}

Context 'When the tests are negated' {
It 'Should convert `Should -Not -Be 1` correctly' {
2 | Should -Not -BeOfType [System.String]
}

It 'Should convert `Should -BeOfType [System.String] -Not` correctly' {
2 | Should -BeOfType [System.String] -Not
}

It 'Should convert `Should -Not -BeOfType $anyValue` correctly' {
$anyValue = ([System.String])

2 | Should -Not -BeOfType $anyValue
}
}

Context 'When tests should always use named parameters' {
It 'Should convert `Should -BeOfType [System.String] ''BecauseString'' -ActualValue ''AnyString''` correctly' {
Should -BeOfType [System.String] 'BecauseString' -ActualValue 'AnyString'
}
}

Context 'When alias operator name is used' {
It 'Should convert `Should -HaveType [System.String] -ActualValue ''AnyString''` correctly' {
Should -HaveType [System.String] -ActualValue 'AnyString'
}
}

Context 'When tests should always use positional parameters' {
Context 'When the tests are affirming' {
It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -ActualValue ''AnyString''` correctly' {
Should -BeOfType -ExpectedValue ([System.String]) -ActualValue 'AnyString'
}

It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' {
Should -BeOfType -ExpectedValue ([System.String]) -ActualValue 'AnyString'
}
}

Context 'When the tests are negated' {
It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -Not -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' {
Should -BeOfType -ExpectedValue ([System.String]) -Not -ActualValue 2 -Because 'BecauseString'
}
}
}
}
8 changes: 4 additions & 4 deletions tests/Unit/Private/Convert-ShouldBeOfType.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Describe 'Convert-ShouldBeOfType' {
It 'Should convert `Should -Not:$false -ExpectedValue [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' {
InModuleScope -ScriptBlock {
$mockCommandAstPester5 = {
Should -BeOfType -Not:$false -ExpectedValue [System.String] -ActualValue 'AnyString' -BeOfType
Should -Not:$false -ExpectedValue [System.String] -ActualValue 'AnyString' -BeOfType
}.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false)

$result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5
Expand Down Expand Up @@ -251,7 +251,7 @@ Describe 'Convert-ShouldBeOfType' {
It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -ActualValue ''AnyString''` correctly' {
InModuleScope -ScriptBlock {
$mockCommandAstPester5 = {
Should -HaveType -ExpectedValue ([System.String]) -ActualValue 'AnyString'
Should -BeOfType -ExpectedValue ([System.String]) -ActualValue 'AnyString'
}.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false)

$result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 -UsePositionalParameters
Expand All @@ -263,7 +263,7 @@ Describe 'Convert-ShouldBeOfType' {
It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' {
InModuleScope -ScriptBlock {
$mockCommandAstPester5 = {
Should -HaveType -ExpectedValue ([System.String]) -ActualValue 'AnyString'
Should -BeOfType -ExpectedValue ([System.String]) -ActualValue 'AnyString'
}.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false)

$result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 -UsePositionalParameters
Expand All @@ -277,7 +277,7 @@ Describe 'Convert-ShouldBeOfType' {
It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -Not -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' {
InModuleScope -ScriptBlock {
$mockCommandAstPester5 = {
Should -HaveType -ExpectedValue ([System.String]) -Not -ActualValue 'AnyString' -Because 'BecauseString'
Should -BeOfType -ExpectedValue ([System.String]) -Not -ActualValue 'AnyString' -Because 'BecauseString'
}.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false)

$result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 -UsePositionalParameters
Expand Down

0 comments on commit 76cef4c

Please sign in to comment.