Skip to content

Commit

Permalink
Using setter syntax for models in testHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Young committed Jan 31, 2011
1 parent 889d60b commit 6a269ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
8 changes: 5 additions & 3 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ var app = require('../app'),

app.listen(3001);

testHelper.setup([app.User], function() {
testHelper.models = [app.User];

testHelper.setup(function() {
// Fixtures
var user = new app.User({'email' : 'alex@example.com', 'password' : 'test' });
user.save(testHelper.run(exports));
});

testHelper.tests({
testHelper.tests = {
'test login': function() {
zombie.visit('http://localhost:3001/', function(err, browser, status) {
// Fill email, password and submit form
Expand All @@ -26,5 +28,5 @@ testHelper.tests({
});
});
}
});
};

37 changes: 22 additions & 15 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Force test environment
process.env.NODE_ENV = 'test';
var state = {};
var state = {
models: []
};

function prepare(models, next) {
var modelCount = models.length;
Expand All @@ -17,22 +19,27 @@ function prepare(models, next) {
});
};

exports.tests = function(tests) {
state.tests = tests;
};
module.exports = {
run: function(e) {
for (var test in state.tests) {
e[test] = state.tests[test];
}
},

exports.run = function(e) {
for (var test in state.tests) {
e[test] = state.tests[test];
}
};
setup: function(next) {
prepare(state.models, next);
},

exports.setup = function(models, next) {
state.models = models;
prepare(state.models, next);
};
end: function() {
prepare(state.models, process.exit);
},

set models(models) {
state.models = models;
},

exports.end = function() {
prepare(state.models, process.exit);
set tests(tests) {
state.tests = tests;
}
};

0 comments on commit 6a269ce

Please sign in to comment.