Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (39 sloc) 1.87 KB

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.