Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cpg1111/factorydude

A Node module to create mongoose objects for test data
https://github.com/cpg1111/factorydude

Last synced: 3 days ago
JSON representation

A Node module to create mongoose objects for test data

Awesome Lists containing this project

README

        

# FactoryDude

A Node module to create mongoose objects for test data

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cpg1111/FactoryDude?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


GitHub version
npm version

To be used in test suites (mocha, chai, jasmine, etc) for features that use mongoose models.
Inspired by factory_girl

### Install

```
npm install FactoryDude
```

## Usage

```
var FactoryDude = require('FactoryDude');
var factoryDude = new FactoryDude();
```

### Create a Factory

```
var newFixtureModel = factoryDude.factory(
,
,

);
/*
* returns a mongoose model that has been saved in the database
* and can be used just as any other mongoose models.
*/
```

### Reference one factory in another factory
```
factoryDude.reference(, );
```

```
var firstFixtureModel = factoryDude.factory(
'firstModel',
'./path/to/model',
{name: 'test', number: 1}
);
//creates a model with the name test and a number 1

var secondFixtureModel = factoryDude.factory(
'secondModel',
'./path/to/model',
{name: factoryDude.reference('firstModel', 'name'), number: 2}
);
//creates a model with the name test and a number 2
```

### Destroy a factory model that was already created
```
factoryDude.destroy();
```

```
var firstFixtureModel = factoryDude.factory(
'firstModel',
'./path/to/model',
{name: 'test', number: 1}
);

factoryDude.destroy('firstModel'); //'firstModel' is no longer in the database or a fixture
```

## License
FactoryDude is licensed under the apache license.