Artifice extension that allows you to let certain requests pass thru to use HTTP
Artifice is a great way to mock HTTP requests in your Ruby applications,
sending all Net::HTTP requests to a Rack application.
That’s great until you find that, for one reason or another, you actually need
to make real HTTP requests!
There are a few reasons why you might need to do this:
require 'artifice/passthru'
# If you want to give a class or module (and all of its subclasses)
# access to the real Net::HTTP, you can #use_real_net_http
Artifice.use_real_net_http MyModule
Artifice.activate_with lambda { |env|
if env['SERVER_NAME'] == 'api.twitter.com'
# Inside of your Artifice Rack application, you can call Artifice.passthru! which:
# - looks at the current Artifice request
# - makes a real HTTP request
# - returns a Rack response representing the actual HTTP response that was returned
Artifice.passthru! # <--- will make the real HTTP call and return the response
else
# return faked responses using your Rack application as you normally would
[ 200, {}, ['Hi!'] ]
end
}
That’s all!
Artifice::Passthru is released under the MIT license.
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.