Skip to content

Commit

Permalink
Removed faker js stuff. Not really that helpful and was buggy.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewest committed Oct 19, 2014
1 parent 185400f commit 8abb251
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
24 changes: 0 additions & 24 deletions src/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
props[prop] = propVal(props, sharedIndicies[factoryName]);
});

// Removing for now, as there are issues we'll need to deal with around passing arguments to certain faker attrs.

// fakerize(props);

sharedIndicies[factoryName]++;

return props;
Expand All @@ -93,26 +89,6 @@
throw new Error(attr + " is not a valid attribute for faker.js");
}

function fakerize(props) {
// Look for faker values
_.each(props, function(propVal, prop) {
// Only accepting Faker calls as strings with "faker | fakerAttr " syntax for now.
if(!_.isString(propVal)) {return;}

var regex = /(faker)\s*\|?\s*(\w*)/i;
var matches = propVal.match(regex);
var attr;
if (matches) {
// The regex has two capture groups. But the first item of the array is always the input itself.
// So we want to look at slots 1 and 2. The first is always "faker", the second is the arg to faker.
// So we're either taking the second group (the arg), or just 'faker' if no second group was captured.
attr = matches[2] ? matches[2] : matches[1];
}

props[prop] = attr ? getFaker(attr, prop) : propVal;
});
}

function define(factoryName, props) {
if ( !_.isString(factoryName) ) { throw new Error('A factory name is required.'); }
// check for props to be object
Expand Down
31 changes: 0 additions & 31 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,37 +184,6 @@ describe('Replicator', function() {
describe('without enforcement', function() {
});
}); // build
xdescribe('with Faker.js', function() {
it("should use the argument after the pipe to pass to faker", function() {
Replicator.define('user', {user_email: 'faker | email'});
Replicator.makeFactory('user')().user_email.should.match(/\@/);
});
it("should be forgiving with the spacing", function() {
Replicator.define('user', {user_email: 'faker | email'});
Replicator.makeFactory('user')().user_email.should.match(/\@/);

Replicator.define('user', {user_email: ' faker|email '});
Replicator.makeFactory('user')().user_email.should.match(/\@/);

Replicator.define('user', {user_email: 'faker | email'});
Replicator.makeFactory('user')().user_email.should.match(/\@/);
});
it("should default to use the key's name as the faker argument", function() {
Replicator.define('user', {email: 'faker'});
Replicator.makeFactory('user')().email.should.match(/\@/);
});
it("should throw an error if the key or the arg isn't a valid Faker option", function() {
// Should show you the attr name
(function(){ Replicator.define('user', {user_email: 'faker | NOTREAL'});}).should.throw(/NOTREAL/);

(function(){ Replicator.define('user', {user_email: 'faker | NOTREAL'});}).should.throw(/not a valid/);
});
it("should work if the faker attribute is part of a trait", function () {
Replicator.define('user', {name: "joe"}).trait("confirmed", {confirmed_at: "faker | past"});
Replicator.makeFactory('user', {confirmed: true})().confirmed_at.should.match(/[0-9]/);
});

});
xdescribe('with calling real APIs', function() {

});
Expand Down

0 comments on commit 8abb251

Please sign in to comment.