CheckOps home

Tools directory

W

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Blocks real HTTP: Unexpected network calls fail tests.
  2. Flexible matching: Headers, query, body, JSON and regex.
  3. Request expectations: Assert requests were made, with counts.
  4. Many clients: Net::HTTP, Faraday adapters, Typhoeus, Excon, HTTP.rb and more.

Pros

  1. Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 14 October 2026.
  3. Community: About 4,100 GitHub stars.

Cons

  1. Manual stubs: Large APIs need many stubs (VCR records them instead).
  2. Library coverage: Uncommon HTTP clients may not be intercepted.
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.

  1. Ruby projects needing strict, explicit HTTP stubs.
  2. 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.