每个故事都与问题跟踪器上的问题、专业文档、人员、外部资源等相关联。
记录这些额外元数据的最佳位置不是埋藏在公司维基上的 Word 文档中,而是埋藏在故事本身中。
你添加到故事中的元数据类型由你决定 - 只需在引擎 InfoDefinition 的 info 参数中添加要添加的属性的名称,并在 InfoProperty 对象内使用 StrictYAML 验证器指定元数据的结构。
此示例展示了如何将一系列 JIRA 票证和功能名称作为故事的元数据添加,并根据 JIRA 票证号过滤要播放的故事。
代码示例
example.story
Build city:
about: Build a great city. The best.
project jiras: JIRA-123, JIRA-124
features: files, creating
steps:
- Reticulate splines
Live in city:
project jiras: JIRA-789
features: other
steps:
- Kick llama's ass
variations:
Build llama zoo:
project jiras: JIRA-123
features: zoo
following steps:
- Kick llama's ass
带代码
from hitchstory import StoryCollection, BaseEngine, InfoDefinition, InfoProperty
from strictyaml import Map, Str, CommaSeparated, Optional
from pathlib import Path
from ensure import Ensure
from code_that_does_things import reticulate_splines, kick_llamas_ass
class Engine(BaseEngine):
info_definition=InfoDefinition(
project_jiras=InfoProperty(schema=CommaSeparated(Str())),
features=InfoProperty(schema=CommaSeparated(Str())),
)
def reticulate_splines(self):
print('reticulate splines')
def kick_llamas_ass(self):
print('kick llamas ass')
story_collection = StoryCollection(Path(".").glob("*.story"), Engine())
运行所有故事
story_collection.ordered_by_name().play()
将输出
RUNNING Build city in /path/to/working/example.story ... reticulate splines
SUCCESS in 0.1 seconds.
RUNNING Live in city in /path/to/working/example.story ... kick llamas ass
SUCCESS in 0.1 seconds.
RUNNING Live in city/Build llama zoo in /path/to/working/example.story ... kick llamas ass
kick llamas ass
SUCCESS in 0.1 seconds.
仅运行过滤后的故事
story_collection.filter(lambda story: "JIRA-124" in story.info.get('project_jiras')).ordered_by_name().play()
将输出
RUNNING Build city in /path/to/working/example.story ... reticulate splines
SUCCESS in 0.1 seconds.
信息
Ensure([story.info['project_jiras'] for story in story_collection.ordered_by_name()]).equals(
[["JIRA-123", "JIRA-124"], ["JIRA-789", ], ["JIRA-123"]]
)
可执行规范
从 metadata.story storytests 自动生成的文档。