-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update rspec.ps1 to copy test case from RSPEC
- Loading branch information
1 parent
98c1d02
commit 38860e1
Showing
3 changed files
with
112 additions
and
0 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,42 @@ | ||
# For each test case file in the RspecRulePath, copy the file to the OutputFolder with the name $FileName + $Scenario + $Extension | ||
# | ||
# The scenario is determined by the following rules: | ||
# 1. The test case file name contains a dot, e.g. "MyTestCase.Scenario.razor" | ||
# Then the scenario name is the second part of the file name, e.g. "Scenario" | ||
# 2. The test case file name contain a dot, but the test case file is in a subfolder, e.g. "MyTestCase\MyTestCase.Scenario.razor" | ||
# Then the scenario name is the second part of the file name, e.g. "Scenario", ignoring the folder name | ||
# 3. The test case file name does not contain a dot, but the test case file is in a subfolder, e.g. "MyTestCase\Scenario.razor" | ||
# Then the scenario name is the file name, e.g. "Scenario", ignoring the folder name | ||
# 4. The test case file name does not contain a dot and the test case file is in the root folder, e.g. "MyTestCase.razor" | ||
# Then the scenario name is empty, e.g. "" | ||
# | ||
# Example: | ||
# 1. MyTestCase.Scenario.razor => RuleName.Scenario.razor | ||
# 2. MyTestCase\MyTestCase.Scenario.razor => RuleName.Scenario.razor | ||
# 3. MyTestCase\Scenario.razor => RuleName.Scenario.razor | ||
# 4. MyTestCase.razor => RuleName.razor | ||
# | ||
function CopyTestCasesFromRspec($FileName, $RspecRulePath, $OutputFolder) { | ||
$TestCaseFileExtension = @( | ||
"*.cs", | ||
"*.vb", | ||
"*.razor", | ||
"*.cshtml" | ||
) | ||
|
||
Get-ChildItem -Recurse -Path $RspecRulePath -Include $TestCaseFileExtension -File | ForEach-Object { | ||
|
||
$scenario = ""; | ||
|
||
if ($_.BaseName.Contains(".")) | ||
{ | ||
$scenario = "." + $($_.BaseName -Split "\." | Select-Object -Last 1) | ||
} | ||
elseif ($_.Directory.FullName -ne $(Convert-Path $RspecRulePath)) | ||
{ | ||
$scenario = "." + $_.BaseName | ||
} | ||
|
||
Set-Content -NoNewline -Path "${OutputFolder}\\$FileName$scenario$($_.Extension)" -Value $(Get-Content $_ -Raw) -Encoding UTF8 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# How to run: | ||
# $ Invoke-Pester -Output Detailed | ||
# | ||
# Requires Pester 5.0.x | ||
# https://pester.dev/docs/quick-start | ||
# $ Install-Module -Name Pester -Force -SkipPublisherCheck | ||
# $ Import-Module Pester -Passthru | ||
BeforeAll { | ||
. $PSScriptRoot/../CopyTestCasesFromRspec.ps1 | ||
|
||
$InputFolder = "TestDrive:\input" | ||
$OutputFolder = "TestDrive:\output" | ||
} | ||
|
||
$FileExtension = @(".cs", ".vb", ".razor", ".cshtml") | ||
|
||
Describe 'CopyTestCasesFromRspec - <_> files' -ForEach $FileExtension { | ||
BeforeEach { | ||
if (Test-Path $InputFolder) | ||
{ | ||
Remove-Item -Force -Recurse $InputFolder | ||
} | ||
if (Test-Path $OutputFolder) | ||
{ | ||
Remove-Item -Force -Recurse $OutputFolder | ||
} | ||
|
||
New-Item -Path "TestDrive:\" -Name "input" -ItemType "directory" | ||
New-Item -Path "TestDrive:\" -Name "output" -ItemType "directory" | ||
} | ||
|
||
|
||
It 'should copy <_> file' { | ||
New-Item -Path $InputFolder -Name "SomeTestCase$_" -ItemType "file" | ||
|
||
CopyTestCasesFromRspec "RuleName" $InputFolder $OutputFolder | ||
|
||
Get-ChildItem -Path $OutputFolder -File -name | Should -Contain "RuleName$_" | ||
"$OutputFolder\RuleName$_" | Should -Exist | ||
} | ||
|
||
It 'should take into account composed test case name' { | ||
New-Item -Path $InputFolder -Name "SomeTestCase.Scenario1$_" -ItemType "file" | ||
|
||
CopyTestCasesFromRspec "RuleName" $InputFolder $OutputFolder | ||
|
||
Get-ChildItem -Path $OutputFolder -File -name | Should -Contain "RuleName.Scenario1$_" | ||
"$OutputFolder\RuleName.Scenario1$_" | Should -Exist | ||
} | ||
|
||
It 'should include file if under a folder with filename used as a scenario' { | ||
New-Item -Path $InputFolder -Name "AFolder" -ItemType "directory" | ||
New-Item -Path "TestDrive:\input\AFolder" -Name "Scenario1$_" -ItemType "file" | ||
|
||
CopyTestCasesFromRspec "RuleName" $InputFolder $OutputFolder | ||
|
||
Get-ChildItem -Path $OutputFolder -File -name | Should -Contain "RuleName.Scenario1$_" | ||
"$OutputFolder\RuleName.Scenario1$_" | Should -Exist | ||
} | ||
} |