NEWS.md
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 using withCallingHandlers to handle different types of errors, throw warnings, etc.including() and excluding() for use with wi_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)RequestPattern. Shouldn’t change behavior (#133)webmockr_configure(show_body_diff = TRUE) or webmockr_configure(show_body_diff = FALSE). Second, a new function stub_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 package diffobj (#126)last_request() and last_stub(), which get the last http request made and the last webmockr stub created, respectively. (#126)global_stubs field from the StubRegistry class as it was completely unused (holdover from the initial port from Ruby). Should not impact users at all. (#127)rlang functions 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)StubRegistry gains new method is_stubbed() to check if a stub is in the stub registrywebmockr now supports the httr2 library, in addition to httr and crul. Note that you’ll see different behavior from httr2 relative to the other 2 http clients because it turns http errors (http statuses 400 and above) into R errors (#122)webmockr can now mock async http requests with crul (w/ crul v1.5 or greater). no change was required in webmockr for this to happen. a PR was merged in crul to hook into webmockr. there’s no support for async in httr as that package does not do any async and no support in httr2 because req_perform_parallel does not have a mocking hook as does req_perform (#124)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 reportstub_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 reportstatus parameter in to_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 reportwebmockr_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)StubCounter added to pkgdown docs page at https://docs.ropensci.org/webmockr/reference/StubCounter.html (#119) @maelleto_raise() and to_return() to explain the difference between them and when you may want to use them (#100)wi_th() now supports basic_auth to mock basic authentication either with crul::auth() or httr::authenticate() (#108)to_return() one creating a stub, or if you want to return the same response each time, you can use the new times parameter within to_return(). As a related use case (#31) you can mock http retry’s using this new feature (#10) (#32) (#101)webmockr_reset() to be able to reset stub registry and request registry in one function call (#97) (#101)wi_th() now accepts basic_auth in addition to query, body, and headers. Note that authentication type is ignored (#103)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”. See UriPattern for more (#102)write_disk_path behavior was correct when using httr, seems to be working, added tests for it (#79)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)uri_regex usage in stub_request(): no longer curl escape the uri_regex given, only escape a non-regex uri (#106)Adapter class to consolidate common code for the HttrAdapter and CrulAdapter classes, which inherit from Adapter; not a user facing change (#87)write_disk_path is NULL when the user is trying to write to disk while using webmockr (#78)set_body() method in the Response class - handle cases where user writing to disk and not, and handle raw bytes correctly (#80)to_s() method in StubbedRequest class - was formatting query parameters incorrectly (#83)BodyPattern class to handle upload objects in a list; related issue fixed where wi_th() parameter body was not handling upload objects (#84) (#85)handle_request() to skip vcr-related code unless a cassette is inserted (#86) (#88)webmockr now supports mocking writing to disk. TLDR: see ?mocking-disk-writing to 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)request_registry_clear() method to easily clear all requests in the request registry (#75)to_return_() and wi_th_() are defunct (#60) (#64)to_return() gains parameter .list (#60) (#64)httr response object to match the date format that httr uses in real HTTP requests (#58) (#61) via https://github.com/ropensci/vcr/issues/91
httr response objects. httr makes the list of headers insensitive to case, so we now use that function from the package (#59) (#61)to_return() and wi_th() drop use of the lazyeval package and fall back to using the simple list(...) - fixes problem where creating stubs was failing within test_that() blocks due to some weird lazy eval conflicts (i think) (#60) (#64) thanks @karawoo !crul and httr. now fixed. (#49) thanks @hlappvcr if vcr is not available (#53)response_headers_all slot (#51) (#54)request_registry() and stub_registry() print methods more similar to avoid confusion for users (#35)enable/disable to indicate that crul and httr supported (#46) (related to #45)requireNamespace so only run when httr available.onLoad call, removing commented out code, and add note about creating adapter objects does not load crul and httr packagesenable() and disable() methods. even though httr is in Suggests, we were loading all adapters (crul, httr) with stop when the package was not found. We now give a message and skip when a package not installed. In addition, we enable() and disable() gain an adapter parameter to indicate which package you want to enable or disable. If adapter not given we attempt all adapters. Note that this bug shouldn’t have affected vcr users as httr is in Imports in that package, so you’d have to have httr installed (#45) thanks to @maelle for uncovering the problemhttr; see HttrAdapter for the details; webmockr now integrates with two HTTP R packages: crul and httr (#43) (#44)httr integration is a new method httr_mock() to turn on mocking for httr; and two methods build_httr_response and build_httr_request meant for internal use?stub_request (#36)crul handles all types of matches (#29)crul versionResponse class that was not dealing with capitalization correctlyto_raise() to say that a matched response should return a certain exception, currently to_raise accepts error classes from the fauxpas package (#9)to_timeout() to say that a matched response should return a timeout. This is a special case of to_raise to easily do a timeout expectation (#11)request_registry() to list requests in the request registry (#23)crul moved 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 clientwebmockr_configure() changes: turn_on has been removed; allow_net_connect and allow_localhost were ignored before, but are now used and are now set to FALSE by default; fixed usage of allow which now accepts character vector of URLs instead of a boolean; the following correctly marked as being ignored for now until fixed net_http_connect_on_start, show_stubbing_instructions, query_values_notation, show_body_diff (#19) (#21)webmockr_disable_net_connect() now accepts an allow parameter to disable all other connections except those URLs given in allow
webmockr_net_connect_allowed() now accepts a uri parameter to test if a URI/URL is allowedstub_registry() and stub_registry_clea() manual files (#24)build_crul_request and build_crul_response moved outside of the CrulAdapter class so that they can be accessed like webmockr:: in other packagesenable() and disable() now return booleans invisiblyto_return() method, and docs details on what to input to the methodwi_th() method, and docs details on what to input to the methodallow_localhost, which wasn’t actually workin before (#25)webmockr_enable() and webmockr_disable are now defunct. Use webmockr::enable() and webmockr::disable() instead