Claude Code assert-specific-error-in-tests 技能:断言准确的 Rust 错误
EnglishClaude Code 安装步骤
- 打开 GitHub 固定提交的 `.claude/skills/assert-specific-error-in-tests/SKILL.md`,核对内容与使用条件。
- 在自己的项目中创建 `.claude/skills/assert-specific-error-in-tests/`,把核对后的文件保存为 `.claude/skills/assert-specific-error-in-tests/SKILL.md`。
- 在该项目根目录启动 Claude Code,在斜杠菜单中选择 `/assert-specific-error-in-tests`。
中文摘要
用错误枚举和相关字段验证失败路径,区分目标错误与其他可能失败原因。
SKILL.md 中文导读
可复现示例
调用 /assert-specific-error-in-tests。用下面虚构的房间编号约定写失败断言。
Rust validator `parse_room_code` | length expected `4` | input `AB` length `2`
expected result `RoomCodeError::InvalidLength { expected: 4, got: 2 }`
other possible error `RoomCodeError::UnsupportedCharacter`工作步骤
- 确认输入要触发的错误。
- 用模式匹配核对错误变体与字段。
- 确认其他错误无法使该用例通过。
验收方法
对 `AB` 匹配 `RoomCodeError::InvalidLength { expected: 4, got: 2 }`。测试遇到 `RoomCodeError::UnsupportedCharacter` 时会失败。
GitHub 原文 · 更新日期
适用环境
可编写 Rust 测试的 Claude Code 项目。准备当前错误类型与输入用例。
常见问题
只用 is_err 能验证长度检查吗?
需要断言实际错误变体,必要时核对字段,使不同失败原因无法替代目标错误。