Exemplo n.º 1
0
        public string TurnFeatureIntoSnippet(Step step)
        {
            var argValues = new[] { "string arg1", "string arg2", "string arg3", "string arg4", "string arg5" };
            const string parameterPattern = "\"[^\"]*\"";
            const string stepPatern = "^(Given|When|Then|And|But)(.*)$";

            var paramCount = new Regex(parameterPattern).Matches(step.FeatureLine).Count;
            string paramText;
            if (step.Table == null)
                paramText = string.Format("({0})", string.Join(", ", argValues, 0, paramCount));
            else
            {
                argValues[paramCount] = "Table table";
                paramText = string.Format("({0})", string.Join(", ", argValues, 0, paramCount + 1));
            }

            var replacedFeatureLine = Regex.Replace(step.FeatureLine, parameterPattern, "\\\"([^\\\"]*)\\\"");

            var matchedTemplate = Regex.Replace(replacedFeatureLine, stepPatern, m =>
                {
                    var keyword = step.Kind.ToStringValue();//m.Groups[1];
                    var text = m.Groups[2].Value.Trim();

                    return string.Format("{0}(\"^{1}$\", {2} =>\n{{\n\tPending();\n}});", keyword, text, paramText);
                });

            return matchedTemplate;
        }
Exemplo n.º 2
0
 private object[] GetParams(Step step)
 {
     var regularParameters = GetParams(step.Body);
     if (step.Table == null)
         return regularParameters;
     else
         return regularParameters.Concat(new[] { step.Table }).ToArray();
 }
Exemplo n.º 3
0
 private Step(Step originalStep)
 {
     KindWord = originalStep.KindWord;
     Body = originalStep.Body;
     LineNumber = originalStep.LineNumber;
     Kind = originalStep.Kind;
     Table = originalStep.Table;
     StepSequence = originalStep.StepSequence;
 }
Exemplo n.º 4
0
        public void Execute(IProcessSteps stepProcessor, IProcessScenarioHooks hookProcessor, IFormatOutput outputFormatter, IDictionary<string, string> dictionary)
        {
            var newBody = Body;

            foreach (var key in dictionary.Keys)
                newBody = newBody.Replace("<" + key + ">", dictionary[key]);

            var newFeatureStep = new Step(this) { Body = newBody };
            newFeatureStep.Execute(stepProcessor, hookProcessor, outputFormatter);
        }
Exemplo n.º 5
0
        public override Node ExitStep(Production node)
        {
            var values = GetChildValues(node);
            if (values.Count > 0)
            {
                var kindWord = (string) values[0];
                CurrentStepKind = LookupStepKind(kindWord);
                var stepBody = (string) values[1];
                var table = (Table) null;
                if (values.Count > 2)
                    table = (Table)values[3];

                var step = new Step(table)
                {
                    KindWord = kindWord,
                    Kind = CurrentStepKind,
                    Body = stepBody,
                    LineNumber = node.StartLine
                };
                node.AddValue(step);
            }
            return node;
        }
Exemplo n.º 6
0
        private StepDefinition GetStepDefinition(Step step)
        {
            IEnumerable<StepDefinition> results;
            switch (step.Kind)
            {
                case StepKinds.Given:
                    results = givens.Where(definition => definition.Regex.IsMatch(step.Body));
                    break;
                case StepKinds.When:
                    results = whens.Where(definition => definition.Regex.IsMatch(step.Body));
                    break;
                case StepKinds.Then:
                    results = thens.Where(definition => definition.Regex.IsMatch(step.Body));
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            if (results.Count() == 0) throw new StepMissingException();

            if (results.Count() > 1) throw new StepAmbiguousException(step.Body);

            CheckForEmptyAction(results.First().Action);

            return results.First();
        }
Exemplo n.º 7
0
        private void ExecuteStepDefinitionWithStep(StepDefinition stepDefinition, Step step)
        {
            stepDefinition.StepSet.StepRunner = this;

            stepDefinition.StepSet.BeforeStep();
            try
            {
                new StepCaller(stepDefinition,
                               new TypeCaster(this.transforms)).Call(step);
            }
            catch (IndexOutOfRangeException e)
            {
                throw new ParameterMismatchException(
                    "The number of paramters is not equal to the number of captured groups in the step definition in",
                    stepDefinition.StepSet.GetType().Name + "  on regex \n" + stepDefinition.Regex);
            }

            stepDefinition.StepSet.AfterStep();
        }
Exemplo n.º 8
0
 public void RunStep(Step step)
 {
     var stepDefinition = GetStepDefinition(step);
     ExecuteStepDefinitionWithStep(stepDefinition, step);
 }
Exemplo n.º 9
0
        public StepRunResult ProcessStep(Step step)
        {
            LastProcessStepException = null;
            LastProcessStepDefinition = null;

            try
            {
                LastProcessStepDefinition = GetStepDefinition(step);
                ExecuteStepDefinitionWithStep(LastProcessStepDefinition, step);
                LastProcessStepResultCode = StepRunResultCode.Passed;
            }
            catch (StepMissingException ex)
            {
                MissingSteps.Add(step);
                LastProcessStepException = ex;
                LastProcessStepResultCode = StepRunResultCode.Missing;
            }
            catch (StepPendingException ex)
            {
                PendingSteps.Add(step);
                LastProcessStepException = ex;
                LastProcessStepResultCode = StepRunResultCode.Pending;
            }
            catch (StepAmbiguousException ex)
            {
                LastProcessStepException = ex;
                LastProcessStepResultCode = StepRunResultCode.Failed;
            }
            catch (Exception ex)
            {
                if ((ex.InnerException != null) && (typeof(StepPendingException) == ex.InnerException.GetType()))
                {
                    LastProcessStepException = ex.InnerException;
                    LastProcessStepResultCode = StepRunResultCode.Pending;
                    PendingSteps.Add(step);
                }
                else
                {
                    FailedSteps.Add(step);
                    LastProcessStepException = ex;
                    LastProcessStepResultCode = StepRunResultCode.Failed;
                }
            }

            PassedSteps.Add(step);

            CheckForMissingStep(step);
            var result = new StepRunResult { ResultCode = LastProcessStepResultCode, MatchedStepDefinition = LastProcessStepDefinition, Exception = LastProcessStepException };
            return result;
        }
Exemplo n.º 10
0
 public void CheckForMissingStep(Step featureStep)
 {
     try
     {
         GetStepDefinition(featureStep);
     }
     catch(StepMissingException ex)
     {
         MissingSteps.Add(featureStep);
     }
     catch(Exception e)
     {
         //we dont care about any other exceptions,
         //they are already handled in the process step
     }
 }
Exemplo n.º 11
0
 public void Call(Step step)
 {
     new ActionCaller(DelegateToInvoke, GetParams(step)).Call();
 }