Example #1
0
        public ContextCollection Run()
        {
            var reflector = new Reflector(this.dll);

            var finder = new SpecFinder(reflector);

            var tagsFilter = new Tags().Parse(Tags);

            var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());

            var runner = new ContextRunner(tagsFilter, Formatter, failFast);

            var contexts = builder.Contexts().Build();

            if(contexts.AnyTaggedWithFocus())
            {
                tagsFilter = new Tags().Parse(NSpec.Domain.Tags.Focus);

                builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());

                runner = new ContextRunner(tagsFilter, Formatter, failFast);

                contexts = builder.Contexts().Build();
            }

            return runner.Run(contexts);
        }
        protected when_running_specs Run(params Type[] types)
        {
            //if (types.Count() == 1) tags = types.First().Name;

            this.types = types;

            var tagsFilter = new Tags().Parse(tags);

            builder = new ContextBuilder(new SpecFinder(types), tagsFilter, new DefaultConventions());

            runner = new ContextRunner(tagsFilter, 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;
        }
Example #3
0
 public bool ShouldNotSkip(Tags tagsFilter)
 {
     //really should be the opposite of ShouldSkip.
     //but unfortunately calling ShouldSkip has side effects
     //see the HasRun assignment. calling ShouldSkip here thus
     //has side effects that fail some tests.
     return false == tagsFilter.ShouldSkip(Tags);
 }
Example #4
0
        public ContextBuilder(ISpecFinder finder, Tags tagsFilter, Conventions conventions)
        {
            contexts = new ContextCollection();

            this.finder = finder;

            this.conventions = conventions;

            this.tagsFilter = tagsFilter;
        }
Example #5
0
        public void parses_multiple_tags_filters()
        {
            var tags = new Tags();
            tags.Parse("myInclude1,~myExclude1,myInclude2,~myExclude2,");

            tags.should_tag_as_included("myInclude1");
            tags.should_tag_as_excluded("myExclude1");

            tags.should_tag_as_included("myInclude2");
            tags.should_tag_as_excluded("myExclude2");

            tags.IncludeTags.Count.should_be(2);
            tags.ExcludeTags.Count.should_be(2);
        }
Example #6
0
        public ClassContext(Type type, Conventions conventions = null, Tags tagsFilter = null, string tags = null)
            : base(type.CleanName(), tags)
        {
            this.type = type;

            this.conventions = conventions ?? new DefaultConventions().Initialize();

            this.tagsFilter = tagsFilter;

            if (type != typeof(nspec))
            {
                classHierarchyToClass.AddRange(type.GetAbstractBaseClassChainWithClass());
            }
        }
        public void debug()
        {
            //the specification class you want to test
            //this can be a regular expression
            var testClassYouWantToDebug = "NSpecSpecs.ClassContextBug.Child";

            //initialize NSpec's specfinder
            var finder = new SpecFinder(
                new Reflector(Assembly.GetExecutingAssembly().Location),
                testClassYouWantToDebug);

            //initialize NSpec's builder
            var builder = new ContextBuilder(finder, new DefaultConventions());

            //this line runs the tests you specified in the filter
            var noTagsFilter = new Tags();
            TestFormatter formatter = new TestFormatter();
            new ContextRunner(noTagsFilter, formatter, false).Run(builder.Contexts().Build());

            Context grandParent = formatter.Contexts[0];
            Assert.That(grandParent.Name, Is.EqualTo("Grand Parent"));
            Assert.That(grandParent.Contexts.Count, Is.EqualTo(2));
            Assert.That(grandParent.Contexts[0].Name, Is.EqualTo("Grand Parent Context"));
            Assert.That(grandParent.Contexts[1].Name, Is.EqualTo("Parent"));
            Assert.That(grandParent.Contexts[0].Examples[0].Spec, Is.EqualTo("TestValue should be \"Grand Parent!!!\""));
            Assert.That(grandParent.Contexts[0].Examples[0].Exception, Is.Null);
            Assert.That(grandParent.Contexts[0].Examples[0].Pending, Is.False);

            Context parent = formatter.Contexts[0].Contexts[1];
            Assert.That(parent.Name, Is.EqualTo("Parent"));
            Assert.That(parent.Contexts.Count, Is.EqualTo(2));
            Assert.That(parent.Contexts[0].Name, Is.EqualTo("Parent Context"));
            Assert.That(parent.Contexts[1].Name, Is.EqualTo("Child"));
            Assert.That(parent.Contexts[0].Examples[0].Spec, Is.EqualTo("TestValue should be \"Grand [email protected]@@\""));
            Assert.That(parent.Contexts[0].Examples[0].Exception, Is.Null);
            Assert.That(parent.Contexts[0].Examples[0].Pending, Is.False);

            Context child = formatter.Contexts[0].Contexts[1].Contexts[1];
            Assert.That(child.Name, Is.EqualTo("Child"));
            Assert.That(child.Contexts.Count, Is.EqualTo(1));
            Assert.That(child.Contexts[0].Name, Is.EqualTo("Child Context"));
            Assert.That(child.Contexts[0].Examples[0].Spec, Is.EqualTo("TestValue should be \"Grand [email protected]@@###\""));
            Assert.That(child.Contexts[0].Examples[0].Exception, Is.Null);
            Assert.That(child.Contexts[0].Examples[0].Pending, Is.False);
        }
Example #8
0
        public void output_verification(Type output, Type []testClasses, string tags)
        {
            var finder = new SpecFinder(testClasses, "");
            var tagsFilter = new Tags().Parse(tags);
            var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());
            var consoleFormatter = new ConsoleFormatter();

            var actual = new System.Collections.Generic.List<string>();
            consoleFormatter.WriteLineDelegate = actual.Add;

            var runner = new ContextRunner(tagsFilter, consoleFormatter, false);
            runner.Run(builder.Contexts().Build());

            var expectedString = ScrubStackTrace(ScrubNewLines(output.GetField("Output").GetValue(null) as string));
            var actualString = ScrubStackTrace(String.Join("\n", actual)).Trim();
            actualString.should_be(expectedString);

            var guid = Guid.NewGuid();
        }
