Created
September 14, 2012 09:01
-
-
Save bartelink/3720893 to your computer and use it in GitHub Desktop.
Row test in NSpec
This file contains 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
/* | |
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