Created
August 4, 2010 19:49
-
-
Save JeremySkinner/508684 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| before_each { | |
| write-host "I will be written before each test is run" | |
| } | |
| when "True is true" { | |
| assert { $true -eq $true } | |
| } | |
| when "True is false, the world may explode" { | |
| assert { $true -eq $false } "True should be false" | |
| } |
This file contains hidden or 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
| # Usage: PsSpec.ps1 path/to/specs.ps1 | |
| param( | |
| $specfile = $(throw "specfile required") | |
| ) | |
| $script:specs = @() | |
| $script:beforeeaches = @() | |
| function assert([scriptblock]$assertion, $message = "") { | |
| $result = & $assertion | |
| if(-not $result) { | |
| throw $message | |
| } | |
| } | |
| function before_each([scriptblock]$block) { | |
| $script:beforeeaches += $block | |
| } | |
| function when($condition, [scriptblock]$spec) { | |
| $specMeta = @{ | |
| "name" = $condition; | |
| "spec" = $spec; | |
| } | |
| $script:specs += $specMeta | |
| } | |
| . (resolve-path $specfile) | |
| $specs | % { | |
| $beforeeaches | % { & $_ } | |
| $meta = $_ | |
| try { | |
| & $_.spec | |
| write-host $meta.name -foregroundcolor green | |
| } catch { | |
| write-host $meta.name -foregroundcolor red | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment