Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:aaronpowell/tbd

Conflicts:
	package.json
  • Loading branch information...
commit d8565f3364f0ab66424f1091330c8251ea99141f 2 parents d5888be + 69ae825
@aaronpowell authored
View
4 .travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
View
2  README.md
@@ -1,5 +1,7 @@
# tbd - Test Data Builder
+[![Build Status](https://secure.travis-ci.org/aaronpowell/tbd.png)](https://secure.travis-ci.org/aaronpowell/tbd.png)
+
Have you ever needed to push out a bunch of data for testing your app? Maybe your backend services aren't ready but you want to build the UI for the expected data?
Well tbd to the rescue, tbd will allow you to quickly build up some data quickly and painlessly.
View
2  lib/tbd.js
@@ -120,7 +120,7 @@
utils.range = function (min, max) {
return function () {
var random = Math.random();
- var val = Math.floor(random * (max-min));
+ var val = Math.floor(random * (max - min + 1) + min);
if(min.constructor === Date || max === Date) {
val = Math.floor(random * (max.getTime() - min.getTime()));
return new Date(max.getTime() - val);
View
7 package.json
@@ -2,7 +2,7 @@
"name":"tbd",
"description":"tbd is a test data building library, allowing you to quickly spin up large amounts of fake data to be pumped into tests",
"keywords": ["testing", "unit-testing", "data", "generator"],
- "version":"0.6.2",
+ "version":"0.6.3",
"maintainers": [{
"name": "Aaron Powell",
"email": "me@aaron-powell.com",
@@ -21,5 +21,8 @@
"type": "git",
"url": "https://github.com/aaronpowell/tbd"
}],
- "homepage": ["https://github.com/aaronpowell/tbd"]
+ "homepage": ["https://github.com/aaronpowell/tbd"],
+ "scripts": {
+ "test": "node tests.js"
+ }
}
View
34 tests/basic-api-spec.js
@@ -1,5 +1,22 @@
describe('tbd-builder', function() {
var tbd = require('../lib/');
+
+ beforeEach(function() {
+ this.addMatchers({
+ toBeInArray: function(array) {
+ return ~array.indexOf(this.actual);
+ },
+ toBeInDateRange: function(min, max) {
+ var actual = this.actual.getTime();
+ return actual <= max.getTime() && actual >= min.getTime();
+ },
+ toBeInNumericalRange: function (min, max) {
+ var actual = this.actual;
+ return actual <= max && actual >= min;
+ }
+ });
+ });
+
it('should allow usage of undefined', function() {
var amount = 10,
data = tbd.from().make(amount);
@@ -21,4 +38,21 @@ describe('tbd-builder', function() {
expect(data.length).toEqual(number);
expect(data.length).toEqual(data2.length);
});
+
+ it('should allow functions in the object literal', function () {
+ var data = tbd.from({
+ a: 1,
+ b: function () { return 'hello'; },
+ c: tbd.utils.range(1, 10),
+ d: tbd.utils.random('a', 'b', 'c'),
+ e: tbd.utils.sequential(1)
+ }).make(1);
+
+ expect(data.length).toEqual(1);
+ expect(data[0].a).toEqual(1);
+ expect(data[0].b).toEqual('hello');
+ expect(data[0].c).toBeInNumericalRange(1, 10);
+ expect(data[0].d).toBeInArray('a', 'b', 'c');
+ expect(data[0].e).toEqual(1);
+ });
});
View
22 tests/util-range-spec.js
@@ -6,6 +6,10 @@ describe('tbd-util-range', function() {
toBeInDateRange: function(min, max) {
var actual = this.actual.getTime();
return actual <= max.getTime() && actual >= min.getTime();
+ },
+ toBeInNumericalRange: function (min, max) {
+ var actual = this.actual;
+ return actual <= max && actual >= min;
}
});
});
@@ -15,17 +19,15 @@ describe('tbd-util-range', function() {
.prop('foo').use(tbd.utils.range(0, 10))
.make(1);
expect(data.length).toBe(1);
- expect(data[0].foo).toBeGreaterThan(-1);
- expect(data[0].foo).toBeLessThan(11);
+ expect(data[0].foo).toBeInNumericalRange(0, 10);
});
it('should allow negative ranges', function () {
var data = tbd.from({})
- .prop('foo').use(tbd.utils.range(-1, -10))
+ .prop('foo').use(tbd.utils.range(-10, -1))
.make(1);
expect(data.length).toBe(1);
- expect(data[0].foo).toBeGreaterThan(-11);
- expect(data[0].foo).toBeLessThan(0);
+ expect(data[0].foo).toBeInNumericalRange(-10, -1);
});
it('should handle date ranges', function () {
@@ -38,4 +40,14 @@ describe('tbd-util-range', function() {
expect(data.length).toBe(1);
expect(data[0].foo).toBeInDateRange(min, max);
});
+
+ it('should handle large number ranges', function () {
+ var data = tbd.from({})
+ .prop('foo').use(tbd.utils.range(100, 500))
+ .make(100);
+
+ for (var i = 0, il = data.length; i < il; i++) {
+ expect(data[i].foo).toBeInNumericalRange(100, 500);
+ }
+ });
});

0 comments on commit d8565f3

Please sign in to comment.
Something went wrong with that request. Please try again.