spec-master

Bootstrap test/spec files for JS.

npm install spec-master
28 downloads in the last month

Spec Master

Bootstrap test/spec files for JS.

Developed for JavaScript projects organized in modules (AMD or CommonJS).

Installation

$ npm install spec-master -g

Installing globally is recommended but not mandatory.

Usage

Please configure me

First, if you haven't already, please read the configuration section.

Generating specs

If no action is specified a list of the modules without specs is printed.

Use the -a option to generate specs for the modules that need then.

Moving things around

The --move option allows you to easily move AMD source files:

  • moves the module and spec (if it exists)
  • the moving is done in a GIT sensible way (using git mv)
  • all the modules and specs are updated with the new path

What move does not do:

  • it does work if you don't use git
  • it fails big time if relative paths are used
  • it only detects top level define/require calls
  • it does not change other strings that contains the old module path

Examples

spec_master -s confs/spec_master.json
6 modules need specs:
core/Father.view.js
core/List.view.js
core/functional.helpers.js
core/partials.js
core/project.js
core/string.utils.js

spec_master -s examples/settings.json -a
Creating missing 6 specs...

c:/Users/lfac/r/spec_master/examples/specs/core/Father.view.js
c:/Users/lfac/r/spec_master/examples/specs/core/project.js
c:/Users/lfac/r/spec_master/examples/specs/core/partials.js
c:/Users/lfac/r/spec_master/examples/specs/core/functional.helpers.js
c:/Users/lfac/r/spec_master/examples/specs/core/List.view.js
c:/Users/lfac/r/spec_master/examples/specs/core/string.utils.js

spec_master --move core/Base.view,core/BaseView
Move was a success

Configuration

settings.json

Spec Master requires a configuration file to work. An example:

{
    "src_modules_path" : "modules",
    "src_specs_path" : "specs",
    "spec_template_path" : "spec_template.jstemplate",
    "sufixes_to_exclude" : ["emplate.js"]
}

The paths are relative to the configuration file.

By default Spec Master will look for a settings.json in the current folder and in src/main/scripts/spec_master/settings.json (its for Maven projects). You can also specify the path via the -s option.

Template

The template is compiled using underscore. An example:

define([
    'chai',
    '<%= path %>'
], function (chai, <%= varName %>) {
    "use strict";

    /*global describe, before, after, beforeEach, afterEach, it, sinon */

    var expect = chai.expect;

    describe('<%= path %>', function () {

    });
});

Two variables are passed as the template data. varName is the recommended variable name for the module and path is its path inside src_modules_path.

License

(The MIT License)

Copyright (c) 2013 Luis Cardoso <luis.cardoso@feedzai.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you