Search in sources :

Example 11 with Keywords

use of org.jbehave.core.configuration.Keywords in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeAndMetaFilter.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeAndMetaFilter() {
    String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Outcome: ANY " + NL + "MetaFilter: +all" + NL + "Given a step after any scenario" + NL + "Outcome: SUCCESS " + NL + "MetaFilter: +happy" + NL + "Given a step after successful scenario" + NL + "Outcome: FAILURE " + NL + "MetaFilter: +sad" + NL + "Given a step after failed scenario" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    Lifecycle lifecycle = story.getLifecycle();
    List<String> afterSteps = lifecycle.getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Given a step after any scenario"));
    assertThat(afterSteps.get(1), equalTo("Given a step after successful scenario"));
    assertThat(afterSteps.get(2), equalTo("Given a step after failed scenario"));
    assertThat(new ArrayList<>(lifecycle.getOutcomes()), equalTo(Arrays.asList(Outcome.ANY, Outcome.SUCCESS, Outcome.FAILURE)));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Given a step after any scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Given a step after successful scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Given a step after failed scenario"));
    assertThat(lifecycle.getMetaFilter(Outcome.ANY).asString(), equalTo("+all"));
    Keywords keywords = new Keywords();
    assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@all", keywords)).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@all", keywords)).get(0), equalTo("Given a step after any scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@none", keywords)).size(), equalTo(0));
    assertThat(lifecycle.getMetaFilter(Outcome.SUCCESS).asString(), equalTo("+happy"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@happy", keywords)).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@happy", keywords)).get(0), equalTo("Given a step after successful scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@none", keywords)).size(), equalTo(0));
    assertThat(lifecycle.getMetaFilter(Outcome.FAILURE).asString(), equalTo("+sad"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@sad", keywords)).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@sad", keywords)).get(0), equalTo("Given a step after failed scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@none", keywords)).size(), equalTo(0));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
Also used : Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Lifecycle(org.jbehave.core.model.Lifecycle) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 12 with Keywords

use of org.jbehave.core.configuration.Keywords in project jbehave-core by jbehave.

the class LocalizedKeywordsBehaviour method shouldAllowSynonymsToOverrideABaseBundleForSameLocale.

@Test
public void shouldAllowSynonymsToOverrideABaseBundleForSameLocale() throws IOException {
    Keywords keywords = new LocalizedKeywords(new Locale("en"), "i18n/synonyms", "i18n/keywords");
    assertThat(keywords.given(), equalTo("Given|Giveth"));
    assertThat(keywords.and(), equalTo("And|With"));
}
Also used : Locale(java.util.Locale) Keywords(org.jbehave.core.configuration.Keywords) Test(org.junit.Test)

Example 13 with Keywords

use of org.jbehave.core.configuration.Keywords in project jbehave-core by jbehave.

the class LocalizedKeywordsBehaviour method ensureKeywordsAreLocalised.

private void ensureKeywordsAreLocalised(Configuration configuration, Locale locale) {
    Keywords keywords = keywordsFor(locale, null, null);
    Map<StepType, String> startingWordsByType = keywords.startingWordsByType();
    assertThat(startingWordsByType.get(StepType.GIVEN), equalTo(keywords.given()));
    assertThat(startingWordsByType.get(StepType.WHEN), equalTo(keywords.when()));
    assertThat(startingWordsByType.get(StepType.THEN), equalTo(keywords.then()));
    assertThat(startingWordsByType.get(StepType.AND), equalTo(keywords.and()));
    assertThat(startingWordsByType.get(StepType.IGNORABLE), equalTo(keywords.ignorable()));
}
Also used : Keywords(org.jbehave.core.configuration.Keywords) StepType(org.jbehave.core.steps.StepType)

Example 14 with Keywords

use of org.jbehave.core.configuration.Keywords in project jbehave-core by jbehave.

the class LocalizedKeywordsBehaviour method ensureKeywordsAreLocalisedFor.

