Skip to content

Instantly share code, notes, and snippets.

@bartelink
Created September 14, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartelink/3720893 to your computer and use it in GitHub Desktop.
Save bartelink/3720893 to your computer and use it in GitHub Desktop.
Row test in NSpec
/*
output of the row test below
describe AClass
describe many variations
A should equal A
C should equal A - [Failed]
*/
//top level context to describe class
class describe_AClass
{
//nested context need so that row test can be done
//a method body is required to do a row test
void describe_many_variations()
{
//create any anonymous type on the fly
//which will represent your row test data
new[]
{
new { actual = "A", expected = "A" },
new { actual = "C", expected = "A" }
}.Do(rowTest => //enumerate the row test using NSpec's "Do" extension method
{
//print out the description using NSpec's "With" method (pretty much a wrapper for string.Format)
it["{0} should equal {1}".With(rowTest.actual, rowTest.expected)] =>
rowTest.expected.should_be(rowTest.actual); //assert on what you need to assert on
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment