Search in sources :

Example 16 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndLifecycle.

@Test
public void shouldParseStoryWithMetaAndLifecycle() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "Lifecycle:" + NL + "Before:" + NL + "Given a step before each scenario" + NL + "And another before step" + NL + "Scenario: A scenario" + NL + "Meta: @author Mauro" + NL + "Given a step " + NL + "Scenario: Another scenario" + NL + "Meta: @author Paul" + NL + "Given another step ";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    Meta storyMeta = story.getMeta();
    assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
    assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
    assertThat(storyMeta.getProperty("unknown"), equalTo(EMPTY));
    Lifecycle lifecycle = story.getLifecycle();
    assertThat(lifecycle.getBeforeSteps().size(), equalTo(2));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.get(0).getTitle(), equalTo("A scenario"));
    assertThat(scenarios.get(0).getMeta().getProperty("author"), equalTo("Mauro"));
    assertThat(scenarios.get(1).getTitle(), equalTo("Another scenario"));
    assertThat(scenarios.get(1).getMeta().getProperty("author"), equalTo("Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) 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 17 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class StoryMapperBehaviour method shouldMapStoriesAllowedByFilter.

@Test
public void shouldMapStoriesAllowedByFilter() throws Throwable {
    // Given
    Meta meta1 = mock(Meta.class, "meta1");
    Story story1 = new Story("/path/to/story1", Description.EMPTY, meta1, Narrative.EMPTY, asList(new Scenario("scenario1", meta1)));
    Meta meta2 = mock(Meta.class, "meta2");
    Story story2 = new Story("/path/to/story2", Description.EMPTY, meta2, Narrative.EMPTY, asList(new Scenario("scenario2", meta2)));
    MetaFilter filter = mock(MetaFilter.class);
    String filterAsString = "-some property";
    // When
    StoryMapper mapper = new StoryMapper();
    when(meta1.inheritFrom(meta1)).thenReturn(meta1);
    when(meta2.inheritFrom(meta2)).thenReturn(meta2);
    when(filter.allow(meta1)).thenReturn(false);
    when(filter.allow(meta2)).thenReturn(true);
    when(filter.asString()).thenReturn(filterAsString);
    mapper.map(story1, filter);
    mapper.map(story2, filter);
    // Then
    StoryMaps storyMaps = mapper.getStoryMaps();
    assertThat(storyMaps.getMaps().size(), equalTo(1));
    StoryMap storyMap = storyMaps.getMap(filterAsString);
    assertThat(storyMap.getMetaFilter(), equalTo(filterAsString));
    assertThat(storyMap.getStories().get(0).getPath(), equalTo(story2.getPath()));
    assertThat(storyMap.getStoryPaths(), equalTo(asList(story2.getPath())));
}
Also used : Meta(org.jbehave.core.model.Meta) StoryMap(org.jbehave.core.model.StoryMap) Story(org.jbehave.core.model.Story) StoryMaps(org.jbehave.core.model.StoryMaps) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 18 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class TemplateableOutput method beforeScenario.

@Override
public void beforeScenario(Scenario scenario) {
    if (this.outputScenario.currentExample == null) {
        this.outputScenario = new OutputScenario();
    }
    this.outputScenario.title = scenario.getTitle();
    this.scope = Scope.SCENARIO;
    Meta meta = scenario.getMeta();
    if (!meta.isEmpty()) {
        this.outputScenario.meta = new OutputMeta(meta);
    }
}
Also used : Meta(org.jbehave.core.model.Meta)

Example 19 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class RegexStoryParser method parseScenario.

private Scenario parseScenario(String scenarioAsText) {
    String title = findScenarioTitle(scenarioAsText);
    String scenarioWithoutKeyword = removeStart(scenarioAsText, keywords.scenario()).trim();
    String scenarioWithoutTitle = removeStart(scenarioWithoutKeyword, title);
    scenarioWithoutTitle = startingWithNL(scenarioWithoutTitle);
    Meta meta = findScenarioMeta(scenarioWithoutTitle);
    ExamplesTable examplesTable = findExamplesTable(scenarioWithoutTitle);
    GivenStories givenStories = findScenarioGivenStories(scenarioWithoutTitle);
    if (givenStories.requireParameters()) {
        givenStories.useExamplesTable(examplesTable);
    }
    List<String> steps = findSteps(scenarioWithoutTitle);
    return new Scenario(title, meta, givenStories, examplesTable, steps);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) Meta(org.jbehave.core.model.Meta) ExamplesTable(org.jbehave.core.model.ExamplesTable) Scenario(org.jbehave.core.model.Scenario)

Example 20 with Meta

use of org.jbehave.core.model.Meta in project jbehave-core by jbehave.

the class RegexStoryParser method parseStory.

public Story parseStory(String storyAsText, String storyPath) {
    Description description = parseDescriptionFrom(storyAsText);
    Meta meta = parseStoryMetaFrom(storyAsText);
    Narrative narrative = parseNarrativeFrom(storyAsText);
    GivenStories givenStories = parseGivenStories(storyAsText);
    Lifecycle lifecycle = parseLifecycle(storyAsText);
    List<Scenario> scenarios = parseScenariosFrom(storyAsText);
    Story story = new Story(storyPath, description, meta, narrative, givenStories, lifecycle, scenarios);
    if (storyPath != null) {
        story.namedAs(new File(storyPath).getName());
    }
    return story;
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) Meta(org.jbehave.core.model.Meta) Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Lifecycle(org.jbehave.core.model.Lifecycle) Story(org.jbehave.core.model.Story) File(java.io.File) Scenario(org.jbehave.core.model.Scenario)

Aggregations

Meta (org.jbehave.core.model.Meta)32 Test (org.junit.Test)23 Story (org.jbehave.core.model.Story)11 Scenario (org.jbehave.core.model.Scenario)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 HashMap (java.util.HashMap)6 Properties (java.util.Properties)6 GivenStory (org.jbehave.core.model.GivenStory)6 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)6 StepMatcher (org.jbehave.core.parsers.StepMatcher)6 Silent (org.jbehave.core.steps.AbstractStepResult.Silent)6 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)6 Map (java.util.Map)4 PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ScenarioType (org.jbehave.core.annotations.ScenarioType)3 ExamplesTable (org.jbehave.core.model.ExamplesTable)3 Lifecycle (org.jbehave.core.model.Lifecycle)3 BytecodeReadingParanamer (com.thoughtworks.paranamer.BytecodeReadingParanamer)2 CachingParanamer (com.thoughtworks.paranamer.CachingParanamer)2