Permalink
Browse files

Initial commit with the basics working

  • Loading branch information...
scottmuc committed Jan 2, 2011
0 parents commit a1d6a0e01f58375175ed090647ab8245a049f1a6
@@ -0,0 +1,27 @@
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$pwd\Add-Numbers.ps1"
. "$pwd\..\..\Source\Pester.ps1"
Describe "Add-Numbers" {
It "adds positive numbers" {
$sum = Add-Numbers 2 3
$sum.should.be(4)
}
It "adds negative numbers" {
$sum = Add-Numbers (-2) (-2)
$sum.should.be((-4))
}
It "adds one negative number to positive number" {
$sum = Add-Numbers (-2) 2
$sum.should.be(0)
}
It "concatenates strings if given strings" {
$sum = Add-Numbers two three
$sum.should.be("twothree")
}
}
@@ -0,0 +1,3 @@
function Add-Numbers($a, $b) {
return $a + $b
}
@@ -0,0 +1,16 @@
Pester
======
Objective
---------
I wanted to make a convention based Powershell Unit testing framework that didn't require the following:
* Installer of any sort
* Changing a users Profile script
The things I wanted it do do is:
* Find all tests by some sort of convention
* Emulate RSpec assertions and fixture setup
* Create NUnit XML reports
@@ -0,0 +1,4 @@
function Describe($name, [ScriptBlock] $fixture) {
Write-Host -fore yellow Describing $name
& $fixture
}
@@ -0,0 +1,13 @@
function It($name, [ScriptBlock] $test)
{
Write-Host -fore DarkCyan $name -NoNewLine
$test_result = & $test
if ($test_result) {
Write-Host -ForegroundColor green " Success"
} else {
Write-Host -ForegroundColor red " Failure`n$($test.ToString())"
}
}
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.Object</Name>
<Members>
<ScriptProperty>
<Name>should</Name>
<GetScriptBlock>
$value = $this
$object = New-Object Object |
Add-Member ScriptMethod be {
param($expected)
return ($expected -eq $this.actual)
} -PassThru |
Add-Member NoteProperty -Name actual -Value $null -PassThru |
Add-Member ScriptProperty -Name ThisValue -Value { $this.actual } `
{
param($newactual)
$this.actual = $newactual
} -PassThru
$object.ThisValue = $value
return $object
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
@@ -0,0 +1,12 @@
param($relative_path = ".")
$script_dir = Split-Path -Parent $MyInvocation.MyCommand.Path
Update-TypeData -pre "$script_dir\ObjectAdaptations\types.ps1xml" -ErrorAction SilentlyContinue
$fixtures_path = Resolve-Path $relative_path
Write-Host Executing all tests in $fixtures_path
Get-ChildItem $fixtures_path -Recurse |
? { $_.Name -match ".Tests." } |
% { & $_.PSPath }
@@ -0,0 +1,4 @@
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path
Resolve-Path $pwd\Functions\*.ps1 | % { . $_.ProviderPath }

0 comments on commit a1d6a0e

Please sign in to comment.