Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Artifice extension that allows you to let certain requests pass thru to use HTTP

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 artifice-passthru.gemspec
README.md

Artifice::Passthru

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:

  • You want to test that real HTTP requests work
  • Your test suite uses HTTP to communicate with its testing tools (eg. Capybara/Selenium requires HTTP)
  • Your test suite calls lots of real APIs and you want to iteratively refactor it to use Artifice
  • ?

Usage

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!

License

Artifice::Passthru is released under the MIT license.

Something went wrong with that request. Please try again.