Skip to content

Instantly share code, notes, and snippets.

@raghur
Created August 4, 2016 19:58
Show Gist options
  • Select an option

  • Save raghur/a6c03ea5977475d68570d234dd4d783e to your computer and use it in GitHub Desktop.

Select an option

Save raghur/a6c03ea5977475d68570d234dd4d783e to your computer and use it in GitHub Desktop.
Nspec sample used for PR# 132 on NSpec
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NSpec;
namespace NspecSample
{
public class A_Sample_Spec :nspec
{
public void describe_a_behavior()
{
it["should do something"] = () =>
{
Console.WriteLine("some text");
5.should_be(5);
};
it["should do something else"] = () =>
{
Console.WriteLine("some else");
5.should_be(5);
Console.Write("a little bit more text");
};
it["a failing spec"] = () =>
{
Console.WriteLine("some text before");
5.should_be(6);
Console.Write("a little text after");
};
it["a failing spec"] = () =>
{
Console.WriteLine("has some text before");
throw new Exception("something exceptional");
};
it["handles multiline text output"] = () =>
{
try
{
foo();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
};
it["handles stderr as well"] = () =>
{
Console.WriteLine("a little text before");
Console.Error.WriteLine("some error");
Console.WriteLine("after");
};
}
void describe_examples_without_output()
{
it["should not be affected"] = () => { };
xit["could be a pending spec"] = () => { };
}
private void foo()
{
bar();
}
private void bar()
{
throw new NullReferenceException("null!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment