不要怂,就是干,撸起袖子干!

Commit bf8246bc by Sascha Depold

added assertion for error messages

1 parent feca1473
...@@ -407,7 +407,7 @@ module.exports = (function() { ...@@ -407,7 +407,7 @@ module.exports = (function() {
throw new Error(msg) throw new Error(msg)
} }
} else { } else {
throw new Error('Include malformed. Expected attributes: daoFactory, as') throw new Error('Include malformed. Expected attributes: daoFactory, as!')
} }
} else { } else {
throw new Error('Include unexpected. Element has to be either an instance of DAOFactory or an object.') throw new Error('Include unexpected. Element has to be either an instance of DAOFactory or an object.')
......
...@@ -2,6 +2,7 @@ const Sequelize = require(__dirname + "/../index") ...@@ -2,6 +2,7 @@ const Sequelize = require(__dirname + "/../index")
, DataTypes = require(__dirname + "/../lib/data-types") , DataTypes = require(__dirname + "/../lib/data-types")
, config = require(__dirname + "/config/config") , config = require(__dirname + "/config/config")
, fs = require('fs') , fs = require('fs')
, buster = require("buster")
var BusterHelpers = module.exports = { var BusterHelpers = module.exports = {
Sequelize: Sequelize, Sequelize: Sequelize,
...@@ -95,5 +96,14 @@ var BusterHelpers = module.exports = { ...@@ -95,5 +96,14 @@ var BusterHelpers = module.exports = {
} else { } else {
throw new Error('Undefined expectation for "' + dialect + '"!') throw new Error('Undefined expectation for "' + dialect + '"!')
} }
},
assertException: function(block, msg) {
try {
block()
throw new Error('Passed function did not throw an error')
} catch(e) {
buster.assert.equals(e.message, msg)
}
} }
} }
...@@ -489,21 +489,21 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -489,21 +489,21 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
it('throws an error about unexpected input if include contains a non-object', function() { it('throws an error about unexpected input if include contains a non-object', function() {
expect(function() { Helpers.assertException(function() {
this.Worker.find({ include: [ 1 ] }) this.Worker.find({ include: [ 1 ] })
}.bind(this)).toThrow() }.bind(this), 'Include unexpected. Element has to be either an instance of DAOFactory or an object.')
}) })
it('throws an error about missing attributes if include contains an object with daoFactory', function() { it('throws an error about missing attributes if include contains an object with daoFactory', function() {
expect(function() { Helpers.assertException(function() {
this.Worker.find({ include: [ { daoFactory: this.Worker } ] }) this.Worker.find({ include: [ { daoFactory: this.Worker } ] })
}.bind(this)).toThrow() }.bind(this), 'Include malformed. Expected attributes: daoFactory, as!')
}) })
it('throws an error if included DaoFactory is not associated', function() { it('throws an error if included DaoFactory is not associated', function() {
expect(function() { Helpers.assertException(function() {
this.Worker.find({ include: [ this.Task ] }) this.Worker.find({ include: [ this.Task ] })
}.bind(this)).toThrow() }.bind(this), 'Task is not associated to Worker!')
}) })
it('returns the associated worker via task.worker', function(done) { it('returns the associated worker via task.worker', function(done) {
...@@ -537,9 +537,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -537,9 +537,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
it('throws an error if included DaoFactory is not associated', function() { it('throws an error if included DaoFactory is not associated', function() {
expect(function() { Helpers.assertException(function() {
this.Task.find({ include: [ this.Worker ] }) this.Task.find({ include: [ this.Worker ] })
}.bind(this)).toThrow() }.bind(this), 'Worker is not associated to Task!')
}) })
it('returns the associated task via worker.task', function(done) { it('returns the associated task via worker.task', function(done) {
...@@ -573,9 +573,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -573,9 +573,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
it('throws an error if included DaoFactory is not associated', function() { it('throws an error if included DaoFactory is not associated', function() {
expect(function() { Helpers.assertException(function() {
this.Task.find({ include: [ this.Worker ] }) this.Task.find({ include: [ this.Worker ] })
}.bind(this)).toThrow() }.bind(this), 'Worker is not associated to Task!')
}) })
it('returns the associated tasks via worker.tasks', function(done) { it('returns the associated tasks via worker.tasks', function(done) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!