更好的RSpec MCP服务器
一个模型上下文协议(MCP)服务器,基于以下内容提供全面的RSpec指导、示例和最佳实践 更好的规格 指导方针。
概述
此MCP服务器使AI助手能够访问结构化的RSpec知识,并提供智能测试指导。它包括用于生成示例、验证代码、获取配置帮助和访问全面的Better Specs指南的工具。
特性
🛠️ 工具
get_rspec_guidance-获取特定主题的更好规格指导search_rspec_guidelines-使用关键字搜索更好的规范指南get_category_overview-获取特定类别中所有指南的概述generate_spec_example-根据最佳实践生成RSpec示例validate_spec_code-根据更好的规范指南验证RSpec代码get_rspec_configuration-获取配置模板和设置指南
📚 资源
- 更好的规格指南 -按类别完整收集指南
- 代码示例库 -不同规格类型的综合示例
- 反模式数据库 -常见错误以及如何避免
- 配置模板 -即用型RSpec配置
- 备忘单 -更好规格原则的快速参考
💬 提示
- 代码审查 -全面的RSpec代码审查模板
- 测试计划 -规划全面测试覆盖率的模板
- 重构 -改进现有测试套件的指南
- 项目设置 -新RSpec项目的完整设置指南
安装
先决条件
- Node.js 18+
快速设置(推荐)
使用npx(无需安装):
添加到您的MCP客户端配置中(例如,Claude Desktop):
{
"mcpServers": {
"better-rspec": {
"command": "npx",
"args": ["--yes", "better-rspec-mcp@latest"]
}
}
}备选方案:地方发展方案
- 克隆和安装依赖关系:
git clone
cd better-rspec-mcp
npm install- 构建项目:
npm run build- 配置MCP客户端:
{
"mcpServers": {
"better-rspec": {
"command": "node",
"args": ["/path/to/better-rspec-mcp/dist/index.js"]
}
}
}发展
项目结构
src/
├── index.ts # Entry point
├── server.ts # Main MCP server
├── types/ # TypeScript type definitions
├── tools/ # MCP tools implementation
│ ├── guidance.ts # RSpec guidance tools
│ ├── examples.ts # Example generation
│ ├── validation.ts # Code validation
│ └── configuration.ts # Configuration help
├── resources/ # MCP resources
├── prompts/ # MCP prompts
├── knowledge/ # Knowledge base system
└── utils/ # Utility functions
data/
├── guidelines/ # Better Specs guidelines (Markdown)
├── examples.json # Code examples database
├── antipatterns.json # Anti-patterns database
└── configurations.json # Configuration templates开发命令
# Development with hot reload
npm run dev
# Build for production
npm run build
# Run tests
npm test
# Lint code
npm run lint
# Type checking
npm run type-check添加新指南
- 在中创建一个新的Markdown文件
data/guidelines/:
---
title: "Your Guideline Title"
category: "naming|organization|expectations|data-setup|mocking|shared-examples|performance|configuration"
tags: ["tag1", "tag2"]
priority: "high|medium|low"
relatedGuidelines: ["other-guideline-ids"]
---
# Your guideline content here- 知识库将在服务器重新启动时自动加载。
添加新示例
将条目添加到 data/examples.json:
{
"id": "unique-example-id",
"title": "Example Title",
"description": "What this example demonstrates",
"specType": "model|request|system|service|job|controller|helper",
"scenario": "What you're testing",
"badCode": "Example of what not to do (optional)",
"goodCode": "Example of the right way",
"explanation": "Why this is better",
"tags": ["relevant", "tags"],
"complexity": "beginner|intermediate|advanced"
}更好的规格原则
此MCP服务器是围绕核心Better Specs原则构建的:
- 清楚地描述方法 -使用
.method对于类方法,#method例如方法 - 使用上下文 -以“何时”、“有”或“无”开头
- 保持描述简短 -40个字符以下,在较长的场景中使用上下文
- 每次测试一个期望值 -单元内测试(集成测试的例外情况)
- 测试所有案例 -快乐之路、边缘案例和失败
- 使用expect语法 -现代
expect().to而不是弃用should - 适当使用主题 -对于主要测试对象
- 使用let/let! -代替测试数据的实例变量
- 谨慎地嘲笑 -更喜欢真实的行为,只模仿外部边界
- 测试你所看到的 -专注于集成测试而非控制器单元测试
api参考
工具
get_rspec_guidance
获取特定主题的更好规格指南。
参数:
topic(字符串,必填)-RSpec主题以获取指导category(字符串,可选)-要关注的特定类别includeExamples(boolean,默认值:true)-是否包含示例complexity(字符串,可选)-复杂性级别过滤器
generate_spec_example
按照更好的规范指南生成RSpec示例代码。
参数:
specType(字符串,必填)-规格类型(型号、请求、系统等)scenario(string,必填)-要测试的内容includeSetup(布尔值,默认值:true)-包括设置代码style(字符串,默认值:“comprehensive”)-示例样式complexity(字符串,默认值:“中级”)-复杂性级别
validate_spec_code
根据更好的规范指南验证RSpec代码。
参数:
code(字符串,必填)-要验证的RSpec代码checkAll(boolean,默认值:true)-运行所有验证检查specificChecks(数组,可选)-要检查的特定规则returnSuggestions(布尔值,默认值:true)-包括建议
get_rspec_configuration
获取RSpec配置模板和设置指南。
参数:
type(字符串,必填)-配置类型(spec_helper、rails_helper等)projectType(字符串,默认值:“rails”)-项目类型includeComments(布尔值,默认值:true)-包括解释性注释features(阵列,可选)-要包括的其他功能
资源
better-specs://guidelines-所有指南better-specs://examples-所有示例better-specs://antipatterns-所有反模式better-specs://configurations-所有配置模板better-specs://cheatsheet-快速参考指南
提示
review_rspec_code-全面的代码审查plan_comprehensive_tests-测试计划指导refactor_test_suite-重构建议setup_rspec_project-项目设置指导
贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 运行linting和测试
- 提交拉取请求
