Skip to content

Fix Regexp and Addressable::Template URL handling#105

Draft
jacamera wants to merge 1 commit into
Betterment:mainfrom
jacamera:jeffc/fix-regex-urls
Draft

Fix Regexp and Addressable::Template URL handling#105
jacamera wants to merge 1 commit into
Betterment:mainfrom
jacamera:jeffc/fix-regex-urls

Conversation

@jacamera
Copy link
Copy Markdown

FakeServiceConfig#service_url previously stringified every URL via strip_basic_auth(url.to_s) before it reached ServiceUrlConverter, which meant the converter's non-String passthrough branch was unreachable from Manager#webmock_service. As a result, the documented Regexp and Addressable::Template registration forms produced WebMock stubs that matched nothing, and path_prefix either returned garbage or raised URI::InvalidURIError. See #104.

  • Only apply strip_basic_auth to String URLs; pass Regexp and Addressable::Template through untouched.
  • Default path_prefix to "" for non-String URLs (no-op against FakeServiceWrapper's leading-prefix gsub) instead of trying to parse a path out of the pattern.
  • Add an optional path_prefix: keyword to WebValve.register for callers who want relative fake-service routes when using a Regexp or Addressable::Template URL.

Adds unit coverage for the new URL forms and override, plus the end-to-end integration coverage that was missing — registering a fake with a Regexp / Template URL, firing a real Net::HTTP request, and asserting the fake responds. The previous test suite only checked the arguments handed to WebMock.stub_request and never exercised FakeServiceWrapper#call, which is why the bug shipped undetected.

`FakeServiceConfig#service_url` previously stringified every URL via
`strip_basic_auth(url.to_s)` before it reached `ServiceUrlConverter`,
which meant the converter's non-String passthrough branch was
unreachable from `Manager#webmock_service`. As a result, the documented
`Regexp` and `Addressable::Template` registration forms produced
WebMock stubs that matched nothing, and `path_prefix` either returned
garbage or raised `URI::InvalidURIError`. See Betterment#104.

- Only apply `strip_basic_auth` to String URLs; pass `Regexp` and
  `Addressable::Template` through untouched.
- Default `path_prefix` to `""` for non-String URLs (no-op against
  `FakeServiceWrapper`'s leading-prefix gsub) instead of trying to
  parse a path out of the pattern.
- Add an optional `path_prefix:` keyword to `WebValve.register` for
  callers who want relative fake-service routes when using a `Regexp`
  or `Addressable::Template` URL.

Adds unit coverage for the new URL forms and override, plus the
end-to-end integration coverage that was missing — registering a fake
with a `Regexp` / `Template` URL, firing a real `Net::HTTP` request,
and asserting the fake responds. The previous test suite only checked
the arguments handed to `WebMock.stub_request` and never exercised
`FakeServiceWrapper#call`, which is why the bug shipped undetected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant