Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 123 lines (75 sloc) 4.073 kb
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
1 # tbd - Test Data Builder
c709d3e @aaronpowell 'initial commit'
authored
2
69ae825 @aaronpowell adding build status to readme
authored
3 [![Build Status](https://secure.travis-ci.org/aaronpowell/tbd.png)](https://secure.travis-ci.org/aaronpowell/tbd.png)
4
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
5 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?
c709d3e @aaronpowell 'initial commit'
authored
6
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
7 Well tbd to the rescue, tbd will allow you to quickly build up some data quickly and painlessly.
c709d3e @aaronpowell 'initial commit'
authored
8
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
9 tbd is designed to work in both Node.js and in the browser so you can use it for any application you want.
c709d3e @aaronpowell 'initial commit'
authored
10
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
11 # Getting tbd
12
13 For *Node.js*:
14
15 npm install tbd
16
17 For the browser - grab the latest version from [git](https://github.com/aaronpowell/tbd/blob/master/lib/tbd.js).
18
19 # Using tbd
20
21 ## Node.js
22
f41401c @aaronpowell updated readme
authored
23 ### Basic usage
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
24
25 var tbd = require('tbd');
26
27 var data = tbd.from({ hello: 'world' }).make(10);
28
29 console.log(data.length); //10
30
f41401c @aaronpowell updated readme
authored
31 ### Tweaking properties
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
32
33 var tbd = require('tbd');
34
35 var data = tbd.from({ hello: 'world' })
10d8f66 @HenryGau Minor missing quote
HenryGau authored
36 .prop('hello').use(function() { return 'my value'; }).done()
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
37 .make(10);
38
39 console.log(data.length); //10
40
f41401c @aaronpowell updated readme
authored
41 ### Using classes
42
43 tbd allows you to create objects from classes the same way that you can create data from objects. The difference is that for classes you just pass in the class reference.
44
45 You can also provide constructor parameters using the `constructWith` and passing in the arguments as you would pass them for the constructor. If you don't want to pass anything to your constructor you don't need to use that method.
46
47 var Person = function(firstName. lastName) {
48 this.firstName = firstName;
49 this.lastName = lastName;
50 };
51
52 var data = tbd.from(Person)
53 .constructWith('Aaron', 'Powell')
54 .make(10);
55
56 ### Utilities
57
58 There are a few utility methods provided by tbd to make generating more random data. These hang off the `tbd.utils` namespace.
59
60 **tbd.utils.random**
61
62 This is used for selecting a random value from an array:
63
3c05789 @aaronpowell updated readme
authored
64 tbd.from({ foo: 1 })
65 .prop('foo').use(tbd.utils.random(1,2,3,4,5,6,7,8,9))
66 .make(10);
f41401c @aaronpowell updated readme
authored
67 //foo's value will be randomly selected from the array for each object created
68
3c05789 @aaronpowell updated readme
authored
69 **tbd.utils.range**
70
71 This is used for randomly choosing a value from a range, similar to the `random` method but simpler as you specify an upper and lower bounds:
72
73 tbd.from({ foo: 1 })
74 .prop('foo').use(tbd.utils.range(1, 1000))
75 .make(10);
76 //foo's value will be randomly chosen from a number between 1 and 1000 (inclusive)
77
78 Ranges don't have to be just numbers, they can also be dates:
79
80 tbd.from({ date: new Date })
81 .prop('date').use(tbd.utils.range(new Date(2010, 1, 1), new Date()))
82 .make(10);
83 //the date propery will be a randomly chosing date between the min and max
84
85 **tbd.utils.sequence**
86
87 This is used for creating a sequential set of data from a starting value:
88
89 tbd.from({ foo: 1 })
90 .prop('foo').use(tbd.utils.sequential(1))
91 .make(10);
92 //[0].foo === 1, [9].foo === 10
93
94 Sequentials support numbers, letters (and words, where the next letter in the alphabet is appended) and dates:
95
96 tbd.from({ date: new Date })
97 .prop('foo').use(tbd.utils.sequential(new Date() /* optional parameter for date property the increment, default is 'd' */)
98 .make(10);
99 //the 'day' property will be incremented by 1 from the starting value
100
101 Dates allow you to increment any part of the date object (except milliseconds), to do so pass in a 2nd argument:
102
103 * y -> Year
104 * M -> Month
105 * d -> Day (default)
106 * h -> Hour
107 * m -> Minutes
108 * s -> Seconds
109
0622d59 @aaronpowell renamed test.js to tests.js. Updated readme
authored
110 ## Browser
111
112 When using tbd in the browser it works exactly the same way, only you don't need the `require` statement (unless you want to use RequireJS).
113
114 # Running the tests
115
116 There's a bunch of tests shipped which uses [Jasmine](http://pivotal.github.com/jasmine/) so you can run them from node.js if you want:
117
118 node tests.js
119
120 # License
121
10d8f66 @HenryGau Minor missing quote
HenryGau authored
122 [MIT](https://github.com/aaronpowell/tbd/blob/master/License.txt)
Something went wrong with that request. Please try again.