Socket
Book a DemoInstallSign in
Socket

netrecorder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netrecorder

0.2.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

== 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

== Scopes

Net recorder makes it easy to add a 'scope' to your recordings. Fakeweb doesn't have a way to name a response. If you make a request to the same url twice and get a different response both times, fakeweb just stores the responses in an array and returns them in order. This means that whatever you are testing will have to maintain the order or else you won't get the correct mocked data for your tests. So netrecorder allows you to set a scope that can be used when registering with fakeweb.

To record using scopes:

if NetRecorder.recording? NetRecorder.scope = 'first request' # request www.something.com # make a change that alters the return value from www.something.com NetRecorder.scope = "second request" # request www.something.com end

To register the scoped cache with fakeweb:

if !NetRecorder.recording? FakeWeb.clean_registry # This will clear out any previous registrations so that our scope will not be added to the array of reponses NetRecorder.register_scope(scenario.name) end

== Cucumber Example

see http://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

Scope all the recordings to the scenario name!

Before do |scenario| if NetRecorder.recording? NetRecorder.scope = scenario.name else FakeWeb.clean_registry NetRecorder.register_scope(scenario.name) end end

record mode (command line)

rake features RECORD_NET_CALLS=true

cache mode (command line)

rake features

== Similar projects

StaleFish[http://github.com/jsmestad/stale_fish]

  • Uses fixtures to store netrequests
  • More configuration options
  • Configure fixtures to atomically refresh themselves at an interval

FAQs

Package last updated on 14 Apr 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.