Library for stubbing and setting expectations on HTTP requests in Ruby.
open sourceMITself-hostablefree
WebMock stubs HTTP requests in Ruby tests at the level of the HTTP client libraries, so tests keep working when you change HTTP library. It matches requests by method, URI, headers and body (treating equivalent encodings of a URI or header as the same), lets you set expectations that a request was made, and by default blocks real network connections in tests. It works with RSpec, Minitest and Test::Unit and supports Net::HTTP (and libraries built on it such as HTTParty), HTTPClient, Excon, Curb, Typhoeus, http.rb, httpx, Patron, Manticore and Async::HTTP. VCR can use it to record and replay requests.
Problems it solves
- my Ruby tests make real HTTP calls to third-party APIs and are slow and flaky
- fake the response from Stripe or GitHub's API in an RSpec test
- make sure a test fails if any code tries to hit the real network
- assert that my code sent a POST with the right JSON body
- simulate a timeout or a 500 from an external API in tests
Features
- stubs at the HTTP client library level
- request matching on method, URI, headers and body
- request expectations
- blocks real connections by default
- RSpec, Minitest and Test::Unit support
Capabilities
| Has official SDKs | plan not known |
|---|
Alternatives
The same job
These do what WebMock does.
- VCR Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
