freerange

freerange/mocha

Ruby No license Dev Tools License not recognized by GitHub

A mocking and stubbing library for Ruby

1.3k stars
159 forks
recent
GitHub

1.3k

Stars

159

Forks

124

Open issues

30

Contributors

AI Analysis

Mocha is a mature Ruby library for mocking and stubbing in unit tests, with built-in support for Minitest and Test::Unit and compatibility with RSpec, Cucumber, and Rails. It serves developers writing Ruby tests who need predictable mock/stub behavior without faking or spying. It is most valuable for teams using Ruby's test frameworks; it is not a general-purpose testing tool and not needed for non-Ruby projects.

Dev Tools Testing Tool Discovery value: 3/10
Documentation 8/10
Activity 8/10
Community 7/10
Code quality 7/10

Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.

Overall score 8/10

AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.

mocking stubbing ruby-testing minitest test-doubles
Actively maintained Well documented Niche/specialized use case Beginner friendly Production ready
Deep Analysis · Based on README and public signals
1w ago

Ruby mocking library with 18 years of stable maintenance, focused narrowly on mocks and stubs for standard test frameworks

Mocha is a mature Ruby mocking and stubbing library originally created in 2008, designed for use with Minitest, Test::Unit, RSpec, and Cucumber. It deliberately constrains itself to mocks and stubs only—not fakes or spies—maintaining a focused, simple API. Adoption appears concentrated in Ruby on Rails projects and organizations using traditional Ruby test frameworks. The project receives regular maintenance but shows modest growth, suggesting it serves an established niche rather than expanding into new domains.

Origin

Created in October 2008, Mocha predates many modern Ruby testing patterns. It emerged alongside Test::Unit and Minitest as Rails testing evolved, and has maintained API stability over 18 years. The deliberate scope constraint (mocks/stubs only) reflects a philosophical design decision made early and largely upheld.

Growth

Mocha gained 1,285 GitHub stars over its lifetime but shows zero stars gained in the last 7 days as of June 2026, indicating mature adoption plateau rather than new user acquisition. Growth appears to have stabilized around a stable installed base of Rails/Ruby projects. The library benefits from being bundled or recommended in standard Rails and RSpec workflows, but attracts few new adopters seeking novel functionality.

In production

Adoption not verified through quantitative evidence in repository metadata. However, Mocha's presence in Rails community documentation, RSpec's built-in adapter, and long tenure suggests entrenched use in existing Rails applications. Likely used by substantial but aging codebases that adopted it 10+ years ago rather than new greenfield projects.

Code analysis
Architecture

Based on README, Mocha provides a unified syntax for mocking and stubbing with adapter integrations for multiple test frameworks. It appears to use method interception on real objects and abstract mock objects. Likely uses Ruby's metaprogramming (method_missing, refinements, or similar) to achieve this. README emphasizes simplicity and readability in API design but does not document internal architecture.

Tests

Not documented in README. CircleCI badge indicates CI is active, but coverage metrics are not mentioned.

Maintenance

Last push June 10, 2026 (21 days before analysis date), indicating active maintenance. CircleCI integration suggests continuous integration is enabled. No evidence of backlog collapse or abandonware status. However, lack of recent star growth and stable version numbers suggest incremental maintenance rather than feature-driven development.

Honest verdict

ADOPT IF: you maintain or contribute to existing Rails/Ruby codebases already using Mocha, or if you require tight integration with Test::Unit/Minitest/Cucumber in a conservative organization. The library is stable, well-integrated, and actively maintained. AVOID IF: you are starting a new Ruby project and can use RSpec or Minitest's built-in mocking, which eliminates a dependency. Also avoid if you need spy or fake object semantics; Mocha explicitly does not support these. MONITOR IF: your project inherits a large Mocha-dependent test suite; track whether maintainers continue bi-annual updates and CircleCI health, as long-term maintenance is the primary value proposition.

Independent dimensions

Mainstream potential

3/10

Technical importance

5/10

Adoption evidence

4/10

Risks
  • Limited growth suggests declining new adoption; future maintainability depends on whether core team continues or community volunteers step up.
  • Deliberate scope constraint (no spies/fakes) may frustrate teams adopting modern testing patterns that expect these capabilities.
  • Ruby ecosystem fragmentation across RSpec, Minitest, Test::Unit, and Cucumber means Mocha must maintain multiple integrations; adapter breakage in test framework updates could strand users.
  • No documented production usage at scale; adoption estimates rely on inference from Rails community patterns rather than published case studies.
  • Long API stability is both strength and weakness; lack of major releases may indicate stagnation rather than maturity to teams seeking active development signals.
Prediction

Mocha will likely remain a stable, slow-growing dependency in legacy and conservative Ruby projects, with adoption percentage declining relative to new Ruby codebases as alternatives (native test framework mocks) mature. Maintenance will probably continue at minimal, reactive levels unless ecosystem disruption (e.g., Rails test framework overhaul) forces change.

0 found this helpful

Newsletter

Get analyses like this every Monday

Free weekly digest of the most interesting open-source discoveries.

Languages

Ruby
100%

Information

Language
Ruby
License
NOASSERTION
Last updated
4w ago
Created
216mo ago
Analyzed with
anthropic/claude-haiku-4-5

Stars over time

Loading…

Contributors over time

Top 100 contributors only — repos with more will plateau at 100.

Loading…

Recent releases

No releases published yet.

Similar repos

mochajs

mochajs/mocha

Mocha is a mature, widely-adopted test framework for Node.js and browsers,...

23k JavaScript Dev Tools
bblimke

bblimke/webmock

WebMock is a Ruby library for stubbing and setting expectations on HTTP...

4.1k Ruby Dev Tools
devlooped

devlooped/moq

Moq is a mocking framework for .NET that enables developers to create mock...

6.4k C# Dev Tools
dashbitco

dashbitco/mox

Mox is a library for creating concurrent mocks in Elixir based on explicit...

1.4k Elixir
dreamhead

dreamhead/moco

Moco is a lightweight, easy-to-configure stub server framework primarily for...

4.4k Java Dev Tools
vs. alternatives
RSpec mocks (built-in)

RSpec includes mock functionality natively; Mocha offers an alternative adapter but does not replace RSpec's built-in doubles. RSpec has likely captured more mindshare in modern Rails projects.

Minitest (Minitest::Mock built-in)

Minitest includes basic mocking; Mocha layers additional syntax and features on top but is optional. Projects using bare Minitest may not adopt Mocha.

flexmock (Ruby alternative)

Comparable scope and maturity; both serve traditional Ruby mocking niche. No indication either has dominated the other; appear to coexist.

mochajs/mocha (JavaScript)

Mocha's JavaScript namesake (22,969 stars) dominates test framework selection in JavaScript; Ruby Mocha occupies much smaller absolute user base. Different ecosystems, not direct competitors.

Elixir mox (1,396 stars)

Similar scope (mocking/stubbing focus) in another language. Comparable star count suggests similar adoption levels within respective ecosystems.