Skip to content

Instantly share code, notes, and snippets.

@gavincampbell
Created February 28, 2017 11:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gavincampbell/05c803654ff70d21d538b49f0e363a6a to your computer and use it in GitHub Desktop.
Save gavincampbell/05c803654ff70d21d538b49f0e363a6a to your computer and use it in GitHub Desktop.
Powershell script to download and extract the latest version of [Pester](https://github.com/pester/Pester)
$latestRelease = Invoke-WebRequest https://github.com/pester/Pester/releases/latest -Headers @{"Accept"="application/json"}
$json = $latestRelease.Content | ConvertFrom-Json
$latestVersion = $json.tag_name
$url = "https://github.com/pester/Pester/archive/$latestVersion.zip"
$download_path = "$env:USERPROFILE\Downloads\pester-master.zip"
Invoke-WebRequest -Uri $url -OutFile $download_path
Get-Item $download_path | Unblock-File
$user_module_path = $env:PSModulePath -split ";" -match $env:USERNAME -notmatch "vscode"
if (-not (Test-Path -Path $user_module_path))
{
New-Item -Path $user_module_path -ItemType Container | Out-Null
}
Expand-Archive -Path $download_path -DestinationPath $user_module_path[0] -Force
Import-Module Pester
$test_name = "Verify-Pester-" + (Get-Random)
New-Fixture -Path $PSScriptRoot\$test_name -name $test_name
(Get-Content $PSScriptRoot\$test_name\$test_name.Tests.ps1 ) | % {$_ -replace '\$true \| Should Be \$false', "$test_name | Should Be 'Hello From Pester!'" } | Set-Content $PSScriptRoot\$test_name\$test_name.Tests.ps1
"function $test_name {'Hello From Pester!'}" | Set-Content $PSScriptRoot\$test_name\$test_name.ps1 -Force
Invoke-Pester $test_name
if (Test-Path $PSScriptRoot\$test_name)
{
Remove-Item -Path $PSScriptRoot\$test_name -Force -Recurse -Verbose
}
# https://blog.markvincze.com/download-artifacts-from-a-latest-github-release-in-sh-and-powershell/
# http://www.powershellmagazine.com/2014/03/12/get-started-with-pester-powershell-unit-testing-framework/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment