Public/Remove-PsModule.Tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' . "$here\$sut" . "$here\New-PsModule.ps1" . "$here\Set-PsModuleBuilderPath.ps1" . "$here\Get-PsModuleBuilderPath.ps1" function Format-TheTest { param([string]$testPath) Write-Host "Formatting the test with: $testPath" New-Item -Path $testPath -ItemType Directory -Force | Out-Null Set-PsModuleBuilderPath $testPath } function Get-ExpectedFilesAndDirs { param( [string]$path, [string]$moduleName ) return @{ files = @( "$path\$moduleName\Data\plasterManifest.xml", "$path\$moduleName\$moduleName.psd1", "$path\$moduleName\$moduleName.psm1", "$path\$moduleName\readme.md" ) directories = @( "$path\$moduleName", "$path\$moduleName\Data", "$path\$moduleName\Internal", "$path\$moduleName\Public", "$path\$moduleName\Tests" ) } } Describe Remove-PsModule { Context "When only name is provided..." { $testModule = "TestModule" $testPath = "TestDrive:\Modules" Format-TheTest $testPath New-PsModule $testModule Remove-PsModule $testModule $expected = Get-ExpectedFilesAndDirs $testPath $testModule $expected.files | ForEach-Object { It "Should remove file $_" { Test-Path $_ -PathType Leaf | Should -Be $false } } $expected.directories | ForEach-Object { It "Should remove directory $_" { Test-Path $_ -PathType Container | Should -Be $false } } } Context "When name and path are provided..." { $testModule = "TestModule" $testPath = "TestDrive:\Other-Modules" Format-TheTest $testPath New-PsModule $testModule $testPath Remove-PsModule $testModule $testPath $expected = Get-ExpectedFilesAndDirs $env:PsModuleBuilderPath $testModule $expected.directories | ForEach-Object { It "Should remove directory $_" { Test-Path $_ -PathType Container | Should -Be $false } } $expected.files | ForEach-Object { It "Should remove file $_" { Test-Path $_ -PathType Leaf | Should -Be $false } } } } |