Last active
August 1, 2019 21:08
-
-
Save seanupton/295b389ce1071acc9cf0519de3739cb0 to your computer and use it in GitHub Desktop.
WebMock and Faraday in irb console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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