webmockr (development version)
-
RequestPatternis no longer exported (#145) - Gains new function
request_registry_filter()to filter requests that have matched stubs. can be used to introspect requests made during tests, or outside of tests (#154)
webmockr 2.1.0
CRAN release: 2025-06-29
MINOR IMPROVEMENTS
- Many previously exported R6 classes that are internal use only are no longer exported.
RequestPatternis still exported in this version, but will not be in the next version - Improve how httr2 mocking is set (#114) thanks @hadley
- Correctly check that vcr is loaded, not attached (#142) thanks @hadley
- Update tests to use testthat edition 3, and run in parallel
- Moved
crulfrom Imports to Suggests. replace use of acrulfunction with an equivalent fromcurlsocrulis truly not needed to runwemockrunless usingcrul
webmockr 2.0.0
CRAN release: 2025-02-11
BREAKING CHANGES
- Previous to this version when stubs were constructed starting with
stub_request()if an error occurred in a pipe chain, or non-pipe flow, the stub prior to the error remained. This was not correct behavior from a logical perspective - i.e., one would expect if an error occurred that thing they were trying to do did not stick around. The new behavior as of this version deletes the stub upon any error during its creation. Under the hood we’re usingwithCallingHandlersto handle different types of errors, throw warnings, etc.
NEW FEATURES
- Partial matching. New functions
including()andexcluding()for use withwi_th()support partial for bodies and queries (header partial matching was already supported without any additional steps). See?partial. This makes it slightly to a whole lot easier to do matching depending on the HTTP request your trying to match (e.g., let’s say you’re trying to match against a query with 20 parameters - if you can match uniquely to it with 1 or 2 of those params, then you’re all set) (#38) - Basic auth internal work for
RequestPattern. Shouldn’t change behavior (#133) - New features for supporting request body diffs. There are two ways to use request body diffing. First, you can toggle it on/off globally like
webmockr_configure(show_body_diff = TRUE)orwebmockr_configure(show_body_diff = FALSE). Second, a new functionstub_body_diff()is a standalone function that compares by default the last stub created and the last http request made - but you can pass in any stub and http request. Note that body diffing functionality requires the suggested packagediffobj(#126) - As part of the above body diffing functionality, two new functions are offered:
last_request()andlast_stub(), which get the last http request made and the last webmockr stub created, respectively. (#126)
MINOR IMPROVEMENTS
- Removed
global_stubsfield from theStubRegistryclass as it was completely unused (holdover from the initial port from Ruby). Should not impact users at all. (#127) - Wider use of
rlangfunctions throughout the package for nicer assertions and condition handling. This change alters the main error message you get when there’s no match to registered stubs. Hopefully this feels like an improvement to you; let me know. (#129) -
StubRegistrygains new methodis_stubbed()to check if a stub is in the stub registry
webmockr 1.0.0
CRAN release: 2024-07-23
NEW FEATURES
-
webmockrnow supports thehttr2library, in addition tohttrandcrul. Note that you’ll see different behavior fromhttr2relative to the other 2 http clients because it turns http errors (http statuses 400 and above) into R errors (#122) -
webmockrcan now mock async http requests withcrul(w/crulv1.5 or greater). no change was required inwebmockrfor this to happen. a PR was merged incrulto hook intowebmockr. there’s no support for async inhttras that package does not do any async and no support inhttr2becausereq_perform_paralleldoes not have a mocking hook as doesreq_perform(#124)
webmockr 0.9.0
CRAN release: 2023-02-28
BUG FIXES
-
to_return()supports returning multiple responses to match many requests to the same matching stub. however, the internals were broken for this, but is now fixed (#115) thanks @kenahoo for the report - matching stubs with specifying a request body to match on (e.g.,
stub_request('post', 'https://httpbin.org/post') %>% wi_th(body = list(a=5))) was not working in some cases; internal matching logic was borked. now fixed. (#118) thanks @konradoberwimmer for the report - The
statusparameter into_return()was documented to accept an integer, but it errored when an integer was passed (e.g.,to_return(status=200L)). This bug is now fixed (#117) thanks @maelle for the report
MINOR IMPROVEMENTS
- Config options changes (see
webmockr_configure()). Three options that were present but not implemented are now removed:show_body_diff,query_values_notation,net_http_connect_on_start. One option that was present but not implemented yet is now implemented:show_stubbing_instructions(#27) (#120)
DOCUMENTATION
-
StubCounteradded to pkgdown docs page at https://docs.ropensci.org/webmockr/reference/StubCounter.html (#119) @maelle
webmockr 0.8.0
CRAN release: 2021-03-14
MINOR IMPROVEMENTS
- to re-create http response objects for both httr and crul we were using the url from the request object; now we use the url from the response object, BUT if there is no url in the response object we fall back to using the url from the request object (#110) (#113)
- improve docs: add further explanation to manual files for both
to_raise()andto_return()to explain the difference between them and when you may want to use them (#100)
webmockr 0.7.4
CRAN release: 2020-12-09
MINOR IMPROVEMENTS
- to support vcr being able to recreate httr objects fully (see github issue ropensci/vcr#132) we needed to handle additional parts of httr request objects: fields and output - with this change vcr should return objects much closer to what real httr requests return (#109)
BUG FIXES
- bug fix + improvement: fixes for simple authentication -
wi_th()now supportsbasic_authto mock basic authentication either withcrul::auth()orhttr::authenticate()(#108)
webmockr 0.7.0
CRAN release: 2020-09-30
NEW FEATURES
- Gains ability to define more than 1 returned HTTP response, and the order in which the HTTP responses are returned. The idea is from the Ruby webmock library, but the implementation is different because the Ruby and R languages are very different. You can give more than one
to_return()one creating a stub, or if you want to return the same response each time, you can use the newtimesparameter withinto_return(). As a related use case (#31) you can mock http retry’s using this new feature (#10) (#32) (#101) - Gains new function
webmockr_reset()to be able to reset stub registry and request registry in one function call (#97) (#101) - Gains support for mocking simple authentication.
wi_th()now acceptsbasic_authin addition to query, body, and headers. Note that authentication type is ignored (#103)
MINOR IMPROVEMENTS
- change to how URI’s are matched in
stub_request(): we weren’t allowing matching URI’s without schemes; you can now do that. In addition, webmockr can match URI’s without the “http” scheme, but does not match if the scheme is “https”. SeeUriPatternfor more (#102) - another change to how URI’s are matched: now query params compared separately to the URI; note that regex not allowed in query params (#104) - And now query parameters are compared with the same code both when regex uri is used and when it is not (#107)
- URI matching for stubs is now done only on the URI’s themselves; that is, query parameters are removed before comparison, so only the base url with http scheme, plus paths, are compared (#107)
- wasn’t sure
write_disk_pathbehavior was correct when using httr, seems to be working, added tests for it (#79) - values for query parameters given to
wi_th()are now all coerced to character class to make sure that all comparisons of stubs and requests are done with the same class (character) (#107)
BUG FIXES
- fix for
uri_regexusage instub_request(): no longer curl escape theuri_regexgiven, only escape a non-regex uri (#106)
webmockr 0.6.0
CRAN release: 2020-03-02
NEW FEATURES
- new
Adapterclass to consolidate common code for theHttrAdapterandCrulAdapterclasses, which inherit fromAdapter; not a user facing change (#87) - pkgdown documentation site gains grouping of functions to help the user navigate the package: see https://docs.ropensci.org/webmockr/reference/ (#93)
MINOR IMPROVEMENTS
- now correctly fails with informative message when
write_disk_pathisNULLwhen the user is trying to write to disk while using webmockr (#78) - improve README construction; use html child for the details section (#81)
- fix matching stub matching for bodies when bodies are JSON encoded (#82)
- when vcr was loaded real HTTP requests were being performed twice when they should have only been performed once (#91) (#92)
BUG FIXES
- fix for
set_body()method in theResponseclass - handle cases where user writing to disk and not, and handle raw bytes correctly (#80) - fix to
to_s()method inStubbedRequestclass - was formatting query parameters incorrectly (#83) - fix to
BodyPatternclass to handle upload objects in a list; related issue fixed wherewi_th()parameterbodywas not handling upload objects (#84) (#85) - httr requests were failing when vcr loaded, but with no cassette inserted; fixed
handle_request()to skip vcr-related code unless a cassette is inserted (#86) (#88)
webmockr 0.5.0
CRAN release: 2019-12-04
NEW FEATURES
-
webmockrnow supports mocking writing to disk. TLDR: see?mocking-disk-writingto get started - That is, both of the major high level http clients in R, crul and httr, support writing directly to disk (rather than the user manually getting the http response and writing it to disk). supporting this required quite a bit of work, both in code and in thinking about how to support the various scenarios in which users can find themselves when dealing with writing to disk - Please get in touch if you have problems with this (#57) (#76) - gains
request_registry_clear()method to easily clear all requests in the request registry (#75)
BUG FIXES
- fix to handle raw responses that can not be converted to character, such as images; needed due to issue https://github.com/ropensci/vcr/issues/112 (#72) (#73)
webmockr 0.4.0
CRAN release: 2019-08-09
BUG FIXES
- fix stub specification within crul and httr adapters; typo in setting headers (#70)
webmockr 0.3.4
CRAN release: 2019-02-09
DEFUNCT
- underscore methods
to_return_()andwi_th_()are defunct (#60) (#64)
NEW FEATURES
-
to_return()gains parameter.list(#60) (#64)
BUG FIXES
- fix date in mocked
httrresponse object to match the date format thathttruses in real HTTP requests (#58) (#61) via https://github.com/ropensci/vcr/issues/91 - fix response headers in mocked
httrresponse objects.httrmakes the list of headers insensitive to case, so we now use that function from the package (#59) (#61) -
to_return()andwi_th()drop use of thelazyevalpackage and fall back to using the simplelist(...)- fixes problem where creating stubs was failing withintest_that()blocks due to some weird lazy eval conflicts (i think) (#60) (#64) thanks @karawoo !
webmockr 0.3.0
CRAN release: 2019-01-09
MINOR IMPROVEMENTS
- returned mocked response headers were retaining case that the user gave - whereas they should be all lowercased to match the output in
crulandhttr. now fixed. (#49) thanks @hlapp - returned mocked response headers were not all of character class, but depended on what class was given by the user on creating the stub. this is now fixed, returning all character class values for response headers (#48) thanks @hlapp
- skip tests that require
vcrifvcris not available (#53) - internal change to crul adapter to produce the same http response as a new version of crul returns - adds a
response_headers_allslot (#51) (#54)
webmockr 0.2.9
CRAN release: 2018-11-05
MINOR IMPROVEMENTS
- make
request_registry()andstub_registry()print methods more similar to avoid confusion for users (#35) - update docs for
enable/disableto indicate thatcrulandhttrsupported (#46) (related to #45) - wrap httr adapter examples in
requireNamespaceso only run when httr available - clean up
.onLoadcall, removing commented out code, and add note about creating adapter objects does not load crul and httr packages
BUG FIXES
- fix to
enable()anddisable()methods. even thoughhttris in Suggests, we were loading all adapters (crul, httr) withstopwhen the package was not found. We now give a message and skip when a package not installed. In addition, weenable()anddisable()gain anadapterparameter to indicate which package you want to enable or disable. Ifadapternot given we attempt all adapters. Note that this bug shouldn’t have affectedvcrusers ashttris in Imports in that package, so you’d have to havehttrinstalled (#45) thanks to @maelle for uncovering the problem
webmockr 0.2.8
CRAN release: 2018-10-19
NEW FEATURES
- Added support for integration with package
httr; seeHttrAdapterfor the details;webmockrnow integrates with two HTTP R packages:crulandhttr(#43) (#44) - Along with
httrintegration is a new methodhttr_mock()to turn on mocking forhttr; and two methodsbuild_httr_responseandbuild_httr_requestmeant for internal use
webmockr 0.2.4
CRAN release: 2018-05-08
MINOR IMPROVEMENTS
- matching by request body was not supported, it now is; added examples of matching on request body, see
?stub_request(#36) - make sure that the adapter for
crulhandles all types of matches (#29) - removed all internal usage of pipes in the package. still exporting pipe for users (#30)
- fixed internals to give vcr error when vcr loaded - for future release with vcr support (#34)
- require newest
crulversion
BUG FIXES
- Error messages with the suggest stub were not giving bodies. They now give bodies if needed along with method, uri, headers, query (#37)
- Fixed
Responseclass that was not dealing with capitalization correctly
webmockr 0.2.0
CRAN release: 2018-03-02
NEW FEATURES
- New function
to_raise()to say that a matched response should return a certain exception, currentlyto_raiseaccepts error classes from thefauxpaspackage (#9) - New function
to_timeout()to say that a matched response should return a timeout. This is a special case ofto_raiseto easily do a timeout expectation (#11) - New function
request_registry()to list requests in the request registry (#23) - package
crulmoved to Imports from Suggests as it’s the only http client supported for now. will move back to Suggests once we support at least one other http client -
webmockr_configure()changes:turn_onhas been removed;allow_net_connectandallow_localhostwere ignored before, but are now used and are now set toFALSEby default; fixed usage ofallowwhich now accepts character vector of URLs instead of a boolean; the following correctly marked as being ignored for now until fixednet_http_connect_on_start,show_stubbing_instructions,query_values_notation,show_body_diff(#19) (#21) -
webmockr_disable_net_connect()now accepts anallowparameter to disable all other connections except those URLs given inallow -
webmockr_net_connect_allowed()now accepts auriparameter to test if a URI/URL is allowed
MINOR IMPROVEMENTS
- Fixed printed stub statement when printed to the console - we weren’t including headers accurately (#18)
- Added examples to the
stub_registry()andstub_registry_clea()manual files (#24) - internal methods
build_crul_requestandbuild_crul_responsemoved outside of theCrulAdapterclass so that they can be accessed likewebmockr::in other packages -
enable()anddisable()now return booleans invisibly - General improvements to documentation throughout
- Added linting of user inputs to the
to_return()method, and docs details on what to input to the method - Added linting of user inputs to the
wi_th()method, and docs details on what to input to the method
BUG FIXES
- Fixed option
allow_localhost, which wasn’t actually workin before (#25)
DEPRECATED AND DEFUNCT
-
webmockr_enable()andwebmockr_disableare now defunct. Usewebmockr::enable()andwebmockr::disable()instead
