Skip to content
Record network requests and responses for easy stubbing of external calls
Ruby
Pull request Compare This branch is 4 commits ahead, 21 commits behind chrisyoung:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
features
lib
.gitignore
Manifest
README.rdoc
Rakefile

README.rdoc

NetRecorder

Record network responses for easy stubbing of external calls.

Net recorder hooks into NetHTTP to record the outgoing request path and method and caches the response. Then you can switch on fakeweb and it will use the cache from the recording.

Requirements

gem install fakeweb

Install

gem install netrecorder

Usage

Anywhere you use fakeweb, you can use net recorder.

Record all responses:

NetRecorder.config do |config|
  config.cache_file       = File.join(RAILS_ROOT, 'fakeweb')
  config.record_net_calls = true
end

Save recorded responses:

NetRecorder.cache!

Use recorded cache with fakeweb:

NetRecorder.config do |config|
  config.cache_file = File.join(RAILS_ROOT, 'features', 'support', 'fakeweb')
  config.fakeweb    = true
end

Cucumber Example

see cukes.info for more info on testing with Cucumber

# Find me in features/support/netrecorder.rb

NetRecorder.config do |config|
  config.cache_file = "#{File.dirname(__FILE__)}/../support/fakeweb"    
  if ENV['RECORD_WEB']
    config.record_net_calls = true
  else
    config.fakeweb = true
    FakeWeb.allow_net_connect = false
  end
end 

at_exit do
  if NetRecorder.recording?
    NetRecorder.cache!
  end
end

record mode (command line)

>> rake features RECORD_NET_CALLS=true

cache mode (command line)

>> rake features
Something went wrong with that request. Please try again.