Skip to content

Record network requests and responses for easy stubbing of external calls

Notifications You must be signed in to change notification settings

hashrocket/netrecorder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Record network requests and responses for easy stubbing of external calls

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%