webmock icon indicating copy to clipboard operation
webmock copied to clipboard

Simplify webmock: exclude User-Agent and Connection from stubbing recommendation

Open KelseyDH opened this issue 6 years ago • 1 comments

I recently ran into an annoying issue with WebMock when implementing stubs the way the gem recommended. I.e. the gem recommends copying over the User-Agent header of each request when pasting in what to stub.

Since most ruby http gems append their gem name and version number as the User-Agent in requests, this means that WebMock will automatically break whenever you update your http client, even if nothing else about the request has changed. These breaks from updates are difficult to debug.

Rather than need to hack my HTTP gem to find way to keep my User-Agent stable in WebMock across gem updates, it dawned on me that it might be a lot simpler for most developers if WebMock by default just excluded the user-agent altogether from what it recommends stubbing... so that developer's using this tool don't see their tests break in confusing ways when they inevitably update their http client gems.

This will make WebMock tests less brittle, developer's more productive, and if people need the User-Agent recommended in their stubbing output they should just add it to their web mock tests manually.


It may also be worth thinking about ways to reduce HTTP boilerplate in what webmock's mock. If so I would recommend removing the Connection header also.

KelseyDH avatar Oct 30 '19 21:10 KelseyDH

Hey @KelseyDH . That makes sense, good idea. I don't think anyone takes advantage of the user agent header.

bblimke avatar Oct 31 '19 11:10 bblimke