Closed mikeblakeuk closed 2 years ago
Readability and consistency, mostly. It's up to you how you organize your tests, though I'd suggest keeping each context/spec as self-contained as possible. The lambda notation (option 2) is more consistent with all your Because
and It
elements which also use the lambda notation.
I agree, we should turn off the R# recommendation
It was more around the pros and cons of the actual IL. e.g.
public class MachineSpec
{
static string _source;
static void SharedSetup()
{
_source = "a";
}
static void ShouldEqual()
{
_source.ShouldEqual("a");
}
public class when_method_group
{
Establish ctx = SharedSetup;
It should_parse_the_environment = ShouldEqual;
}
public class when_method_lambda
{
Establish ctx = () => SharedSetup();
It should_parse_the_environment = () => ShouldEqual();
}
public class when_delegate
{
Establish ctx = delegate() { SharedSetup(); };
It should_parse_the_environment = delegate() { ShouldEqual(); };
}
}
Becomes:
public class MachineSpec
{
private static string _source;
private static void SharedSetup() => MachineSpec._source = "a";
private static void ShouldEqual() => MachineSpec._source.ShouldEqual<string>("a");
public class when_method_group
{
private Establish ctx = new Establish(MachineSpec.SharedSetup);
private It should_parse_the_environment = new It(MachineSpec.ShouldEqual);
}
public class when_method_lambda
{
private Establish ctx = (Establish) (() => MachineSpec.SharedSetup());
private It should_parse_the_environment = (It) (() => MachineSpec.ShouldEqual());
}
public class when_delegate
{
private Establish ctx = (Establish) (() => MachineSpec.SharedSetup());
private It should_parse_the_environment = (It) (() => MachineSpec.ShouldEqual());
}
}
In MSpec, does it make a difference if you do
Establish context = Things
vsEstablish context = () => Things() ?
[ReSharper suggestion]