travisjeffery

timecop

travisjeffery

A gem providing "time travel", "time freezing", and "time acceleration" capabilities, making it simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.

AI 简介

Timecop 是一个 Ruby 测试辅助库,用于模拟时间行为以简化时间敏感逻辑的单元测试。它提供时间冻结(固定当前时间)、时间旅行(跳转到指定时间点并继续推进)和时间加速(按比例缩放时间流逝)三大核心能力,统一拦截 Time.now、Date.today、DateTime.now 和 Process.clock_gettime 等系统时间调用。无外部依赖,兼容纯 Ruby 项目与 Rails 应用,支持嵌套时间操作和多种时间参数格式。适用于需要验证时效性业务逻辑(如过期判断、定时任务、账单周期等)的测试场景。

Ruby
MIT License
3.4k
Stars
229
Forks
26
Watchers
6
Issues

Star 增长

今日0
近 7 天0
近 30 天0
综合评分59.09
默认分支master