Example #9
0
        public static void Main(string[] args)
        {
            //format();
            //Tests.GenerateTestComponents.Generate();

            //var tagOrClassName = "focus";
            var tagOrClassName = string.Empty;

            var types = Assembly.GetAssembly(typeof(describe_Entity)).GetTypes();

            var finder = new SpecFinder(types, "");
            var tagsFilter = new Tags().Parse(tagOrClassName);
            var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());
            var runner = new ContextRunner(tagsFilter, new ConsoleFormatter(), false);

            var results = runner.Run(builder.Contexts().Build());

            Environment.Exit(results.Failures().Count());
        }
Example #10
0
 public void parses_single_include_tag_filters()
 {
     var tags = new Tags();
     tags.Parse("mytag");
     tags.should_tag_as_included("mytag");
 }
Example #11
0
 public bool ShouldSkip(Tags tagsFilter)
 {
     return tagsFilter.ShouldSkip(Tags) || ((HasRun = true) && Pending);
 }
Example #12
0
            public void parses_tag_filters()
            {
                it[ "parses single 'include' tag filter" ] = () =>
                {
                    var tags = new Tags();
                    tags.ParseTagFilters( "mytag" );
                    tags.should_tag_as_included( "mytag" );
                };

                it[ "parses single 'exclude' tag filter" ] = () =>
                {
                    var tags = new Tags();
                    tags.ParseTagFilters( "~mytag" );
                    tags.should_tag_as_excluded( "mytag" );
                };

                it[ "parses ampersat tag filter" ] = () =>
                {
                    var tags = new Tags();
                    tags.ParseTagFilters( "@mytag" );
                    tags.should_tag_as_included( "mytag" );
                };

                it[ "parses multiple tags filter" ] = () =>
                {
                    var tags = new Tags();
                    tags.ParseTagFilters( "myInclude1,~myExclude1,@myInclude2,[email protected]," );
                    tags.should_tag_as_excluded( "@myExclude1" );
                    tags.should_tag_as_excluded( "myExclude2" );
                    tags.should_tag_as_included( "@myInclude1" );
                    tags.should_tag_as_included( "myInclude2" );
                    tags.IncludeTags.Count.should_be( 2 );
                    tags.ExcludeTags.Count.should_be( 2 );
                };
            }
Example #13
0
 public ContextBuilder(ISpecFinder finder, Tags tagsFilter)
     : this(finder, new DefaultConventions())
 {
 }
Example #14
0
 public ContextRunner(Tags tagsFilter, IFormatter formatter, bool failFast)
 {
     this.failFast = failFast;
     this.tagsFilter = tagsFilter;
     this.formatter = formatter;
 }