Skip to content

Instantly share code, notes, and snippets.

@seanupton
Last active August 1, 2019 21:08
Show Gist options
  • Save seanupton/295b389ce1071acc9cf0519de3739cb0 to your computer and use it in GitHub Desktop.
Save seanupton/295b389ce1071acc9cf0519de3739cb0 to your computer and use it in GitHub Desktop.
WebMock and Faraday in irb console
require 'webmock'
include WebMock::API
# Enable WebMock, but...
WebMock.enable!
# ...allow connection for non-stubbed requests:
WebMock.allow_net_connect!
url = 'https://www.example.com'
# will actually get URL
Faraday.get url
stub_request(:any, url).to_return(body: 'abc', headers: {'Content-Length' => 3})
# will get stubbed content
Faraday.get url
# Now, let's disable WebMock and its stubs:
WebMock.disable!
# will actually get URL (again)
Faraday.get url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment