Search in sources :

Example 11 with StoryFinder

use of org.jbehave.core.io.StoryFinder in project jbehave-core by jbehave.

the class CoreStoryRunner method runClasspathLoadedStoriesAsJUnit.

@Test
public void runClasspathLoadedStoriesAsJUnit() {
    // CoreEmbedder defines the configuration and steps factory
    Embedder embedder = new CoreEmbedder();
    embedder.embedderControls().doIgnoreFailureInStories(true);
    List<String> storyPaths = new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");
    embedder.runStoriesAsPaths(storyPaths);
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 12 with StoryFinder

use of org.jbehave.core.io.StoryFinder in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldReportFailuresInMappingStoriesAsEmbeddables.

@Test(expected = MojoFailureException.class)
public void shouldReportFailuresInMappingStoriesAsEmbeddables() throws MojoExecutionException, MojoFailureException {
    // Given
    final EmbedderClassLoader classLoader = new EmbedderClassLoader(this.getClass().getClassLoader());
    MapStoriesAsEmbeddables mojo = new MapStoriesAsEmbeddables() {

        @Override
        protected Embedder newEmbedder() {
            return embedder;
        }

        @Override
        protected EmbedderClassLoader classLoader() {
            return classLoader;
        }
    };
    String searchInDirectory = "src/test/java/";
    mojo.sourceDirectory = searchInDirectory;
    List<String> includes = asList("**/*StoryMaps.java");
    mojo.includes = includes;
    List<String> excludes = asList();
    mojo.excludes = excludes;
    List<String> classNames = new StoryFinder().findClassNames(searchInDirectory, includes, excludes);
    // When
    doThrow(new RuntimeException()).when(embedder).runAsEmbeddables(classNames);
    mojo.execute();
// Then fail as expected
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 13 with StoryFinder

use of org.jbehave.core.io.StoryFinder in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldRunStoriesAsPaths.

@Test
public void shouldRunStoriesAsPaths() throws MojoExecutionException, MojoFailureException {
    // Given
    final EmbedderClassLoader classLoader = new EmbedderClassLoader(this.getClass().getClassLoader());
    RunStoriesAsPaths mojo = new RunStoriesAsPaths() {

        @Override
        protected Embedder newEmbedder() {
            return embedder;
        }

        @Override
        protected EmbedderClassLoader classLoader() {
            return classLoader;
        }
    };
    String searchInDirectory = "src/test/java/";
    mojo.sourceDirectory = searchInDirectory;
    List<String> includes = asList("**/stories/*.story");
    mojo.includes = includes;
    List<String> excludes = asList();
    mojo.excludes = excludes;
    List<String> storyPaths = new StoryFinder().findPaths(searchInDirectory, includes, excludes);
    // When
    mojo.execute();
    // Then
    verify(embedder).runStoriesAsPaths(storyPaths);
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with StoryFinder

use of org.jbehave.core.io.StoryFinder in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldReportFailuresInRunningStoriesAsEmbeddables.

@Test(expected = MojoFailureException.class)
public void shouldReportFailuresInRunningStoriesAsEmbeddables() throws MojoExecutionException, MojoFailureException {
    // Given
    final EmbedderClassLoader classLoader = new EmbedderClassLoader(this.getClass().getClassLoader());
    RunStoriesAsEmbeddables mojo = new RunStoriesAsEmbeddables() {

        @Override
        protected Embedder newEmbedder() {
            return embedder;
        }

        @Override
        protected EmbedderClassLoader classLoader() {
            return classLoader;
        }
    };
    String searchInDirectory = "src/test/java/";
    mojo.sourceDirectory = searchInDirectory;
    List<String> includes = asList("**/stories/*.java");
    mojo.includes = includes;
    List<String> excludes = asList();
    mojo.excludes = excludes;
    List<String> classNames = new StoryFinder().findClassNames(searchInDirectory, includes, excludes);
    // When
    doThrow(new RuntimeException()).when(embedder).runAsEmbeddables(classNames);
    mojo.execute();
// Then fail as expected
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 15 with StoryFinder

use of org.jbehave.core.io.StoryFinder in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldAllowSpecificationOfStoryFinderClass.

@Test
public void shouldAllowSpecificationOfStoryFinderClass() {
    // Given
    AbstractEmbedderMojo mojo = new AbstractEmbedderMojo() {

        public void execute() throws MojoExecutionException, MojoFailureException {
        }
    };
    // When
    mojo.storyFinderClass = MyStoryFinder.class.getName();
    StoryFinder storyFinder = mojo.newStoryFinder();
    // Then
    assertThat(storyFinder.getClass().getName(), equalTo(MyStoryFinder.class.getName()));
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) Test(org.junit.Test)

Aggregations

StoryFinder (org.jbehave.core.io.StoryFinder)24 Test (org.junit.Test)22 Matchers.containsString (org.hamcrest.Matchers.containsString)15 EmbedderClassLoader (org.jbehave.core.embedder.EmbedderClassLoader)15 Embedder (org.jbehave.core.embedder.Embedder)3 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1