Search in sources :

Example 1 with Steps

use of org.jbehave.core.model.Lifecycle.Steps in project jbehave-core by jbehave.

the class RegexStoryParser method parseBeforeLifecycle.

private List<Steps> parseBeforeLifecycle(String lifecycleAsText) {
    List<Steps> list = new ArrayList<>();
    for (String byScope : lifecycleAsText.split(keywords.scope())) {
        byScope = byScope.trim();
        if (byScope.isEmpty())
            continue;
        Scope scope = parseScope(findScope(keywords.scope() + byScope));
        Steps steps = new Steps(scope, findSteps(startingWithNL(byScope)));
        list.add(steps);
    }
    return list;
}
Also used : Steps(org.jbehave.core.model.Lifecycle.Steps) Scope(org.jbehave.core.annotations.Scope) ArrayList(java.util.ArrayList)

Example 2 with Steps

use of org.jbehave.core.model.Lifecycle.Steps in project jbehave-core by jbehave.

the class RegexStoryParser method parseLifecycle.

private Lifecycle parseLifecycle(String storyAsText) {
    String scenarioKeyword = keywords.scenario();
    // use text before scenario keyword, if found
    String beforeScenario = "";
    if (StringUtils.contains(storyAsText, scenarioKeyword)) {
        beforeScenario = StringUtils.substringBefore(storyAsText, scenarioKeyword);
    }
    Matcher findingLifecycle = findingLifecycle().matcher(beforeScenario);
    String lifecycle = findingLifecycle.find() ? findingLifecycle.group(1).trim() : NONE;
    Matcher findingBeforeAndAfter = compile(".*" + keywords.before() + "(.*)\\s*" + keywords.after() + "(.*)\\s*", DOTALL).matcher(lifecycle);
    if (findingBeforeAndAfter.matches()) {
        String beforeLifecycle = findingBeforeAndAfter.group(1).trim();
        List<Steps> beforeSteps = parseBeforeLifecycle(beforeLifecycle);
        String afterLifecycle = findingBeforeAndAfter.group(2).trim();
        List<Steps> afterSteps = parseAfterLifecycle(afterLifecycle);
        return new Lifecycle(beforeSteps, afterSteps);
    }
    Matcher findingBefore = compile(".*" + keywords.before() + "(.*)\\s*", DOTALL).matcher(lifecycle);
    if (findingBefore.matches()) {
        String beforeLifecycle = findingBefore.group(1).trim();
        List<Steps> beforeSteps = parseBeforeLifecycle(beforeLifecycle);
        return new Lifecycle(beforeSteps, Arrays.<Steps>asList());
    }
    Matcher findingAfter = compile(".*" + keywords.after() + "(.*)\\s*", DOTALL).matcher(lifecycle);
    if (findingAfter.matches()) {
        List<Steps> beforeSteps = asList();
        String afterLifecycle = findingAfter.group(1).trim();
        List<Steps> afterSteps = parseAfterLifecycle(afterLifecycle);
        return new Lifecycle(beforeSteps, afterSteps);
    }
    return Lifecycle.EMPTY;
}
Also used : Steps(org.jbehave.core.model.Lifecycle.Steps) Matcher(java.util.regex.Matcher) Lifecycle(org.jbehave.core.model.Lifecycle)

Example 3 with Steps

use of org.jbehave.core.model.Lifecycle.Steps in project jbehave-core by jbehave.

the class RegexStoryParser method parseAfterLifecycle.

private List<Steps> parseAfterLifecycle(String lifecycleAsText) {
    List<Steps> list = new ArrayList<>();
    for (String byScope : lifecycleAsText.split(keywords.scope())) {
        byScope = byScope.trim();
        if (byScope.isEmpty())
            continue;
        Scope scope = parseScope(findScope(keywords.scope() + byScope));
        for (String byOutcome : byScope.split(keywords.outcome())) {
            byOutcome = byOutcome.trim();
            if (byOutcome.isEmpty())
                continue;
            String outcomeAsText = findOutcome(byOutcome);
            String filtersAsText = findFilters(removeStart(byOutcome, outcomeAsText));
            List<String> steps = findSteps(startingWithNL(removeStart(byOutcome, filtersAsText)));
            list.add(new Steps(scope, parseOutcome(outcomeAsText), parseFilters(filtersAsText), steps));
        }
    }
    return list;
}
Also used : Steps(org.jbehave.core.model.Lifecycle.Steps) Scope(org.jbehave.core.annotations.Scope) ArrayList(java.util.ArrayList)

Aggregations

Steps (org.jbehave.core.model.Lifecycle.Steps)3 ArrayList (java.util.ArrayList)2 Scope (org.jbehave.core.annotations.Scope)2 Matcher (java.util.regex.Matcher)1 Lifecycle (org.jbehave.core.model.Lifecycle)1