Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
A is a nodejs module which consists of A mocking framework and A testing framework.
partial mock
var original = function() {
return 'realValue';
}
var mock = require('a').mock;
original = mock(original);
mock.expect().return('fake');
original(); //returns 'fake'
original(); //returns 'realValue'
strict mock
var original = function() {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect().return('fake');
original(); //returns 'fake'
original(); //throws unexpected arguments
strict mock with arguments
var original = function(arg) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect('testValue1').return('fake1');
mock.expect('testValue2').return('fake2');
original('testValue1'); //returns 'fake1'
original('testValue2'); //returns 'fake2'
original(); //throws unexpected arguments
original('foo'); //throws unexpected arguments
strict mock with multiple arguments
var original = function(arg1, arg2) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect('firstArg1', 'secondArg1').return('fake1');
mock.expect('firstArg2', 'secondArg2').return('fake2');
original('firstArg1', 'secondArg1'); //returns 'fake1'
original('firstArg2', 'secondArg2'); //returns 'fake2'
original('foo'); //throws unexpected arguments
original('foo', 'bar'); //throws unexpected arguments
strict mock with repeats
var original = function() {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect().return('fake').repeat(2);
original(); //returns 'fake'
original(); //returns 'fake'
original(); //throws unexpected arguments
strict mock with infinite repeats
var original = function() {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect().return('fake').repeatAny();
original(); //returns 'fake'
original(); //returns 'fake'
original(); //returns 'fake'...
strict mock ignoring arguments
var original = function(arg) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expectAnything().return('fake1');
original('someRandomValue'); //returns 'fake1'
original(); //throws unexpected arguments
strict mock with interceptor
var original = function(arg) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect('testValue').whenCalled(onCalled).return('fake1');
function onCalled(arg) {
//arg == 'testValue'
}
original('someRandomValue'); //returns 'fake1'
original(); //throws unexpected arguments
strict mock - verify (fail)
var original = function(arg) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect('testValue1').return('fake1');
mock.expect('testValue2').return('fake2');
original('testValue1'); //returns 'fake1'
mock.verify(); //throws mock has 1 pending functions
strict mock - verify (success)
var original = function(arg) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect('testValue1').return('fake1');
mock.expect('testValue2').return('fake2');
original('testValue1'); //returns 'fake1'
original('testValue2'); //returns 'fake2'
mock.verify(); //returns true
strict mock - advanced scenario
var original = function(arg, callback) {
return 'realValue';
}
var mock = require('a').mock;
original = mock();
mock.expect('testValue').expectAnything().whenCalled(onCalled).return('fake1');
function onCalled(arg,callback) {
//arg == 'testValue'
//callback == foo
}
function foo() {
}
original('testValue', foo); //returns 'fake1'
mock.verify() //returns true
original('testValue',foo); //throws unexpected arguments
expectRequire
var fakeDep = {};
var expectRequire = require('a').expectRequire;
expectRequire('./realDep').return(fakeDep);
require('./realDep'); //returns fakeDep
require('./realDep'); //returns realDep (behaves like a partial mock)
requireMock (compact syntax)
var requireMock = require('a').requireMock;
var fakeDep = requireMock('./realDep'); //returns a strict mock
require('./realDep'); //returns fakeDep
require('./realDep'); //returns realDep
..is equivalent to ..
var mock = require('a').mock;
var expectRequire = require('a').expectRequire;
var fakeDep = mock();
expectRequire('./realDep').return(fakeDep);
require('./realDep'); //returns fakeDep
require('./realDep'); //returns realDep
partial object mock
function newCustomer(_name) {
var c = {};
c.getName = function ()
{
return _name;
};
return c;
}
var customer = newCustomer('Alfonzo The Real');
var customerMock = mock(customer);
customerMock.getName.expect().return('Johnny Fake');
customer.getName(); //returns Alfonzo The Real
customer.getName(); //returns Johnny Fake
customerMock.verify(); //returns true
Not fully documented yet. See dummy_specs.
FAQs
Mocking framework
The npm package a receives a total of 2,588 weekly downloads. As such, a popularity was classified as popular.
We found that a demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.