How to use includes_tag_for_method_as_method_attribute method of NSpec.Tests.WhenRunningSpecs.SpecClassDerived class

Best NSpec code snippet using NSpec.Tests.WhenRunningSpecs.SpecClassDerived.includes_tag_for_method_as_method_attribute

Run NSpec automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

describe_tag_filtering.cs

Source: describe_tag_filtering.cs Github

copy
1using System.Linq;
2using NSpec;
3using NUnit.Framework;
4
5namespace NSpecSpecs.WhenRunningSpecs
6{
7    [TestFixture]
8    public class describe_tag_filtering : when_running_specs
9    {
10        [Tag("class-tag-zero")]
11        class SpecClass0 : nspec
12        {
13            [Tag("method-tag-zero")]
14            void it_has_an_empty_example()
15            {
16
17            }
18        }
19
20        abstract class SpecClassBase : nspec
21        {
22            void specify_empty_example()
23            {
24                
25            }
26        }
27
28        class SpecClassDerived : SpecClassBase
29        {
30            void specify_another_empty_example()
31            {
32                
33            }
34        }
35
36        [Tag("class-tag")]
37        class SpecClass : nspec
38        {
39            [Tag("method-tag-one")]
40            void has_tag_at_method_level_context()
41            {
42                it["tests nothing"] = () => 1.should_be(1);
43            }
44
45            [Tag("method-tag-two")]
46            void has_tags_in_context_or_example_level()
47            {
48                context["is tagged with 'mytag'", "mytag"] = () =>
49                {
50                    it["is tagged with 'mytag'"] = () => 1.should_be(1);
51                };
52
53                context["has three tags", "mytag,expect-to-failure,foobar"] = () =>
54                {
55                    it["has three tags"] = () => { 1.should_be(1); };
56                };
57
58                context["does not have a tag"] = () =>
59                {
60                    it["does not have a tag"] = () => { true.should_be_true(); };
61                };
62
63                context["has a nested context"] = () =>
64                {
65                    context["is the nested context", "foobar"] = () =>
66                    {
67                        it["is the nested example", "nested-tag"] = () => { true.should_be_true(); };
68                    };
69                };
70            }
71        }
72
73        class SpecClass1 : nspec
74        {
75            void filters_out_not_run_examples()
76            {
77                context["has only example level tags"] = () =>
78                {
79                    it["should run and be in output", "shouldbeinoutput"] = () => true.should_be_true();
80                    it["should not run and not be in output", "barbaz"] = () => true.should_be_true();
81                    it["should also not run too not be in output"] = () => true.should_be_true();
82
83                    xit["pending but should be in output", "shouldbeinoutput"] = () => true.should_be_true();
84                    it["also pending but should be in output", "shouldbeinoutput"] = todo;
85                };
86
87                context["has context level tags", "shouldbeinoutput"] = () =>
88                {
89                    it["should also run and be in output", "barbaz"] = () => true.should_be_true();
90                    it["should yet also run and be in output"] = () => true.should_be_true();
91                };
92            }
93        }
94
95        [Test]
96        public void abstracted_classes_are_automatically_included_in_class_tags()
97        {
98            Run(typeof(SpecClassDerived));
99
100            classContext.Tags.should_contain("SpecClassBase");
101
102            classContext.Tags.should_contain("SpecClassDerived");
103        }
104
105        [Test]
106        public void classes_are_automatically_tagged_with_class_name()
107        {
108            Run(typeof(SpecClass0));
109
110            classContext.Tags.should_contain("class-tag-zero");
111
112            classContext.Tags.should_contain("SpecClass0");
113        }
114
115        [Test]
116        public void includes_tag()
117        {
118            tags = "mytag";
119            Run(typeof(SpecClass));
120            classContext.AllContexts().Count().should_be(4);
121        }
122
123        [Test]
124        public void excludes_tag()
125        {
126            tags = "~mytag";
127            Run(typeof(SpecClass));
128            classContext.AllContexts().Count().should_be(6);
129            classContext.AllContexts().should_not_contain(c => c.Tags.Contains("mytag"));
130        }
131
132        [Test]
133        public void includes_and_excludes_tags()
134        {
135            tags = "mytag,~foobar";
136            Run(typeof(SpecClass));
137            classContext.AllContexts().should_contain(c => c.Tags.Contains("mytag"));
138            classContext.AllContexts().should_not_contain(c => c.Tags.Contains("foobar"));
139            classContext.AllContexts().Count().should_be(3);
140        }
141
142        [Test]
143        public void includes_tag_as_class_attribute()
144        {
145            tags = "class-tag-zero";
146            Run(typeof(SpecClass0));
147            classContext.AllContexts().Count().should_be(1);
148        }
149
150        [Test]
151        public void includes_tag_for_method_as_method_attribute()
152        {
153            tags = "method-tag-zero";
154            Run(typeof(SpecClass0));
155            classContext.AllContexts().SelectMany(s => s.Examples).Count().should_be(1);
156        }
157
158        [Test]
159        public void excludes_tag_as_class_attribute()
160        {
161            tags = "~class-tag";
162            Run(new[] { typeof(SpecClass), typeof(SpecClass0) });
163            contextCollection.Count.should_be(1);
164        }
165
166        [Test]
167        public void includes_tag_as_method_attribute()
168        {
169            tags = "method-tag-one";
170            Run(typeof(SpecClass));
171            classContext.AllContexts().Count().should_be(2);
172        }
173
174        [Test]
175        public void excludes_tag_as_method_attribute()
176        {
177            tags = "~method-tag-one";
178            Run(typeof(SpecClass));
179            classContext.AllContexts().Count().should_be(7);
180        }
181
182        [Test]
183        public void excludes_examples_not_run()
184        {
185            tags = "shouldbeinoutput";
186            Run(typeof(SpecClass1));
187            var allExamples = classContext.AllContexts().SelectMany(c => c.AllExamples()).ToList();
188            allExamples.should_contain(e => e.Spec == "should run and be in output");
189            allExamples.should_contain(e => e.Spec == "should also run and be in output");
190            allExamples.should_contain(e => e.Spec == "should yet also run and be in output");
191            allExamples.should_contain(e => e.Spec == "pending but should be in output");
192            allExamples.should_contain(e => e.Spec == "also pending but should be in output");
193            allExamples.should_not_contain(e => e.Spec == "should not run and not be in output");
194            allExamples.should_not_contain(e => e.Spec == "should also not run too not be in output");
195        }
196    }
197}
198
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)