我正在玩NSpec,我对前面的例子感到困惑:
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;
它有效,但是当我进行下一个更改时:
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;
弦音只有“M!!!”。当我调试代码时,它只调用最后一个。也许我不理解这个理论,但我相信所有之前的 lambda 表达式都在“行为”和“它”之前运行。有什么问题?