Skip to content

Instantly share code, notes, and snippets.

@BrainCrumbz
Last active December 28, 2015 19:56
Show Gist options
  • Save BrainCrumbz/5fde579cee880eeb9822 to your computer and use it in GitHub Desktop.
Save BrainCrumbz/5fde579cee880eeb9822 to your computer and use it in GitHub Desktop.
Changes to NSpec docs to show execution order
using NSpec;
using System;
namespace NSpecExecutionOrder
{
abstract class parent_class : nspec // this can be either an abstract class, or just a class
{
public const string parentPrefix = "parent: ";
public const string childPrefix = "\t\t child: ";
public const string methodPrefix = "\t\t\t\t method: ";
public const string subPrefix = "\t\t\t\t\t\t sub: ";
public static string order = "\n\n";
void Print(string s)
{
Console.WriteLine(s);
}
void before_all()
{
order += parentPrefix + "before all \n";
}
void before_each()
{
order += parentPrefix + "before each \n";
}
void it_works_parent_1()
{
order += parentPrefix + "it works 1 \n";
}
void it_works_parent_2()
{
order += parentPrefix + "it works 2 \n";
}
void after_each()
{
order += parentPrefix + "after each \n.\n";
}
void after_all()
{
order += parentPrefix + "after all \n";
Print(order);
}
}
class child_class : parent_class
{
void before_all()
{
order += childPrefix + "before all \n";
}
void before_each()
{
order += childPrefix + "before each \n";
}
void it_works_child_3()
{
order += childPrefix + "it works 3 \n";
}
void it_works_child_4()
{
order += childPrefix + "it works 4 \n";
}
void after_each()
{
order += childPrefix + "after each \n";
}
void after_all()
{
order += childPrefix + "after all \n";
}
void method_level_context()
{
beforeAll = () => order += methodPrefix + "before all \n";
before = () => order += methodPrefix + "before each \n";
it["it works method 5"] = () => order += methodPrefix + "it works 5 \n";
it["it works method 6"] = () => order += methodPrefix + "it works 6 \n";
after = () => order += methodPrefix + "after each \n";
afterAll = () => order += methodPrefix + "after all \n";
context["sub context"] = () =>
{
beforeAll = () => order += subPrefix + "before all \n";
before = () => order += subPrefix + "before each \n";
it["it works sub 7"] = () => order += subPrefix + "it works 7 \n";
it["it works sub 8"] = () => order += subPrefix + "it works 8 \n";
after = () => order += subPrefix + "after each \n";
afterAll = () => order += subPrefix + "after all \n";
};
}
}
}
parent: before all
child: before all
parent: before each
child: before each
parent: it works 1
child: after each
parent: after each
.
parent: before each
child: before each
parent: it works 2
child: after each
parent: after each
.
parent: before each
child: before each
child: it works 3
child: after each
parent: after each
.
parent: before each
child: before each
child: it works 4
child: after each
parent: after each
.
method: before all
parent: before each
child: before each
method: before each
method: it works 5
method: after each
child: after each
parent: after each
.
parent: before each
child: before each
method: before each
method: it works 6
method: after each
child: after each
parent: after each
.
sub: before all
parent: before each
child: before each
method: before each
sub: before each
sub: it works 7
sub: after each
method: after each
child: after each
parent: after each
.
parent: before each
child: before each
method: before each
sub: before each
sub: it works 8
sub: after each
method: after each
child: after each
parent: after each
.
sub: after all
method: after all
child: after all
parent: after all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment