录制与回放
sh
ruby-anything app record <repo> --http --inputs rails/port/app-cases/inputs.jsonl \
--db-reset "<command that resets the test database>" -- <command that starts the original>
ruby-anything app replay <repo> --original # the original must pass its own recording 100%
启动命令读取 PORT,或者使用 {port}(端口固定时用 --port)。不带参数的 GET 路由会从代码中自动发现;其余的都来自 inputs.jsonl(每行一个 {"name", "method", "path", "headers", "body"})。
每个用例保存状态码、重定向、JSON 和页面文本。每个 GET 请求都会运行两次:两次运行之间发生变化的值会变成 [..] 通配符。
副作用
忘记扣款或忘记发送收据的移植版必须失败:
sh
ruby-anything app record <repo> --http --inputs ... \
--effect-env PAYMENT_API_URL=http,SMTP_HOST=smtp_host,SMTP_PORT=smtp_port \
--db-dump "sqlite3 db.sqlite3 .dump" --db-reset "<reset command>" -- <start command>
--effect-env NAME=KIND 会把应用自身的配置指向一个本地替身服务,由它记录每一次调用:http、smtp、smtp_host 和 smtp_port。--db-dump 在每个非 GET 请求之后运行,导出的数据行也是用例的一部分。回放时会为 Rails 应用设置相同的变量,Rails 应用也必须读取它们。
CLI 应用
sh
ruby-anything app record <repo> --cli --inputs rails/port/app-cases/cli.jsonl -- python tool.py
在 cli.jsonl 中列出各次调用({"name", "args": [...], "stdin", "env"})。每次调用都会在仓库的临时副本中运行两次;退出码、stdout、stderr 以及它写入的文件构成一个用例。
回放
sh
ruby-anything app replay <repo> # every case through Rails
ruby-anything app replay <repo> --case <name> # one case
页面按可见文本比较,所以标记结构是全新的,但每个标题、标签、价格和空状态都必须保留。JSON 必须完全一致。