protected when_running_specs Run(params Type[] types) { //if (types.Count() == 1) tags = types.First().Name; this.types = types; builder = new ContextBuilder(new SpecFinder(types), new Tags().Parse(tags), new DefaultConventions()); runner = new ContextRunner(builder, formatter, failFast); contextCollection = builder.Contexts(); contextCollection.Build(); classContext = contextCollection .AllContexts() .Where(c => c is ClassContext) .Cast<ClassContext>() .FirstOrDefault(c => types.Contains(c.type)); methodContext = contextCollection.AllContexts().FirstOrDefault(c => c is MethodContext); runner.Run(contextCollection); return this; }
protected void Run(Type type) { classContext = new ClassContext(type); var method = type.Methods().First().Name; Run(type, method); }
public void setup() { context = typeof(child_before).RootContext(); instance = new child_before(); context.Contexts.First().SetInstanceContext(instance); }
NSpecContextTest CreateGallioTestFrom(Context nspecContext) { NSpecContextTest contextTest = new NSpecContextTest(nspecContext); nspecContext.Examples.Do(e => contextTest.AddChild(this.CreateGallioTestFrom(e))); nspecContext.Contexts.Do(c => contextTest.AddChild(this.CreateGallioTestFrom(c))); return contextTest; }
public void BuildMethodContexts(Context classContext, Type specClass) { specClass.Methods().Where(s => !reservedMethods.Contains(s.Name)).Do( contextMethod => { var methodContext = new MethodContext(contextMethod); classContext.AddContext(methodContext); }); }
public void should_concatenate_its_contexts_name_into_a_full_name() { var context = new Context("context name"); var example = new Example("example name"); context.AddExample(example); example.FullName().should_be("context name. example name."); }
public void BuildMethodLevelExamples(Context classContext, Type specClass) { specClass .Methods() .Where(s => conventions.IsMethodLevelExample(s.Name)).Do( methodInfo => { classContext.AddExample(new Example(methodInfo)); }); }
public void BuildMethodContexts(Context classContext, Type specClass) { specClass .Methods() .Where(s => conventions.IsMethodLevelContext(s.Name)).Do( contextMethod => { classContext.AddContext(new MethodContext(contextMethod)); }); }
public void AddContext(Context child) { child.Level = Level + 1; child.Parent = this; child.Tags.AddRange(child.Parent.Tags); Contexts.Add(child); }
public void should_be_marked_as_pending_if_parent_context_is_pending() { var context = new Context("pending context", null, isPending: true); var example = new Example("example name"); context.AddExample(example); example.Pending.should_be_true(); }
public void setup() { var finder = MockRepository.GenerateMock<ISpecFinder>(); var builder = new ContextBuilder(finder); classContext = new Context("class"); builder.BuildMethodContexts(classContext, typeof(SpecClass)); }
protected void Run(Type type, string methodName) { classContext = new ClassContext(type); var method = type.Methods().Single(s => s.Name == methodName); methodContext = new MethodContext(method); classContext.AddContext(methodContext); classContext.Run(); }
public void BuildMethodContexts(Context classContext, Type specClass) { specClass .Methods() .Where(s => conventions.IsMethodLevelContext(s.Name)) .Do(contextMethod => { var methodContext = new MethodContext(contextMethod, TagStringFor(contextMethod)); classContext.AddContext(methodContext); }); }
public void should_be_marked_as_pending_if_any_parent_context_is_pending() { var parentContext = new Context("parent pending context", 0, isPending: true); var context = new Context("not pending"); var example = new Example("example name"); parentContext.AddContext(context); context.AddExample(example); example.Pending.should_be_true(); }
public void BuildMethodLevelExamples(Context classContext, Type specClass) { specClass .Methods() .Where(s => conventions.IsMethodLevelExample(s.Name)) .Do(methodInfo => { var methodExample = new MethodExample(methodInfo, TagStringFor(methodInfo)); classContext.AddExample(methodExample); }); }
public void given_nested_contexts_and_the_child_has_a_failure() { var child = new Context("child"); child.AddExample(new Example("") {Exception = new Exception()}); var parent = new Context("parent"); parent.AddContext(child); parent.Failures().Count().should_be(1); }
private void Build(Context parent, IEnumerable<Type> allSpecClasses) { var derivedTypes = allSpecClasses.Where(s => parent.IsSub( s.BaseType) ); foreach (var derived in derivedTypes) { var classContext = CreateClassContext(derived, conventions); parent.AddContext(classContext); Build(classContext, allSpecClasses); } }
public static void GenerateUniqueExampleName(Context context, ref string output, string spec=null) { output += "-" + context.Name; if (context.Parent != null) GenerateUniqueExampleName(context.Parent, ref output, spec); else { if(!string.IsNullOrWhiteSpace(spec)) output = spec + output; output = output.Replace(" ", "").Trim(new char[] { '-' }); } }
public static Context RootContext(this Type type, Context childContext=null) { if (type.BaseType == typeof(nspec)) { var context = new ClassContext( type ); if(childContext!=null) context.AddContext(childContext); return context; } return RootContext(type.BaseType, new ClassContext(type)); }
public void setup() { reflector = MockRepository.GenerateMock<IReflector>(); RhinoMocksExtensions.Stub(reflector, r => r.GetTypesFrom("")).IgnoreArguments().Return(new[] { typeof(SpecClass) }); var contextBuilder = new ContextBuilder(new SpecFinder("", reflector), new DefaultConventions()); classContext = contextBuilder.Contexts().First(); classContext.Build(); classContext.Run(new SilentLiveFormatter(), failFast: false); }
public void setup() { contexts = new ContextCollection(); var context = new Context(); context.AddExample(new Example()); context.AddExample(new Example(pending:true)); context.AddExample(new Example{Exception = new Exception()}); contexts.Add(context); }
public void should_prepend_successive_subcontexts_with_additional_indents() { var parent = new Context("parent context"); var child = new Context("child context"); var grandChild = new Context("grandchild context"); parent.AddContext(child); child.AddContext(grandChild); formatter.Write(parent).should_be_of_form("{0}parent context{0}{1}child context{0}{1}{1}grandchild context"); }
public string Write(Context context, int level = 1) { var result = ""; if (level == 1) result += Environment.NewLine; result += context.Name; context.Examples.Do(e => result += Write(e, level)); context.Contexts.Do(c => result += Environment.NewLine + indent.Times(level) + Write(c, level + 1)); return result; }
public void setup() { contexts = new ContextCollection(); var context = new Context(); context.AddExample(new ExampleBaseWrap()); context.AddExample(new ExampleBaseWrap { Pending = true }); context.AddExample(new ExampleBaseWrap { Exception = new Exception() }); context.Tags.Add(Tags.Focus); contexts.Add(context); }
void Build(Context parent, IEnumerable<Type> allSpecClasses) { var derivedTypes = allSpecClasses.Where(s => parent.IsSub(s.BaseType)); foreach (var derived in derivedTypes) { var classContext = CreateClassContext(derived); parent.AddContext(classContext); BuildMethodContexts(classContext, derived); BuildMethodLevelExamples(classContext, derived); Build(classContext, allSpecClasses); } }
public void setup() { try { throw new Exception("BOOM!"); } catch (Exception exception) { example = new Example("example name") { Exception = exception }; } var context = new Context("context name"); context.AddExample(example); output = new ConsoleFormatter().WriteFailure(example); }
public void Write(Context context) { if (ExamplesToProcess.Count == 0 || context.AllExamples().Any(t => ExamplesToProcess.Contains(GetSpecName(t)))) { if (context.Level == 1) WriteLineDelegate(""); WriteLineDelegate(indent.Times(context.Level - 1) + context.Name); if (context is ClassContext && TestClassProcessed != null) { string name = string.Empty; Utilities.GenerateUniqueExampleName(context, ref name); TestClassProcessed(name, eventArgs); } } }
public void setup() { var finder = MockRepository.GenerateMock<ISpecFinder>(); finder.Stub(f => f.Except).Return(new SpecFinder().Except); finder.Stub(s => s.SpecClasses()).Return(new[] { typeof(SpecClass) }); var builder = new ContextBuilder(finder); classContext = new Context("class"); classContext.Type = typeof(SpecClass); builder.BuildMethodContexts(classContext, typeof(SpecClass)); classContext.Run(); }
protected void AddContext(string name, Action action) { level++; var newContext = new Context(name,level); Context.AddContext(newContext); var beforeContext = Context; Context = newContext; action(); level--; Context = beforeContext; }
protected void Run(Type type) { var finder = new SpecFinder(new[] { type }); var builder = new ContextBuilder(finder, new DefaultConventions()); var contexts = builder.Contexts(); contexts.Build(); contexts.Run(); classContext = contexts .AllContexts() .Select(c => c as ClassContext) .First(c => c.type == type); methodContext = contexts.AllContexts().First(c => c is MethodContext); }