Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Record and playback Net::HTTP requests. Useful for testing.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION

README.rdoc

doubleweb

DoubleWeb watches and records Net::HTTP requests so that you can play the responses back later. This is useful for tests, for instance to switch from testing the network to testing canned responses.

Example

# Cache requests as YAML
DoubleWeb.cache_strategy = :yaml
DoubleWeb.cache.path = File.join(SPECDIR, 'fixtures', 'network.yaml')

# Record network requests
before(:all) { DoubleWeb.watch! }
after(:all)  { DoubleWeb.unwatch! }

# Playback network requests
before(:all) { DoubleWeb.playback! }
after(:all)  { DoubleWeb.stop_playback! }

In playback mode, DoubleWeb will return the recorded responses for each request and will raise a `DoubleWeb::UnexpectedRequestError` for any requests that do not have recorded responses.

DoubleWeb.init!

DoubleWeb.init! lets you control DoubleWeb from your environment. For instance, with the following in your spec/spec_helper.rb

SPECDIR = File.dirname(__FILE__)

require 'doubleweb'
DoubleWeb.cache_strategy = :yaml
DoubleWeb.cache.path = File.join(SPECDIR, 'fixtures', 'doubleweb.yaml')
DoubleWeb.init!

DoubleWeb will be controlled by an “internet” environment variable. For instance:

$ rake spec internet=on

Disable DoubleWeb

$ rake spec internet=watch

DoubleWeb in watch mode

$ rake spec internet=off

DoubleWeb in playback mode (internet disabled)

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Rein Henrichs. See LICENSE for details.

Something went wrong with that request. Please try again.