Skip to content

Commit

Permalink
adding a random picker api
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Nov 24, 2011
1 parent 0622d59 commit be02847
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/tbd.js
Expand Up @@ -76,4 +76,20 @@
return new ObjectBuilder(schema);
}
};
}).call(this);

(function() {
var utils = {};

utils.random = function() {
var args = [].slice.call(arguments);

return function() {
var random = Math.random();

return args[Math.floor(random * args.length)];
};
};

this.tbd.utils = utils;
}).call(this);
23 changes: 23 additions & 0 deletions tests/util-random-spec.js
@@ -0,0 +1,23 @@
describe('tbd-util-random', function() {
var tbd = require('../lib/');

beforeEach(function() {
this.addMatchers({
toBeInArray: function(array) {
return ~array.indexOf(this.actual);
}
});
});

it('should have a random generator api', function() {
expect(tbd.utils.random).toBeDefined();
});

it('should allow random generation from arguments', function() {
var data = tbd.from({ foo: 1 })
.prop('foo').use(tbd.utils.random(1,2,3,4,5)).done()
.make(1);

expect(data[0].foo).toBeInArray([1,2,3,4,5]);
});
});

0 comments on commit be02847

Please sign in to comment.