Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of the example project including source code and unit test code along with a grunt task for running the tests from the command line.
- Loading branch information
0 parents
commit 13136d7
Showing
14 changed files
with
4,476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# qunit-require | ||
An example which shows how to get QUnit and RequireJS to play nice with each other. | ||
|
||
For more information, please refer my [blog entry]( http://www.jonnyreeves.co.uk/2012/qunit-and-requirejs) which describes this setup in further detail, or just dive head-first into the code comments :) | ||
|
||
## Running the Tests | ||
Although this example project has almost zero real world value, you can execute the default [grunt](https://github.com/cowboy/grunt) task to lint and execute the unit tests from the command line. From the root of the project, issue: | ||
|
||
grunt | ||
|
||
Alternativley, open the [Test Runner](https://raw.github.com/jonnyreeves/qunit-require/master/tests/tests.html] in your web browser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*global module:false*/ | ||
module.exports = function(grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
lint: { | ||
src: ['src/example/**/*.js'], | ||
tests: ['tests/example/**/*.js'] | ||
}, | ||
qunit: { | ||
files: ['tests/tests.html'] | ||
}, | ||
jshint: { | ||
options: { | ||
curly: true, | ||
eqeqeq: true, | ||
immed: true, | ||
latedef: true, | ||
newcap: true, | ||
noarg: true, | ||
sub: true, | ||
undef: true, | ||
boss: true, | ||
eqnull: true, | ||
browser: true | ||
}, | ||
|
||
src: { | ||
globals: { define: true } | ||
}, | ||
tests: { | ||
globals: { QUnit: true, define: true } | ||
} | ||
}, | ||
uglify: {} | ||
}); | ||
|
||
// Default task. | ||
grunt.registerTask('default', 'lint qunit'); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
define(function (require) { | ||
"use strict"; | ||
|
||
// Represents a Computer Game. | ||
function Game(name, pegiRating) { | ||
this._name = name; | ||
this._pegiRating = pegiRating; | ||
} | ||
|
||
// Define the Game object methods. | ||
Game.prototype = { | ||
|
||
// Repoint the Constructor function. | ||
constructor: Game, | ||
|
||
// Returns true if this Game is suitible for the supplied age | ||
isSuitibleFor: function (age) { | ||
|
||
// Forward to the requires to the PegiRating object, applies the | ||
// Law of Demeter (least knowledge). | ||
return this._pegiRating.isSuitibleFor(age); | ||
}, | ||
|
||
toString: function () { | ||
return this._name + " (" + this._pegiRating + ")"; | ||
} | ||
}; | ||
|
||
// Export the Constructor function. | ||
return Game; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
define(function (require) { | ||
"use strict"; | ||
|
||
// Represents a PegiRating value | ||
function PegiRating(minAge) { | ||
this._minAge = minAge; | ||
} | ||
|
||
// Define the Game object methods. | ||
PegiRating.prototype = { | ||
|
||
// Repoint the Constructor function. | ||
constructor: PegiRating, | ||
|
||
// Returns true if the supplied age range is equal to or greater than | ||
// the minimum age indicated by this Pegi Rating. | ||
isSuitibleFor: function(age) { | ||
return age >= this._minAge; | ||
}, | ||
|
||
toString: function () { | ||
return "PEGI " + this._minAge; | ||
} | ||
}; | ||
|
||
// Don't export the Constructor, instead export a hash of values as the | ||
// PegiRating module is intended to be used as an Enum (all valid values | ||
// are known ahead of execution). | ||
return { | ||
PEGI_3: new PegiRating(3), | ||
PEGI_7: new PegiRating(7), | ||
PEGI_12: new PegiRating(12), | ||
PEGI_16: new PegiRating(16), | ||
PEGI_18: new PegiRating(18) | ||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
define(function (require) { | ||
"use strict"; | ||
|
||
// Import underscore. | ||
var _ = require("vendor/underscore"); | ||
|
||
// Represents a Player who onws a collection of Comptuer Games. | ||
function Player(name, age, games) { | ||
this._name = name; | ||
this._age = age; | ||
this._games = _.isArray(games) ? games.slice() : []; | ||
} | ||
|
||
// Define the Player object methods. | ||
Player.prototype = { | ||
|
||
// Repoint the Constructor function. | ||
constructor: Player, | ||
|
||
// Returns an Array of Games which this Player should not have in their | ||
// collection because they are indenteded for an older audience based | ||
// on their Pegi Rating. | ||
getUnsuitableGames: function () { | ||
var self = this; | ||
|
||
return _.filter(this._games, function (game) { | ||
return !game.isSuitibleFor(self._age); | ||
}); | ||
}, | ||
|
||
toString: function () { | ||
return this._name + " (" + this._age + ") has " + | ||
this._games.length + " game(s)"; | ||
} | ||
}; | ||
|
||
// Export the Constructor function. | ||
return Player; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var require = { | ||
shim: { | ||
"vendor/underscore": { | ||
exports: "_" | ||
} | ||
} | ||
}; |
Oops, something went wrong.