← Graph

WebMock

tool 9 connections

Ruby gem created by Bartosz Blimke during a one-day company hackathon at New Bamboo in 2009 to address his own needs as a Ruby developer. Two core capabilities: (1) stub HTTP requests — declare fake responses so no real connection is made — and (2) verify that HTTP requests (stubbed or real) have been executed. Offers an HTTP-client-agnostic DSL for stubbing and verification, follows a stub–execute–verify paradigm borrowed from the Java Mockito framework, and separates the stubbing phase from verification (unlike RSpec's single expect for both). Supports stubbing timeouts, basic auth, replaying raw curl-recorded responses, request callbacks (used by VCR under the hood), and prints helpful stubbing instructions when a request doesn't match. Supports all popular Ruby HTTP clients and all major Ruby testing frameworks. Internally uses adapters that subclass each HTTP client and monkey-patch request handling: build request, create a request signature in the request registry, check the global stub registry for a matching request stub, return a fake response or raise with stubbing instructions (real connections blocked by default), run registered callbacks and middleware. Adapter enabling swaps the original constant for the instrumented copy via constant replacement, so it can be cleanly reverted. Downloaded >250M times, ~4,000 GitHub stars, 260+ contributors over 15 years, used by ~8,000 registered gems and thousands of public GitHub projects. Has no hardcoded version restrictions on the HTTP clients it wraps — tests always run against the latest gem versions. Inspired web-mocking libraries in other languages.

created
2009
license
open-source
category
library
language
Ruby
downloads
250M+
dependents
~8000 gems
contributors
260+
github_stars
~4000
about
WebMock tool
Entire talk covers WebMock's features and internal architecture.
about
WebMock tool
Takeaway specifically about using WebMock as a safety net on legacy applications.
about
WebMock tool
Takeaway is about using WebMock stubs as a stand-in for unreleased or unavailable third-party APIs.
about
WebMock tool
Question asks whether WebMock supports contract testing.
about
WebMock tool
Question asks how WebMock keeps up with changes in the HTTP-client libraries it monkey-patches.
tool WebMock
related_to
FakeWeb tool
WebMock was inspired by and designed to overcome the limitations of FakeWeb (limited request matching, Net::HTTP only).
tool WebMock
related_to
Mockito tool
WebMock's stub–execute–verify paradigm was borrowed from Mockito.
tool VCR
uses
WebMock tool
VCR uses WebMock's request callbacks under the hood to record HTTP traffic.
works_on
WebMock tool
Author and single maintainer of WebMock for 15 years.
role: author and sole maintainer

Provenance

Read by
7 extractions