From 6bd2055fbcb2be3ecee250b008503cf2dae4680d Mon Sep 17 00:00:00 2001 From: Ryota Ikezawa Date: Mon, 16 Mar 2026 16:33:58 +0900 Subject: [PATCH] feat(claude): add dedicated TDD rule with Red-Green-Refactor discipline (#90) Extract TDD guidance from development-principles.md into a dedicated tdd.md rule file with detailed Red-Green-Refactor cycle, granularity rules, uncertainty guidance, and exceptions for non-testable contexts. Co-Authored-By: Claude Opus 4.6 --- dot_claude/rules/development-principles.md | 3 +- dot_claude/rules/tdd.md | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 dot_claude/rules/tdd.md diff --git a/dot_claude/rules/development-principles.md b/dot_claude/rules/development-principles.md index 1529c8c..082f704 100644 --- a/dot_claude/rules/development-principles.md +++ b/dot_claude/rules/development-principles.md @@ -6,8 +6,7 @@ alwaysApply: true ## Test-Driven Development -- Write tests first, then implementation -- Red → Green → Refactor cycle +- See `tdd.md` for detailed TDD rules ## Simplicity diff --git a/dot_claude/rules/tdd.md b/dot_claude/rules/tdd.md new file mode 100644 index 0000000..7afde17 --- /dev/null +++ b/dot_claude/rules/tdd.md @@ -0,0 +1,34 @@ +--- +alwaysApply: true +--- + +# Test-Driven Development + +## Red-Green-Refactor Cycle + +1. **Red**: Write a failing test that describes the desired behavior +2. Confirm the test fails for the expected reason +3. **Green**: Write the minimal implementation to make the test pass +4. Confirm all tests pass +5. **Refactor**: Improve code quality while keeping tests green + +## Rules + +- Never write production code without a corresponding failing test +- One test = one behavior. Keep incremental steps small +- Run tests after each step; show Red before Green +- Do not skip the Red step — a test that has never failed proves nothing + +## When Uncertain + +- Ask the user about test location, framework, or naming conventions rather than guessing +- If multiple test patterns exist in the project, ask which to follow + +## Exceptions + +TDD does not apply to contexts without test frameworks: + +- Dotfiles configuration and templates +- CI/CD pipeline definitions +- Shell scripts without a test harness +- Declarative config files (JSON, YAML, TOML)