Skip to content

Commit

Permalink
Updated New-Fixture template (pester#1775)
Browse files Browse the repository at this point in the history
* Updated New-Fixture template

* Update testname
  • Loading branch information
fflaten authored Nov 15, 2020
1 parent abfedec commit d3e8e14
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/functions/New-Fixture.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function New-Fixture {
#>

param (
[String]$Path = $PWD,
[Parameter(Mandatory = $true)]
[String]$Name
[String]$Name,
[String]$Path = $PWD
)

$Name = $Name -replace '.ps(m?)1', ''
Expand All @@ -86,8 +86,7 @@ function New-Fixture {

#keep this formatted as is. the format is output to the file as is, including indentation
$scriptCode = "function $Name {
#Do something
`$true
throw [NotImplementedException]'$Name is not implemented.'
}"

$testCode = 'BeforeAll {
Expand All @@ -96,7 +95,7 @@ function New-Fixture {
Describe "#name#" {
It "Returns expected output" {
#name# | Should -Be $true
#name# | Should -Be "YOUR_EXPECTED_VALUE"
}
}' -replace "#name#", $Name

Expand Down
4 changes: 2 additions & 2 deletions tst/functions/New-Fixture.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Set-StrictMode -Version Latest

Describe "New-Fixture" {
It "Name parameter is mandatory" {
(Get-Command New-Fixture ).Parameters.Name.ParameterSets.__AllParameterSets.IsMandatory | Should -Be $true
(Get-Command New-Fixture).Parameters.Name.ParameterSets.__AllParameterSets.IsMandatory | Should -Be $true
}

Context "Only Name parameter is specified" {
Expand Down Expand Up @@ -115,7 +115,7 @@ Describe "New-Fixture" {
$name = "Test Fixture"
$path = "TestDrive:\"

{ New-Fixture -Path $path -Name $name } | Should -Throw -Because "whitespace is not allowed in fixture name"
{ New-Fixture -Name $name -Path $path } | Should -Throw -Because "whitespace is not allowed in fixture name"
}
}
}
7 changes: 4 additions & 3 deletions tst/functions/New-Fixture.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Import-Module $PSScriptRoot\..\..\bin\Pester.psd1

$global:PesterPreference = @{
Debug = @{
ShowFullErrors = $true
ShowFullErrors = $false
}
}

i -PassThru:$PassThru {
b "New-Fixture" {
t "Generated fixture works" {
t "Generated fixture fails as expected" {
$tempFolder = [IO.Path]::GetTempPath()
$name = "Fixture$([Guid]::NewGuid().Guid)"

Expand All @@ -26,7 +26,8 @@ i -PassThru:$PassThru {
New-Fixture -Path $tempFolder -Name $name

$r = Invoke-Pester -Path $testsPath -PassThru
$r.Containers[0].Blocks[0].Tests[0].Result | Verify-Equal "Passed"
$r.Containers[0].Blocks[0].Tests[0].Result | Verify-Equal "Failed"
$r.Containers[0].Blocks[0].Tests[0].ErrorRecord.Exception | Verify-Type ([System.NotImplementedException])
}
finally {
if (Test-Path $scriptPath) {
Expand Down

0 comments on commit d3e8e14

Please sign in to comment.