A Ruby library for stubbing and setting expectations on HTTP requests in tests.
WebMock is a Ruby library for stubbing and setting expectations on HTTP requests in tests. It intercepts HTTP requests at the client library level, allowing developers to simulate external API responses, control network behavior, and verify that their code makes the expected HTTP calls without relying on live services.
Ruby developers writing tests for applications that make HTTP requests, especially those using RSpec, MiniTest, or Test::Unit and needing reliable, fast, and deterministic test suites.
Developers choose WebMock for its deep integration with Ruby HTTP clients, flexible request matching, and seamless support for major testing frameworks, making it the go-to solution for mocking HTTP interactions in Ruby tests.
Library for stubbing and setting expectations on HTTP requests in Ruby.
Supports over 10 popular Ruby HTTP clients including Net::HTTP, HTTParty, and Excon, as listed in the README, ensuring broad compatibility without switching libraries.
Matches requests by method, URI (with regex and RFC 6570 templates), headers, and body (JSON, XML, etc.), demonstrated in examples like stubbing with partial hashes or lambda blocks.
Out-of-the-box support for RSpec, MiniTest, and Test::Unit with simple require statements, as shown in setup instructions for each framework.
Allows custom responses, errors, timeouts, and Rack app delegation, with features like chained responses and dynamic evaluation from blocks or lambdas.
The README warns that WebMock breaks Net::HTTP's default behavior by not connecting on start, requiring manual :net_http_connect_on_start configuration, which adds complexity.
Only works with the explicitly listed HTTP libraries; if a project uses an unsupported client, WebMock cannot intercept requests, forcing workarounds or alternative tools.
Managing stub precedence and clearing history requires careful setup (e.g., using WebMock.reset!), as the last declared stub wins and stale stubs can cause test pollution.
A library for generating fake data such as names, addresses, and phone numbers.
Acceptance test framework for web applications
A library for setting up Ruby objects as test data.
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.