Ok. I'm trying to wrap my head around why MSpec uses static methods / variables. (Well not exactly static methods, but with member variable delegates, it's practically the same).
This makes it impossible to reuse contexts. That or go through and make sure all static variables are reset manually. This has no enforcement on test isolation. If one test sets up some variables and the next one checks for it, it'd pass when it shouldn't.
This is starting to get very annoying. What I do in one "because" statement should just stay there, not get carried through to every other random test just because it's sharing the same context.
Edit-
The question is, how do I "ENFORCE" test isolation. For example, look at the specs below, sharing the FooContext
. Let's take a wild guess if should_not_throw
passes?
public class FooContext
{
Establish context = () => Subject = new Foo();
public static Foo Subject;
public static int result;
public static Exception ex;
}
public class When_getting_an_int_incorrectly : FooContext
{
Because of = () => ex = Exception.Catch(() => result = Subject.GetInt(null));
It should_throw = () => ex.ShouldNotBeNull();
}
public class When_getting_an_int_correctly : FooContext
{
Because of = () => ex = Exception.Catch(() => result = Subject.GetInt(0));
It should_not_throw = () => ex.ShouldBeNull();
}