A Ruby library for mocking and stubbing objects in unit tests with a unified syntax for Minitest, Test::Unit, and RSpec.
Mocha is a Ruby library for creating mock objects and stubs in unit tests. It allows developers to replace real dependencies with controlled test doubles, isolating the code under test and verifying interactions. The library provides a unified syntax that works with popular Ruby test frameworks like Minitest, Test::Unit, and RSpec.
Ruby developers writing unit tests who need to mock external dependencies or stub methods for isolated testing. It's particularly useful for teams using Minitest, Test::Unit, or RSpec.
Developers choose Mocha for its clean, readable syntax and framework-agnostic approach to mocking. Unlike more complex alternatives, it focuses specifically on mocking and stubbing with minimal setup, making tests easier to write and maintain.
A mocking and stubbing library for Ruby
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Offers a simple, consistent API for both full and partial mocking, as demonstrated in the quick start examples with expects and stubs methods.
Integrates seamlessly with Minitest, Test::Unit, and RSpec via built-in adapters, with detailed installation instructions for each in the README.
Enables stubbing specific methods on real objects without replacing entire instances, shown in examples like stubbing total_weight on an Order object.
Provides warnings for common issues like stubbing non-existent methods, as mentioned in the configuration documentation to improve test robustness.
Explicitly stated in the README that Mocha does not attempt to be thread-safe, making it unreliable for testing multi-threaded code or running tests concurrently.
Focuses only on mocks and stubs, deliberately avoiding fakes and spies, which may require additional libraries for comprehensive testing needs.
Requires careful ordering when loading with test frameworks (e.g., after Minitest or RSpec), as improper setup can cause integration issues, noted in installation steps.