示例#1
0
        public FixtureBuilder(IGherkinFeature gherkin, ISpockOptions options)
        {
            this.gherkin           = gherkin;
            this.options           = options;
            this.fixtureInvariants = new FixtureInvariants(gherkin, options);

            var summary = new List <string>
            {
                "Feature Id: " + this.fixtureInvariants.FeatureId,
                gherkin.Name,
                gherkin.Description
            };

            if (gherkin.Background != null)
            {
                summary.AddRange(gherkin.Background.Gherkin);
            }

            var disabled = gherkin.Comments.DisabledScenarios("<item>", "</item>").ToArray();

            if (disabled.Any())
            {
                const string header =
                    "The following Scenario Ids (Test Step Id's) have been disabled from this fixture. Please review " +
                    "the original test cases XML file to see if the test scenario was valid, and if " +
                    "so, update the Gherkin .feature file to reflect the test case. Then regenerate " +
                    "this test fixture to include the new scenario.";

                var builder = new StringBuilder();
                builder.Append(header);
                builder.Append("<list type=\"bullet\">");
                foreach (var d in disabled)
                {
                    builder.Append(d);
                }

                builder.Append("</list>");
                summary.Add(builder.ToString());
            }

            this.comments.AddRange(CodeGeneration.ToXmlSummary(summary.ToArray(), false));
            this.comments.AddRange(CodeGeneration.ToXmlRemarks(gherkin.Gherkin, new[] { "example", "code language=\"none\" title=\"Gherkin\"" }));
            this.feature = FixtureStep.Create(GherkinKeyword.Feature, gherkin.Description);
            if (gherkin.Background == null)
            {
                return;
            }

            this.background = new BackgroundBuilder(gherkin.Background).Build();
            this.feature.AddBackground(this.background);
        }
        public FixtureInvariants(IGherkinFeature gherkin, ISpockOptions options)
        {
            this.FixtureName = gherkin.Name.ToSafeSyntax();

            this.Namespace = !string.IsNullOrEmpty(options.QualifiedNamespace)
                ? options.QualifiedNamespace
                : gherkin.Namespace;

            var maybe = gherkin.Comments.Find(GherkinIdRef.FeatureId);

            this.FeatureId = maybe.HasValue ? maybe.Value.Value : Guid.NewGuid().ToString();

            this.FilePath = gherkin.SourceFile.Replace(".feature", ".generated.cs");
        }
示例#3
0
        /// <summary>
        /// Parses the Gherkin Feature AST and creates a Test Fixture AST.
        /// </summary>
        /// <param name="feature">The Gherkin AST feature.</param>
        /// <returns>
        /// An object that supports the <see cref="ISpockFixture" /> interface.
        /// </returns>
        /// <exception cref="GherkinException">No scenarios found in the feature.</exception>
        public ISpockFixture Parse(IGherkinFeature feature)
        {
            if (feature.Scenarios == null || !feature.Scenarios.Any())
            {
                throw new GherkinException(GherkinExceptionType.NoScenariosInFeature, "No scenarios found in the feature");
            }

            var builder = new FixtureBuilder(feature, this.options);

            foreach (var scenario in feature.Scenarios)
            {
                builder.AddMethods(scenario);
            }

            return(builder.Build());
        }
示例#4
0
 public SpockFixture(
     IGherkinFeature gherkin,
     IFixtureInvariants fixtureInvariants,
     IFixtureStep feature,
     IEnumerable <string> comments,
     IFixtureBackground background,
     IFixtureMethods methods,
     ISpockOptions options)
     : base(options, fixtureInvariants)
 {
     this.gherkin           = gherkin;
     this.FixtureInvariants = fixtureInvariants;
     this.GherkinAttributes = feature;
     this.XmlDocComments    = new SpockCollection <string>(comments);
     this.Background        = background;
     this.FixtureMethods    = methods;
 }