Skip to content

Commit

Permalink
refactor tests to catch up with the framework docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bredikhin committed Oct 29, 2014
1 parent 189dee8 commit dba802d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
27 changes: 3 additions & 24 deletions test/bootstrap.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var assert = require('assert');
var Sails = require('sails');
var Barrels = require('barrels');
var fixtures;
require('should');

// Global before hook
before(function (done) {
Expand All @@ -24,7 +23,7 @@ before(function (done) {
// Save original objects in `fixtures` variable
fixtures = barrels.data;

// Populate the DB
// Populate the DB
barrels.populate(function(err) {
done(err, sails);
});
Expand All @@ -33,26 +32,6 @@ before(function (done) {

// Global after hook
after(function (done) {
console.log();
console.log(); // Skip a line before displaying Sails lowering logs
sails.lower(done);
});

// Here goes a module test
describe('Fruits', function() {
describe('#list()', function() {
it ('should list the sorts of apples and oranges', function() {
// All apples
Apples.find(function(err, apples) {
var gotApples = (fixtures['apples'].length > 0);
var applesAreInTheDb = (apples.length === fixtures['apples'].length);
assert(gotApples&&applesAreInTheDb, 'There must be something!');

// All oranges
Oranges.find(function(err, oranges) {
assert.equal(apples.length, oranges.length,
'The amount of varieties of apples and oranges should be equal!');
});
});
});
});
});
12 changes: 12 additions & 0 deletions test/unit/controllers/ApplesController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var request = require('supertest');

describe('ApplesController', function() {
describe('index', function() {
it('should return success', function (done) {
request(sails.hooks.http.app)
.get('/apples')
.expect(200, done);
});
});

});
9 changes: 9 additions & 0 deletions test/unit/models/Apples.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Apples', function() {
it ('should not be empty', function(done) {
Apples.find().exec(function(err, apples) {
apples.length.should.be.eql(fixtures['apples'].length);

done();
});
});
});
10 changes: 10 additions & 0 deletions test/unit/models/Oranges.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe('Oranges', function() {
it ('should have the same amount of documents as in fixtures', function(done) {
Oranges.find().exec(function(err, oranges) {
fixtures['oranges'].length.should.be.greaterThan(0);
oranges.length.should.be.eql(fixtures['oranges'].length);

done();
});
});
});

0 comments on commit dba802d

Please sign in to comment.