Reputation: 2724
I need to have my mystory.story file and MyStory.java in different folders. Below is my configuration,
@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
// where to find the stories
.useStoryLoader(new LoadFromClasspath(this.getClass()))
// CONSOLE and TXT reporting
.useStoryReporterBuilder(
new StoryReporterBuilder().withDefaultFormats()
.withFormats(Format.CONSOLE, Format.HTML));
}
// Here we specify the steps classes
@Override
public List<CandidateSteps> candidateSteps() {
// varargs, can have more that one steps classes
return new InstanceStepsFactory(configuration(), new SurveySteps())
.createCandidateSteps();
}
That is i need to use the folder structure as
test
|_config
|_MyStory.java
|_stories
|_my_Story.story
instead of,
test
|_MyStory.java
|_my_Story.story
How can i achieve it ?
Upvotes: 4
Views: 3729
Reputation: 1098
You can override default story path resolver, ex:
@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryPathResolver(new StoryPathResolver() {
@Override
public String resolve(Class<? extends Embeddable> embeddableClass) {
return "_stories/_my_Story.story";
}
})
}
(Of course it is better to create somewhere outside class and use it here, not anonymous). But keep in mind that if you do so, you need also specify explicitly name of story file, reuse somehow jbehave functionality that convert 'MyClass' to 'my_class' or create your own strategy.
Upvotes: 1
Reputation: 4901
I assume you use JUnitStory
.
I think the only thing you have to do is to put on the classpath both directories: test/config
and test/stories
. The default story resolver is org.jbehave.core.io.UnderscoredCamelCaseResolver
this will create a story path like "org.jbehave.core.ICanLogin.java" -> "org/jbehave/core/i_can_login.story"
, and this will be loaded using the org.jbehave.core.io.LoadFromClasspath
because that's the default resource loader. Since the src/stories
directory is on the classpath, the resource loader will find it. Note that this requires that the classes and stories are placed in the same "package", that is if the class is com.foo.Bar
(placed in src/config
) then you have to place the corresponding story into com/foo/Bar.story
(in src/stories
). This is similar to separating resource files and java files into separate folders.
Upvotes: 1