Skip to content

Commit

Permalink
Requirements with narratives are now correctly merged with outcomes o…
Browse files Browse the repository at this point in the history
…f tests from those directories
  • Loading branch information
jan-molak committed Feb 2, 2024
1 parent e96af57 commit 4d31b5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public Requirement readRequirementFrom(File requirementDirectory) {

return requirementWithNarrative(
requirementDirectory,
humanReadableVersionOf(requirementDirectory.getName()),
requirementDirectory.getName(),
requirementNarrative.get()
);
}
Expand All @@ -612,12 +612,14 @@ public Optional<Requirement> readRequirementsFromStoryOrFeatureFile(File storyFi
java.util.Optional<RequirementDefinition> narrative = (type == FeatureType.STORY) ? loadFromStoryFile(storyFile) : loadFromFeatureFile(storyFile);

String storyPath = requirementsConfiguration.relativePathOfFeatureFile(storyFile);
String storyName = storyNameFrom(narrative, type, storyFile);
String storyFileName = storyFile.getName().substring(0, storyFile.getName().lastIndexOf("."));
Requirement requirement;
if (narrative.isPresent()) {
requirement = leafRequirementWithNarrative(storyName,
requirement = leafRequirementWithNarrative(
storyFileName,
storyPath,
narrative.get()).withType(type.toString());
narrative.get()).withType(type.toString()
);

if (narrative.get().background().isPresent()) {
requirement = requirement.withBackground(narrative.get().background().get());
Expand All @@ -626,7 +628,7 @@ public Optional<Requirement> readRequirementsFromStoryOrFeatureFile(File storyFi
requirement = requirement.withNoScenarios();
}
} else {
requirement = storyNamed(storyName, storyPath).withType(type.toString());
requirement = storyNamed(storyFileName, storyPath).withType(type.toString());
}

return Optional.of(requirement.definedInFile(storyFile));
Expand All @@ -636,21 +638,6 @@ public Optional<Requirement> readRequirementsFromStoryOrFeatureFile(File storyFi
}
}

private String storyNameFrom(java.util.Optional<RequirementDefinition> narrative, FeatureType type, File storyFile) {
if (narrative.isPresent() && isNotBlank(narrative.get().getTitle().orElse(""))) {
return narrative.get().getTitle().get();
} else {
if (isSnakeCase(storyFile.getName())) {
return storyFile.getName().replace(type.getExtension(), "").replace("_", " ");
} else {
String storyNameWithoutExtension = storyFile.getName().replace(type.getExtension(), "");
String snakeCaseStoryName = inflection().underscore(storyNameWithoutExtension);
return inflection().of(snakeCaseStoryName).asATitle().toString();
}
}

}

private boolean isSnakeCase(String name) {
return name.contains("_");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,6 @@ private Requirement nonLeafRequirementFrom(PathElements relativePath, int maxReq
.withParent(parentPath);
}

// fixme: duplicated from AbstractRequirementsTagProvider
// as it is not the parent of this class (should it be?).
// This is to make the discovered requirements compatible with the results
// of the FileSystemRequirementsTagProvider.
protected String humanReadableVersionOf(String name) {
String underscoredName = Inflector.getInstance().underscore(name);
return Inflector.getInstance().humanize(underscoredName);
}

private PathElements relativePathFrom(PathElements pathElements) {
List<String> rootPackageElements = rootPackageElements();
List<PathElement> relativePathElements = new ArrayList<>(pathElements);
Expand Down

0 comments on commit 4d31b5e

Please sign in to comment.