Jasmine-Species - Quick Start

A simple example to get you up and running with Jasmine-Species in no time.

HTML

<script src="https://github.com/headjs/headjs/raw/master/dist/head.load.min.js"></script>
<link rel="stylesheet" href="https://github.com/rudylattae/jasmine-species/raw/master/lib/jasmine-1.0.1/jasmine.css">
<link rel="stylesheet" href="https://github.com/rudylattae/jasmine-species/raw/master/src/jasmine-species/calm.css">
<div class="header"><h1>Jasmine-Species - Quick Start</h1></div>

JavaScript

/**
 * In this example, we are using head.js to manage our script dependencies
 * 1. Jasmine
 * 2. Jasmine-species -- grammar package
 * 3. Jasmine-species -- reporting package
 * 4. Namespace.js -- needed to import our grammar into the global namespace
 */
head.js(
    'https://rawgit.com/smith/namespacedotjs/master/Namespace.js',
    'https://rawgit.com/rudylattae/jasmine-species/master/lib/jasmine-1.0.1/jasmine.js',
    'https://rawgit.com/rudylattae/jasmine-species/master/lib/jasmine-1.0.1/jasmine-html.js',
    'https://rawgit.com/rudylattae/jasmine-species/master/src/jasmine-species/jasmine-grammar.js',
    'https://rawgit.com/rudylattae/jasmine-species/master/src/jasmine-species/jasmine-reporting.js'
);


/**
 * Let's pretend we have been tasked with creating 
 * a simple Page Turning component for an e-book reader.
 * Per the customer, this component must be able to handle
 * basic page turning as well as some advanced functions
 * 
 * Basic stuff
 *   - flip to the next page
 *   - flip to the previous page
 *   - jump to a particular page
 * 
 * Wicked-cool stuff
 *   - skip over a given number of pages
 *   - maintain a navigation history for the book
 *
 *
 * Based on the above criteria, 
 * we could setup our project like so
 * 
 *   |- src/
 *   |   '- ebook.js
 *   |- spec/
 *       |- index.html 
 *       '- PageTurner.spec.js
 */


// src/ebook.js
// ============
// This is the code we created to meet the specs defined in spec/PageTurner.spec.js

var Book = function() {
    this.page = 0;
};

var PageTurner = function(book) {
    this.book = book;
};
PageTurner.prototype.next = function() {
    this.book.page++;
};


// spec/index.html
// ===============
// This brings is the spec runner that pulls in our dependencies and executes the specs
head(function() {
    // spec/index.html
    // ===============

    // import feature, scenario ...
    Namespace.use('jasmine.grammar.FeatureStory.*');  

    // import given, when, then
   ...