跳到内容

故事成功运行时的执行过程 - 即故事运行期间没有抛出异常。

代码示例

example.story

Create files:
  steps:
    - Create file
    - Create file: step2.txt
    - Create file:
        file name: step3.txt
        content: third step
engine.py

from hitchstory import BaseEngine


class Engine(BaseEngine):
    def create_file(self, file_name="step1.txt", content="example"):
        with open(file_name, 'w') as handle:
            handle.write(content)

    def on_success(self):
        print("splines reticulated")

        with open("ranstory.txt", 'w') as handle:
            handle.write(self.story.name)

带有代码

from hitchstory import StoryCollection
from pathlib import Path
from engine import Engine
StoryCollection(Path(".").glob("*.story"), Engine()).named("Create files").play()

将输出

RUNNING Create files in /path/to/working/example.story ... splines reticulated
SUCCESS in 0.1 seconds.

文件 step1.txt 现在应该包含

example

文件 step2.txt 现在应该包含

example

文件 step3.txt 现在应该包含

third step

文件 ranstory.txt 现在应该包含

Create files

可执行规范

success.story storytests 自动生成的文档。