Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent 518cee7 commit 8bd95373e5c6a3bd388423420f350f834d6abfe9 @jsoverson committed Oct 21, 2012
Showing with 12,146 additions and 124 deletions.
  1. +2 −25 README.md
  2. +6 −1 grunt.js
  3. +0 −60 spec/PlayerSpec.js
  4. +0 −9 spec/SpecHelper.js
  5. +41 −0 spec/augment.spec.js
  6. +0 −22 src/Player.js
  7. +0 −7 src/Song.js
  8. +26 −0 src/backbone.augment.js
  9. +1,431 −0 vendor/backbone.js
  10. +9,440 −0 vendor/jquery-1.8.2.js
  11. +1,200 −0 vendor/underscore.js
View
@@ -1,31 +1,8 @@
-grunt-jasmine-runner-example
+Backbone.Augment
============================
-[![Build Status](https://secure.travis-ci.org/jsoverson/grunt-jasmine-runner-example.png)](http://travis-ci.org/jsoverson/grunt-jasmine-runner-example)
+[![Build Status](https://secure.travis-ci.org/jsoverson/Backbone.Augment.png)](http://travis-ci.org/jsoverson/Backbone.Augment)
-Example setup for grunt-jasmine-runner.
-
-Browse the source for an example of how to set up your tests to be run via grunt-jasmine-runner.
-
-The application here is the Jasmine example application. The only changes made were jshint comments to allow the linter to pass.
-
-Clone this repo and then run `npm install` to install grunt-jasmine-runner
-
-## Running tests headlessly
-
-`grunt jasmine`
-
-Or to run the default tasks (lint + jasmine) :
-
-`grunt`
-
-## Running tests in a browser
-
-`grunt jasmine-server`
-
-### PhantomJS
-
-This plugin requires phantomjs to run tests headlessly. Get it at [phantomjs.org](http://phantomjs.org/)
### License
View
@@ -10,7 +10,12 @@ module.exports = function(grunt) {
tasks: 'jasmine'
},
jasmine : {
- src : 'src/**/*.js',
+ src : [
+ 'vendor/jquery*.js',
+ 'vendor/underscore.js',
+ 'vendor/backbone.js',
+ 'src/**/*.js'
+ ],
specs : 'spec/**/*.js'
},
jshint: {
View
@@ -1,60 +0,0 @@
-/*globals Player:false, Song: false*/
-
-describe("Player", function() {
- var player;
- var song;
-
- beforeEach(function() {
- player = new Player();
- song = new Song();
- });
-
- it("should be able to play a Song", function() {
- player.play(song);
- expect(player.currentlyPlayingSong).toEqual(song);
-
- //demonstrates use of custom matcher
- expect(player).toBePlaying(song);
- });
-
- describe("when song has been paused", function() {
- beforeEach(function() {
- player.play(song);
- player.pause();
- });
-
- it("should indicate that the song is currently paused", function() {
- expect(player.isPlaying).toBeFalsy();
-
- // demonstrates use of 'not' with a custom matcher
- expect(player).not.toBePlaying(song);
- });
-
- it("should be possible to resume", function() {
- player.resume();
- expect(player.isPlaying).toBeTruthy();
- expect(player.currentlyPlayingSong).toEqual(song);
- });
- });
-
- // demonstrates use of spies to intercept and test method calls
- it("tells the current song if the user has made it a favorite", function() {
- spyOn(song, 'persistFavoriteStatus');
-
- player.play(song);
- player.makeFavorite();
-
- expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
- });
-
- //demonstrates use of expected exceptions
- describe("#resume", function() {
- it("should throw an exception if song is already playing", function() {
- player.play(song);
-
- expect(function() {
- player.resume();
- }).toThrow("song is already playing");
- });
- });
-});
View
@@ -1,9 +0,0 @@
-beforeEach(function() {
- this.addMatchers({
- toBePlaying: function(expectedSong) {
- var player = this.actual;
- return player.currentlyPlayingSong === expectedSong &&
- player.isPlaying;
- }
- });
-});
View
@@ -0,0 +1,41 @@
+/*globals Backbone*/
+
+
+describe("augment", function() {
+ 'use strict';
+
+ it("should exist on all core backbone objects", function() {
+ expect(typeof Backbone.Model.augment).toEqual('function');
+ expect(typeof Backbone.Collection.augment).toEqual('function');
+ expect(typeof Backbone.View.augment).toEqual('function');
+ });
+
+ it("should exist on extended objects", function() {
+ var NewView = Backbone.View.extend({});
+ expect(typeof NewView.augment).toEqual('function');
+ });
+
+ it("should call augments' augment() when augmenter augments.", function() {
+ var augment = {
+ augment : jasmine.createSpy('augment()')
+ };
+ var NewView = Backbone.View.extend({});
+ NewView.augment(augment);
+ expect(augment.augment).toHaveBeenCalled();
+ });
+
+ it("should return the augmented object from augment()", function() {
+ var augmentSpy = jasmine.createSpy('function from augment');
+ var augment = {
+ augment : function(Orig) {
+ return Orig.extend({
+ foo : augmentSpy
+ });
+ }
+ };
+ var NewView = Backbone.View.augment(augment).extend({});
+ var newViewInstance = new NewView();
+ newViewInstance.foo();
+ expect(augmentSpy).toHaveBeenCalled();
+ });
+});
View
@@ -1,22 +0,0 @@
-function Player() {
-}
-Player.prototype.play = function(song) {
- this.currentlyPlayingSong = song;
- this.isPlaying = true;
-};
-
-Player.prototype.pause = function() {
- this.isPlaying = false;
-};
-
-Player.prototype.resume = function() {
- if (this.isPlaying) {
- throw new Error("song is already playing");
- }
-
- this.isPlaying = true;
-};
-
-Player.prototype.makeFavorite = function() {
- this.currentlyPlayingSong.persistFavoriteStatus(true);
-};
View
@@ -1,7 +0,0 @@
-function Song() {
-}
-
-Song.prototype.persistFavoriteStatus = function(value) {
- // something complicated
- throw new Error("not yet implemented");
-};
@@ -0,0 +1,26 @@
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define(['backbone'], factory);
+ } else {
+ // Browser globals
+ factory(root.Backbone);
+ }
+}(this, function (Backbone) {
+ "use strict";
+
+ function augment(/* augments... */) {
+ var self = this;
+ for (var i = 0; i < arguments.length; i++) {
+ var aug = arguments[i];
+ if (aug.augment) {
+ self = aug.augment(self);
+ }
+ }
+ return self;
+ }
+
+ Backbone.Model.augment = Backbone.Collection.augment = Backbone.View.augment = augment;
+
+ return augment;
+}));
Oops, something went wrong.

0 comments on commit 8bd9537

Please sign in to comment.