-
Notifications
You must be signed in to change notification settings - Fork 0
Home
michael-erasmus edited this page Aug 16, 2010
·
5 revisions
Welcome to the specr wiki!
Here is some quick examples of what you can do with specr.
Let’s say you have a class that you want to write some specifications for(Not really behavior-driven, I know, but bear with me, it’s only for illustration purposes):
public enum Gender {Male; Female;}
public class Person
{
public string Name{get;set;}
public bool IsOrphan{get;set;}
public Person Father{get;set;}
public Person Mother{get;set;}
public Gender Sex{get;set;}
public List<Person> Children{get;private set};
public Person HaveAChild(string name)
{
if(Children == null)
Children = new List<Person>();
var child = new Person{Name = name};
Children.Add(child);
return child;
}
}
Now lets write some specs:
[TestClass]
public class DescribePerson
{
private Person person;
[TestInitialize]
public void Before()
{
person = new Person(){ IsOrphan =true, Sex = Gender.Male};
}
[TestMethod]
public void He_Should_Be_A_Nameless_Orphan()
{
person.Should().NotHaveA().Name();
person.Should().BeAn().Orphan();
}
[TestMethod]
public He_Should_Be_Able_To_Have_Children()
{
Person.Should().HaveNo().Children();
var child = person.HaveAChild("Johnny");
child.Should().HaveA().Father();
person.Should().Have(1).Children();
}
}