From 07433645cdf1ec21007d70307e283585172d2402 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Fri, 29 Jan 2021 10:02:53 -0800 Subject: [PATCH] #220 fix for this issue in webmockr - but a fix needed here for the change in webmockr - RequestMatcherRegistry register_$built_ins method needed fix in the rul for path: strip trailing slash first --- DESCRIPTION | 3 ++- R/request_matcher_registry.R | 3 ++- tests/testthat/test-RequestMatcherRegistry.R | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 28987d4..744c3aa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,7 @@ LinkingTo: Imports: crul (>= 0.8.4), httr, - webmockr (>= 0.7.4), + webmockr (>= 0.7.4.93), urltools, yaml, R6, @@ -48,6 +48,7 @@ Suggests: cli, curl, withr +Remotes: ropensci/webmockr X-schema.org-applicationCategory: Web X-schema.org-keywords: http, https, API, web-services, curl, mock, mocking, http-mocking, testing, testing-tools, tdd X-schema.org-isPartOf: https://ropensci.org diff --git a/R/request_matcher_registry.R b/R/request_matcher_registry.R index 892303e..6b6dd84 100644 --- a/R/request_matcher_registry.R +++ b/R/request_matcher_registry.R @@ -49,7 +49,8 @@ RequestMatcherRegistry <- R6::R6Class( self$register("body", function(r1, r2) identical(r1$body, r2$body)) self$register('headers', function(r1, r2) identical(r1$headers, r2$headers)) self$register("host", function(r1, r2) identical(r1$host, r2$host)) - self$register("path", function(r1, r2) identical(r1$path, r2$path)) + self$register("path", function(r1, r2) + identical(sub("/$", "", r1$path), sub("/$", "", r2$path))) self$register("query", function(r1, r2) identical(r1$query, r2$query)) self$try_to_register_body_as_json() }, diff --git a/tests/testthat/test-RequestMatcherRegistry.R b/tests/testthat/test-RequestMatcherRegistry.R index 5a25566..004ccfe 100644 --- a/tests/testthat/test-RequestMatcherRegistry.R +++ b/tests/testthat/test-RequestMatcherRegistry.R @@ -75,6 +75,9 @@ test_that("RequestMatcherRegistry basic functionality works", { expect_false(request_matchers$registry$path$matches(b, d)) expect_true(request_matchers$registry$path$matches(c, d)) expect_true(request_matchers$registry$path$matches(b, e)) + ## trailing slash is removed + expect_true(request_matchers$registry$path$matches( + list(path="foo"), list(path="foo/"))) # query expect_true(request_matchers$registry$body_as_json$matches(a, b))