コード例 #1
0
ファイル: RunnableExample.cs プロジェクト: darodriguez/NSpec
        public void Write(ILiveFormatter formatter)
        {
            if (example.HasRun)
            {
                context.WriteAncestors(formatter);

                formatter.Write(example, context.Level);
            }
        }
コード例 #2
0
ファイル: Context.cs プロジェクト: qipa/NSpec
        /// <summary>
        /// Test execution happens in two phases: this is the first phase.
        /// </summary>
        /// <remarks>
        /// Here all contexts and all their examples are run, collecting distinct exceptions
        /// from context itself (befores/ acts/ it/ afters), beforeAll, afterAll.
        /// </remarks>
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null, bool recurse = true)
        {
            if (failFast && Parent.HasAnyFailures())
            {
                return;
            }

            var nspec = savedInstance ?? instance;

            bool runBeforeAfterAll = AnyUnfilteredExampleInSubTree(nspec);

            using (new ConsoleCatcher(output => this.CapturedOutput = output))
            {
                if (runBeforeAfterAll)
                {
                    RunAndHandleException(RunBeforeAll, nspec, ref ExceptionBeforeAll);
                }
            }

            // intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];

                if (failFast && example.Context.HasAnyFailures())
                {
                    return;
                }

                using (new ConsoleCatcher(output => example.CapturedOutput = output))
                {
                    Exercise(example, nspec);
                }

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun)
                {
                    formatter.Write(example, Level);
                }
            }

            if (recurse)
            {
                Contexts.Do(c => c.Run(formatter, failFast, nspec));
            }

            if (runBeforeAfterAll)
            {
                RunAndHandleException(RunAfterAll, nspec, ref ExceptionAfterAll);
            }
        }
コード例 #3
0
        void WriteAncestors(ILiveFormatter formatter)
        {
            if (Parent == null)
            {
                return;
            }

            Parent.WriteAncestors(formatter);

            if (!alreadyWritten)
            {
                formatter.Write(this);
            }

            alreadyWritten = true;
        }
コード例 #4
0
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures())
            {
                return;
            }

            var nspec = savedInstance ?? instance;

            if (AllExamples().Count() > 0)
            {
                RunAndHandleException(RunBeforeAll, nspec, ref Exception);
            }

            //intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];
                if (failFast && example.Context.HasAnyFailures())
                {
                    return;
                }

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun)
                {
                    formatter.Write(example, Level);
                }
            }

            Contexts.Do(c => c.Run(formatter, failFast, nspec));

            if (AllExamples().Count() > 0)
            {
                RunAndHandleException(RunAfterAll, nspec, ref Exception);
            }
        }
コード例 #5
0
ファイル: Context.cs プロジェクト: darodriguez/NSpec
        public void WriteAncestors(ILiveFormatter formatter)
        {
            if (alreadyWritten)
            {
                return;
            }

            // when hitting root `nspec` context, skip it
            if (Parent == null)
            {
                alreadyWritten = true;
                return;
            }

            Parent.WriteAncestors(formatter);

            formatter.Write(this);

            alreadyWritten = true;
        }
コード例 #6
0
ファイル: Context.cs プロジェクト: BrainCrumbz/NSpec
        void WriteAncestors(ILiveFormatter formatter)
        {
            if (Parent == null) return;

            Parent.WriteAncestors(formatter);

            if (!alreadyWritten) formatter.Write(this);

            alreadyWritten = true;
        }
コード例 #7
0
ファイル: Context.cs プロジェクト: BrainCrumbz/NSpec
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures()) return;

            var nspec = savedInstance ?? instance;

            if(AllExamples().Any(e=>e.ShouldNotSkip(nspec.tagsFilter))) RunAndHandleException(RunBeforeAll, nspec, ref Exception);

            //intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];
                if (failFast && example.Context.HasAnyFailures()) return;

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun) formatter.Write(example, Level);
            }

            Contexts.Do(c => c.Run(formatter, failFast, nspec));

            if (AllExamples().Count() > 0) RunAndHandleException(RunAfterAll, nspec, ref Exception);
        }
コード例 #8
0
ファイル: Context.cs プロジェクト: aluetjen-wonga/NSpec
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures()) return;

            var nspec = savedInstance ?? instance;

            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];

                if (failFast && example.Context.HasAnyFailures()) return;

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun) formatter.Write(example, Level);
            }

            Contexts.Do(c => c.Run(formatter, failFast, nspec));
        }
コード例 #9
0
ファイル: Context.cs プロジェクト: NaseUkolyCZ/NSpec
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures()) return;

            var nspec = savedInstance ?? instance;

            if(AllExamples().Any(e=>e.ShouldNotSkip(nspec.tagsFilter))) RunAndHandleException(RunBeforeAll, nspec, ref Exception);

            //intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];
                if (failFast && example.Context.HasAnyFailures()) return;

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun) formatter.Write(example, Level);
            }

            //allow Contexts to change dynamically during the test
            List<Context> runContexts = new List<Context>();
            List<Context> contexts  = new List<Context>(Contexts);
            while (contexts.Count()>0)
            {
                contexts.Do(c => c.Run(formatter, failFast, nspec));
                runContexts.AddRange(contexts);
                contexts = new List<Context>(Contexts.Where(p => !runContexts.Contains(p)));
            }

            if (AllExamples().Count() > 0) RunAndHandleException(RunAfterAll, nspec, ref Exception);
        }