CheckOps
WebMock
WebMock is an MIT-licensed Ruby library for stubbing and setting expectations on HTTP requests, supporting many HTTP clients and blocking real network access in tests.
- Unit Testing
- Ruby
- Open source
- Free
- Mocking
- API mocking
- Library
- Unit testing
- Integration testing
- API & contract testing
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
WebMock is a library for stubbing and setting expectations on HTTP requests in Ruby. Once enabled, it blocks all real network connections by default, so tests fail fast if code tries to reach the internet unexpectedly, and you explicitly stub the requests you expect.
Stubs are declared with stub_request(:get, "https://api.example.com/users/1"), optionally matching headers, query parameters and bodies (including JSON and hash matchers or regular expressions), and returning a status, headers and body, raising exceptions or simulating timeouts. Expectations such as expect(a_request(:post, url).with(body: {...})).to have_been_made.once verify outgoing calls. It supports many HTTP libraries, including Net::HTTP, HTTPClient, Patron, EM-HTTP-Request, Curb, Typhoeus, Excon, HTTP.rb and Manticore, and works with RSpec, Minitest and Test::Unit. VCR commonly uses WebMock as its hook. Version 3.34.0 was released on 14 October 2026.
The source code is at bblimke/webmock on GitHub under the MIT licence, with about 4,100 stars; the most recent commit was on 14 October 2026.
Features
- Blocks real HTTP: Unexpected network calls fail tests.
- Flexible matching: Headers, query, body, JSON and regex.
- Request expectations: Assert requests were made, with counts.
- Many clients: Net::HTTP, Faraday adapters, Typhoeus, Excon, HTTP.rb and more.
Pros
- Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 14 October 2026.
- Community: About 4,100 GitHub stars.
Cons
- Manual stubs: Large APIs need many stubs (VCR records them instead).
- Library coverage: Uncommon HTTP clients may not be intercepted.
Usage and Links (Example)
require "webmock/rspec"
RSpec.describe PaymentClient do
it "creates a charge" do
stub_request(:post, "https://api.example.com/charges")
.with(body: { amount: 100 }.to_json, headers: { "Content-Type" => "application/json" })
.to_return(status: 201, body: { id: "ch_1" }.to_json)
expect(PaymentClient.new.charge(100)).to eq("ch_1")
expect(a_request(:post, "https://api.example.com/charges")).to have_been_made.once
end
end
Resources:
Pricing
WebMock is free and open source under the MIT licence.
Recommended for?
- Ruby projects needing strict, explicit HTTP stubs.
- Teams combining WebMock with VCR for recorded interactions.
Conclusion
WebMock is the standard Ruby HTTP stubbing library, valued for its strict no-network default and broad client support.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with WebMock side by side.
VVCR (Ruby)VCR is a Ruby library that records your test suite's HTTP interactions to cassettes and replays them in future runs for fast, deterministic, accurate tests; it uses the Hippocratic License 2.1.Compare with WebMock
RRSpecRSpec is the MIT-licensed behaviour-driven testing framework for Ruby, made up of rspec-core, rspec-expectations and rspec-mocks, and widely used with Rails via rspec-rails.Compare with WebMock
MMinitestMinitest is an MIT-licensed, fast and lightweight Ruby testing library providing xUnit-style tests, a spec DSL and benchmarks; it is the default testing framework in Ruby on Rails.Compare with WebMock
NNockHTTP server mocking and expectations library for Node.js.Compare with WebMock
Rresponsesresponses is an Apache-2.0 Python library from Sentry for mocking the Requests HTTP library, letting tests register fake responses, match request details and assert on calls.Compare with WebMock
WWireMockA tool for mocking HTTP services.Compare with WebMock