Home > nelson

nelson

Nelson is a project mainly written in CoffeeScript, based on the MIT license.

NodeJS mocking library

Nelson is a lightweight NodeJS mocking library

Installation

To install nelson, use npm:

$ npm install nelson

Usage

var nelson = require('nelson');
nelson.mock('namespace', {thisis: 'mynewvalue'});
// Use super cool new value
nelson.restore('namespace');
// or you can use
nelson.restoreAll();

Examples

nelson = require 'nelson'
darpSys = require 'sys'
systest = {tar: 'dar', dar: 'har'}
console.log darpSys.inspect systest # {tar: 'dar', dar: 'har'}
nelson.mock 'sys.inspect', (obj) -> 
  delete obj[key] for key in Object.keys obj when key is 'dar' # Filter out hashes when the key is dar
  return obj

console.log darpSys.inspect systest # {tar: 'dar',}
nelson.restoreAll()

You can view further examples in the example folder.

Namespacing

'os.types.blah.blah' = require('os').types.blah.blah

LICENSE

(MIT License)

Copyright (c) 2011 Fractal [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Previous:Teste