private void ensureKeywordsAreLocalisedFor(Locale locale, Locale baseLocale, String bundleName) throws IOException {
    Keywords keywords = keywordsFor(locale, baseLocale, bundleName, null);
    Properties properties = bundleFor(locale);
    ensureKeywordIs(properties, META, keywords.meta());
    ensureKeywordIs(properties, META_PROPERTY, keywords.metaProperty());
    ensureKeywordIs(properties, NARRATIVE, keywords.narrative());
    ensureKeywordIs(properties, IN_ORDER_TO, keywords.inOrderTo());
    ensureKeywordIs(properties, AS_A, keywords.asA());
    ensureKeywordIs(properties, I_WANT_TO, keywords.iWantTo());
    ensureKeywordIs(properties, SO_THAT, keywords.soThat());
    ensureKeywordIs(properties, SCENARIO, keywords.scenario());
    ensureKeywordIs(properties, GIVEN_STORIES, keywords.givenStories());
    ensureKeywordIs(properties, LIFECYCLE, keywords.lifecycle());
    ensureKeywordIs(properties, BEFORE, keywords.before());
    ensureKeywordIs(properties, AFTER, keywords.after());
    ensureKeywordIs(properties, EXAMPLES_TABLE, keywords.examplesTable());
    ensureKeywordIs(properties, EXAMPLES_TABLE_ROW, keywords.examplesTableRow());
    ensureKeywordIs(properties, EXAMPLES_TABLE_HEADER_SEPARATOR, keywords.examplesTableHeaderSeparator());
    ensureKeywordIs(properties, EXAMPLES_TABLE_VALUE_SEPARATOR, keywords.examplesTableValueSeparator());
    ensureKeywordIs(properties, EXAMPLES_TABLE_IGNORABLE_SEPARATOR, keywords.examplesTableIgnorableSeparator());
    ensureKeywordIs(properties, GIVEN, keywords.given());
    ensureKeywordIs(properties, WHEN, keywords.when());
    ensureKeywordIs(properties, THEN, keywords.then());
    ensureKeywordIs(properties, AND, keywords.and());
    ensureKeywordIs(properties, IGNORABLE, keywords.ignorable());
    ensureKeywordIs(properties, PENDING, keywords.pending());
    ensureKeywordIs(properties, NOT_PERFORMED, keywords.notPerformed());
    ensureKeywordIs(properties, FAILED, keywords.failed());
    ensureKeywordIs(properties, DRY_RUN, keywords.dryRun());
    ensureKeywordIs(properties, STORY_CANCELLED, keywords.storyCancelled());
    ensureKeywordIs(properties, SCOPE, keywords.scope());
    ensureKeywordIs(properties, SCOPE_SCENARIO, keywords.scopeScenario());
    ensureKeywordIs(properties, SCOPE_STORY, keywords.scopeStory());
    ensureKeywordIs(properties, META_FILTER, keywords.metaFilter());
    ensureKeywordIs(properties, OUTCOME, keywords.outcome());
    ensureKeywordIs(properties, OUTCOME_ANY, keywords.outcomeAny());
    ensureKeywordIs(properties, OUTCOME_SUCCESS, keywords.outcomeSuccess());
    ensureKeywordIs(properties, OUTCOME_FAILURE, keywords.outcomeFailure());
    ensureKeywordIs(properties, OUTCOME_DESCRIPTION, keywords.outcomeDescription());
    ensureKeywordIs(properties, OUTCOME_VALUE, keywords.outcomeValue());
    ensureKeywordIs(properties, OUTCOME_MATCHER, keywords.outcomeMatcher());
    ensureKeywordIs(properties, OUTCOME_VERIFIED, keywords.outcomeVerified());
}
Also used : Keywords(org.jbehave.core.configuration.Keywords) Properties(java.util.Properties)

Example 15 with Keywords

use of org.jbehave.core.configuration.Keywords in project jbehave-core by jbehave.

the class LocalizedKeywordsBehaviour method shouldAllowSynonymsToOverrideABaseLocale.

@Test
public void shouldAllowSynonymsToOverrideABaseLocale() throws IOException {
    Keywords keywords = new LocalizedKeywords(new Locale("sy"), Locale.ENGLISH);
    assertThat(keywords.given(), equalTo("Given|Giveth"));
    assertThat(keywords.and(), equalTo("And|With"));
}
Also used : Locale(java.util.Locale) Keywords(org.jbehave.core.configuration.Keywords) Test(org.junit.Test)

Aggregations

Keywords (org.jbehave.core.configuration.Keywords)18 Test (org.junit.Test)12 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)9 Locale (java.util.Locale)4 Properties (java.util.Properties)4 Configuration (org.jbehave.core.configuration.Configuration)4 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)4 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)4 SimpleDateFormat (java.text.SimpleDateFormat)3 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)3 LoadFromURL (org.jbehave.core.io.LoadFromURL)3 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)3 Matchers.anyString (org.mockito.Matchers.anyString)3 URL (java.net.URL)2 AnnotationBuilder (org.jbehave.core.configuration.AnnotationBuilder)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 Meta (org.jbehave.core.model.Meta)2 TableTransformers (org.jbehave.core.model.TableTransformers)2 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)2 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2