Ok I am trying to wrap my head around why MSpec uses static methods / variables. (Well, not exactly static methods, but with delegates of member variables, it's pretty much the same).
This makes reuse of contexts impossible. Either go through this and make sure that all static variables are reset manually. This does not require forced isolation. If one test sets some variables, and the next tests it, it will pass when it is not.
It starts to get very annoying. What I do in one βbecauseβ should just stay there, and not be carried over to all other random tests just because they use the same context.
Edit -
The question is how to isolate the ENFORCE test insulation. For example, view the specs below, dividing FooContext . Let's take a wild guess if should_not_throw pass?
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(); }
source share