Fix Pester tests

These fail with the improved console because $input is already defined.
This commit is contained in:
Andrew Schwartzmeyer 2015-11-04 15:13:21 -08:00
parent f411d056c2
commit db338c2b9a
4 changed files with 32 additions and 32 deletions

View file

@ -1,34 +1,34 @@
Describe "Format-List" {
BeforeEach {
$input = New-Object PSObject
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
}
It "Should call format list without error" {
{ $input | Format-List } | Should Not Throw
{ $input | Format-List } | Should Not BeNullOrEmpty
{ $in | Format-List } | Should Not Throw
{ $in | Format-List } | Should Not BeNullOrEmpty
}
It "Should be able to call the alias" {
{ $input | fl } | Should Not Throw
{ $input | fl } | Should Not BeNullOrEmpty
{ $in | fl } | Should Not Throw
{ $in | fl } | Should Not BeNullOrEmpty
}
It "Should have the same output whether choosing alias or not" {
$expected = $input | Format-List | Out-String
$actual = $input | fl | Out-String
$expected = $in | Format-List | Out-String
$actual = $in | fl | Out-String
$actual | Should Be $expected
}
It "Should produce the expected output" {
$expected = "`n`ntestName : testValue`n`n`n`n"
$input = New-Object PSObject
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
$input | Format-List | Should Not BeNullOrEmpty
$input | Format-List | Out-String | Should Not BeNullOrEmpty
$input | Format-List | Out-String | Should Be $expected
$in | Format-List | Should Not BeNullOrEmpty
$in | Format-List | Out-String | Should Not BeNullOrEmpty
$in | Format-List | Out-String | Should Be $expected
}
It "Should be able to call a property of the piped input" {
@ -64,7 +64,7 @@ Describe "Format-List" {
}
It "Should be able to take input without piping objects to it" {
$output = { Format-List -InputObject $input }
$output = { Format-List -InputObject $in }
$output | Should Not Throw
$output | Should Not BeNullOrEmpty

View file

@ -49,18 +49,18 @@
}
It "Should be able to set the value of a variable by piped input" {
$input = "value"
$in = "value"
$input | New-Variable -Name var1
$in | New-Variable -Name var1
$var1 | Should Be $input
$var1 | Should Be $in
}
It "Should be able to pipe object properties to output using the PassThru switch" {
$input = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$output = $input | Format-List -Property Description | Out-String
$output = $in | Format-List -Property Description | Out-String
$output | Should Be "`n`nDescription : test description`n`n`n`n"
}

View file

@ -1,6 +1,6 @@
Describe "Out-File" {
$expectedContent = "some test text"
$inputObject = New-Object psobject -Property @{text=$expectedContent}
$inObject = New-Object psobject -Property @{text=$expectedContent}
$testfile = "/tmp/outfileTest.txt"
AfterEach {
@ -28,17 +28,17 @@
}
It "Should be able to accept object input" {
{ $inputObject | Out-File -FilePath $testfile } | Should Not Throw
{ $inObject | Out-File -FilePath $testfile } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
}
It "Should not overwrite when the noclobber switch is used" {
Out-File -FilePath $testfile -InputObject $inputObject
Out-File -FilePath $testfile -InputObject $inObject
{ Out-File -FilePath $testfile -InputObject $inputObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists."
{ Out-File -FilePath $testfile -InputObject $inputObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists."
{ Out-File -FilePath $testfile -InputObject $inObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists."
{ Out-File -FilePath $testfile -InputObject $inObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists."
$actual = Get-Content $testfile
@ -49,8 +49,8 @@
}
It "Should Append a new line when the append switch is used" {
{ Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inputObject -Append } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject -Append } | Should Not Throw
$actual = Get-Content $testfile
@ -71,7 +71,7 @@
It "Should limit each line to the specified number of characters when the width switch is used on objects" {
Out-File -FilePath $testfile -Width 10 -InputObject $inputObject
Out-File -FilePath $testfile -Width 10 -InputObject $inObject
$actual = Get-Content $testfile
@ -84,11 +84,11 @@
It "Should allow the cmdlet to overwrite an existing read-only file" {
# create a read-only text file
{ Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true
# write information to the RO file
{ Out-File -FilePath $testfile -InputObject $inputObject -Append -Force } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject -Append -Force } | Should Not Throw
$actual = Get-Content $testfile

View file

@ -48,9 +48,9 @@
}
It "Should be able to pipe object properties to output using the PassThru switch" {
$input = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$output = $input | Format-List -Property Description | Out-String
$output = $in | Format-List -Property Description | Out-String
# This will cause errors running these tests in windows
$output | Should Be "`n`nDescription : test description`n`n`n`n"