I'm playing with NSpec and I'm confused with the before example:
void they_are_loud_and_emphatic()
{
//act runs after all the befores, and before each spec
//declares a common act (arrange, act, assert) for all subcontexts
act = () => sound = sound.ToUpper() + "!!!";
context["given bam"] = () =>
{
before = () => sound = "bam";
it["should be BAM!!!"] =
() => sound.should_be("BAM!!!");
};
}
string sound;
It works, but when I make the next change:
void they_are_loud_and_emphatic()
{
//act runs after all the befores, and before each spec
//declares a common act (arrange, act, assert) for all subcontexts
act = () => sound = sound.ToUpper() + "!!!";
context["given bam"] = () =>
{
before = () => sound = "b";
before = () => sound += "a";
before = () => sound += "m";
it["should be BAM!!!"] =
() => sound.should_be("BAM!!!");
};
}
string sound;
the string sound only has "M!!!". When I debug the code, it only calls the last before. Perhaps I don't understand the theory, but I believed that all befores lambdas run 'before' the 'act' and the 'it'. What is it wrong?