Skip to content

Commit

Permalink
Add net_http_connect_on_start example with explicit domain
Browse files Browse the repository at this point in the history
In order to workaround the `net_http_connect_on_start` gotcha while working with Capybara it's sometimes necessary to restrict the scope of `net_http_connect_on_start`.

This adds information from [this comment](#914 (comment)) to the readme to make debugging that issue easier, and adds an example to show `net_http_connect_on_start` accepts domains as well as boolean values.
  • Loading branch information
spikeheap committed Jan 13, 2023
1 parent 833291d commit e5008c6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,11 @@ which can be passed to `WebMock.allow_net_connect!` and `WebMock.disable_net_con
WebMock.allow_net_connect!(net_http_connect_on_start: true)
```

This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`.
This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`. At the time of connection being made there is no information about the request or URL yet, therefore WebMock is not able to decide whether to stub a request or not and all connections are allowed. To enable connections only to a specific domain (e.g. your test server) use:

```ruby
WebMock.allow_net_connect!(net_http_connect_on_start: "www.example.com")
```

## Setting Expectations

Expand Down

0 comments on commit e5008c6

Please sign in to comment.