我正在使用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!”。当我调试代码时,它只调用前面的最后一个。也许我不理解这个理论,但我相信所有的lambdas都在'act‘和'it’之前运行。出什么问题了?
发布于 2014-09-07 07:14:17
我使用下面的语法和工作(方法之前是外部的,上下文中是内部的):
void they_are_loud_and_emphatic()
{
act = () => sound = sound.ToUpper() + "!!!";
context["given bam"] = () =>
{
before = () =>
{
sound = "b";
sound += "a";
sound += "m";
};
it["should be BAM!!!"] = () => sound.should_be("BAM!!!");
};
}
string sound;发布于 2015-11-18 15:46:40
即使在前面的例子中它是递增的,但是对于每个规范再次运行之前的操作将会停止。
void they_are_loud_and_emphatic(){
act = () => sound = sound.ToUpper() + "!!!";
context["given bam"] = () =>
{
before = () => sound = "b"; //now sound is B!!!
before = () => sound += "a"; //now sound is A!!!
before = () => sound += "m"; //now sound is M!!!
it["should be BAM!!!"] =
() => sound.should_be("BAM!!!"); // when this line is runing ,sound is"M!!!"
};
}
string sound;https://stackoverflow.com/questions/25703731
复制相似问题