Book Image

Learning Behavior-driven development with Javascript

Book Image

Learning Behavior-driven development with Javascript

Overview of this book

Table of Contents (17 chapters)
Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finishing our feature


We are almost done; we just need to finish our last scenario. First of all, we need a new DAO that is responsible for storing the messages. The real implementation of this DAO, perhaps, will not go to the database but will probably use the flash scope or the session scope of the web framework we are going to use. This does not matter conceptually as it is an object to access external data:

beforeEach(function () {
  this.orderStorage = newStorage();
  this.messageStorage = newStorage();
  this.orderSystem = orderSystemWith({
    order: this.orderStorage.dao(),
    message: this.messageStorage.dao()
  });
});

Now, we can create an example message factory in the test/support/examples/errors.js file:

'use strict';

module.exports = {
  badQuantity: function (quantity) {
    return {
      key: "error.quantity",
      params:[quantity]
    };
  },
  beverageDoesNotExist: function () {
    return {
      key: "error.beverage.notExists"
    };
  }
};

For now, we can imagine two...