diff --git a/LICENSE b/LICENSE index 38e1b6dde..199f991af 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,6 @@ -Copyright (c) 2010 David Laing +The MIT License (MIT) + +Copyright (c) 2010-2014 David Laing and Greg Malcolm Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/koans/AboutApplyingWhatWeHaveLearnt.js b/koans/AboutApplyingWhatWeHaveLearnt.js index 9a7bdbdf4..eccc93763 100644 --- a/koans/AboutApplyingWhatWeHaveLearnt.js +++ b/koans/AboutApplyingWhatWeHaveLearnt.js @@ -4,7 +4,7 @@ describe("About Applying What We Have Learnt", function() { var products; - beforeEach(function () { + beforeEach(function () { products = [ { name: "Sonoma", ingredients: ["artichoke", "sundried tomatoes", "mushrooms"], containsNuts: false }, { name: "Pizza Primavera", ingredients: ["roma", "sundried tomatoes", "goats cheese", "rosemary"], containsNuts: false }, @@ -47,14 +47,14 @@ describe("About Applying What We Have Learnt", function() { /*********************************************************************************/ it("should add all the natural numbers below 1000 that are multiples of 3 or 5 (imperative)", function () { - + var sum = 0; - for(var i=1; i<=1000; i+=1) { + for(var i=1; i<1000; i+=1) { if (i % 3 === 0 || i % 5 === 0) { sum += i; } } - + expect(sum).toBe(FILL_ME_IN); }); @@ -62,7 +62,7 @@ describe("About Applying What We Have Learnt", function() { var sum = FILL_ME_IN; /* try chaining range() and reduce() */ - expect(234168).toBe(FILL_ME_IN); + expect(233168).toBe(FILL_ME_IN); }); /*********************************************************************************/ @@ -90,20 +90,20 @@ describe("About Applying What We Have Learnt", function() { /* UNCOMMENT FOR EXTRA CREDIT */ /* it("should find the largest prime factor of a composite number", function () { - + }); it("should find the largest palindrome made from the product of two 3 digit numbers", function () { - + }); it("should find the smallest number divisible by each of the numbers 1 to 20", function () { - - + + }); it("should find the difference between the sum of the squares and the square of the sums", function () { - + }); it("should find the 10001st prime", function () { diff --git a/koans/AboutArrays.js b/koans/AboutArrays.js index 147162963..f9b33f8cc 100644 --- a/koans/AboutArrays.js +++ b/koans/AboutArrays.js @@ -1,9 +1,9 @@ describe("About Arrays", function() { - //We shall contemplate truth by testing reality, via spec expectations. + //We shall contemplate truth by testing reality, via spec expectations. it("should create arrays", function() { var emptyArray = []; - expect(typeof(emptyArray)).toBe(FILL_ME_IN); //A mistake? - http:javascript.crockford.com/remedial.html + expect(typeof(emptyArray)).toBe(FILL_ME_IN); //A mistake? - http://javascript.crockford.com/remedial.html expect(emptyArray.length).toBe(FILL_ME_IN); var multiTypeArray = [0, 1, "two", function () { return 3; }, {value1: 4, value2: 5}, [6, 7]]; @@ -18,13 +18,13 @@ describe("About Arrays", function() { it("should understand array literals", function () { var array = []; expect(array).toEqual([]); - + array[0] = 1; expect(array).toEqual([1]); - + array[1] = 2; expect(array).toEqual([1, FILL_ME_IN]); - + array.push(3); expect(array).toEqual(FILL_ME_IN); }); @@ -36,7 +36,7 @@ describe("About Arrays", function() { fourNumberArray.push(5, 6); expect(fourNumberArray.length).toBe(FILL_ME_IN); - var tenEmptyElementArray = new Array(10); + var tenEmptyElementArray = new Array(10); expect(tenEmptyElementArray.length).toBe(FILL_ME_IN); tenEmptyElementArray.length = 5; @@ -45,7 +45,7 @@ describe("About Arrays", function() { it("should slice arrays", function () { var array = ["peanut", "butter", "and", "jelly"]; - + expect(array.slice(0, 1)).toEqual(FILL_ME_IN); expect(array.slice(0, 2)).toEqual(FILL_ME_IN); expect(array.slice(2, 2)).toEqual(FILL_ME_IN); @@ -78,7 +78,7 @@ describe("About Arrays", function() { array.push(3); expect(array).toEqual(FILL_ME_IN); - + var poppedValue = array.pop(); expect(poppedValue).toBe(FILL_ME_IN); expect(array).toEqual(FILL_ME_IN); @@ -89,9 +89,9 @@ describe("About Arrays", function() { array.unshift(3); expect(array).toEqual(FILL_ME_IN); - + var shiftedValue = array.shift(); expect(shiftedValue).toEqual(FILL_ME_IN); expect(array).toEqual(FILL_ME_IN); - }); + }); }); diff --git a/koans/AboutExpects.js b/koans/AboutExpects.js index 52148b243..a7ced620a 100644 --- a/koans/AboutExpects.js +++ b/koans/AboutExpects.js @@ -1,38 +1,38 @@ describe("About Expects", function() { - //We shall contemplate truth by testing reality, via spec expectations. + // We shall contemplate truth by testing reality, via spec expectations. it("should expect true", function() { expect(false).toBeTruthy(); //This should be true }); - //To understand reality, we must compare our expectations against reality. - it("should expect equality", function () { - var expectedValue = FILL_ME_IN; - var actualValue = 1 + 1; - - expect(actualValue === expectedValue).toBeTruthy(); - }); - - //Some ways of asserting equality are better than others. - it("should assert equality a better way", function () { - var expectedValue = FILL_ME_IN; - var actualValue = 1 + 1; - + // To understand reality, we must compare our expectations against reality. + it("should expect equality", function () { + var expectedValue = FILL_ME_IN; + var actualValue = 1 + 1; + + expect(actualValue === expectedValue).toBeTruthy(); + }); + + // Some ways of asserting equality are better than others. + it("should assert equality a better way", function () { + var expectedValue = FILL_ME_IN; + var actualValue = 1 + 1; + // toEqual() compares using common sense equality. - expect(actualValue).toEqual(expectedValue); + expect(actualValue).toEqual(expectedValue); }); - //Sometimes you need to be really exact about what you "type". - it("should assert equality with ===", function () { - var expectedValue = FILL_ME_IN; - var actualValue = (1 + 1).toString(); - + // Sometimes you need to be really exact about what you "type." + it("should assert equality with ===", function () { + var expectedValue = FILL_ME_IN; + var actualValue = (1 + 1).toString(); + // toBe() will always use === to compare. - expect(actualValue).toBe(expectedValue); - }); + expect(actualValue).toBe(expectedValue); + }); - //Sometimes we will ask you to fill in the values. + // Sometimes we will ask you to fill in the values. it("should have filled in values", function () { - expect(1 + 1).toEqual(FILL_ME_IN); + expect(1 + 1).toEqual(FILL_ME_IN); }); }); diff --git a/koans/AboutFunctions.js b/koans/AboutFunctions.js index 1a2f53cc9..569100806 100644 --- a/koans/AboutFunctions.js +++ b/koans/AboutFunctions.js @@ -1,26 +1,26 @@ describe("About Functions", function() { it("should declare functions", function() { - + function add(a, b) { return a + b; } - + expect(add(1, 2)).toBe(FILL_ME_IN); }); it("should know internal variables override outer variables", function () { var message = "Outer"; - + function getMessage() { return message; } - + function overrideMessage() { var message = "Inner"; return message; } - + expect(getMessage()).toBe(FILL_ME_IN); expect(overrideMessage()).toBe(FILL_ME_IN); expect(message).toBe(FILL_ME_IN); @@ -29,9 +29,9 @@ describe("About Functions", function() { it("should have lexical scoping", function () { var variable = "top-level"; function parentfunction() { - var variable = "local"; + var variable = "local"; function childfunction() { - return variable; + return variable; } return childfunction(); } @@ -39,47 +39,44 @@ describe("About Functions", function() { }); it("should use lexical scoping to synthesise functions", function () { - - function makeIncreaseByFunction(increaseByAmount) + + function makeMysteryFunction(makerValue) { - var increaseByFunction = function increaseBy(numberToIncrease) + var newFunction = function doMysteriousThing(param) { - return numberToIncrease + increaseByAmount; + return makerValue + param; }; - return increaseByFunction; + return newFunction; } - - var increaseBy3 = makeIncreaseByFunction(3); - var increaseBy5 = makeIncreaseByFunction(5); - - expect(increaseBy3(10) + increaseBy5(10)).toBe(FILL_ME_IN); + + var mysteryFunction3 = makeMysteryFunction(3); + var mysteryFunction5 = makeMysteryFunction(5); + + expect(mysteryFunction3(10) + mysteryFunction5(5)).toBe(FILL_ME_IN); }); it("should allow extra function arguments", function () { - - function returnFirstArg(firstArg) - { + + function returnFirstArg(firstArg) { return firstArg; } - + expect(returnFirstArg("first", "second", "third")).toBe(FILL_ME_IN); - - function returnSecondArg(firstArg, secondArg) - { + + function returnSecondArg(firstArg, secondArg) { return secondArg; } - + expect(returnSecondArg("only give first arg")).toBe(FILL_ME_IN); - - function returnAllArgs() - { + + function returnAllArgs() { var argsArray = []; for (var i = 0; i < arguments.length; i += 1) { argsArray.push(arguments[i]); } return argsArray.join(","); } - + expect(returnAllArgs("first", "second", "third")).toBe(FILL_ME_IN); }); @@ -88,27 +85,16 @@ describe("About Functions", function() { var appendRules = function (name) { return name + " rules!"; }; - + var appendDoubleRules = function (name) { return name + " totally rules!"; }; - + var praiseSinger = { givePraise: appendRules }; expect(praiseSinger.givePraise("John")).toBe(FILL_ME_IN); - + praiseSinger.givePraise = appendDoubleRules; expect(praiseSinger.givePraise("Mary")).toBe(FILL_ME_IN); - - }); - it("should use function body as a string", function () { - var add = new Function("a", "b", "return a + b;"); - expect(add(1, 2)).toBe(FILL_ME_IN); - - var multiply = function (a, b) { - //An internal comment - return a * b; - }; - expect(multiply.toString()).toBe(FILL_ME_IN); - }); + }); }); diff --git a/koans/AboutHigherOrderFunctions.js b/koans/AboutHigherOrderFunctions.js index 2fc64e490..07c416792 100644 --- a/koans/AboutHigherOrderFunctions.js +++ b/koans/AboutHigherOrderFunctions.js @@ -10,29 +10,29 @@ describe("About Higher Order Functions", function () { it("should use filter to return array items that meet a criteria", function () { var numbers = [1,2,3]; var odd = _(numbers).filter(function (x) { return x % 2 !== 0 }); - + expect(odd).toEqual(FILL_ME_IN); expect(odd.length).toBe(FILL_ME_IN); expect(numbers.length).toBe(FILL_ME_IN); }); - + it("should use 'map' to transform each element", function () { var numbers = [1, 2, 3]; var numbersPlus1 = _(numbers).map(function(x) { return x + 1 }); - + expect(numbersPlus1).toEqual(FILL_ME_IN); expect(numbers).toEqual(FILL_ME_IN); }); - + it("should use 'reduce' to update the same result on each iteration", function () { var numbers = [1, 2, 3]; var reduction = _(numbers).reduce( function(/* result from last call */ memo, /* current */ x) { return memo + x }, /* initial */ 0); - + expect(reduction).toBe(FILL_ME_IN); expect(numbers).toEqual(FILL_ME_IN); }); - + it("should use 'forEach' for simple iteration", function () { var numbers = [1,2,3]; var msg = ""; @@ -41,11 +41,11 @@ describe("About Higher Order Functions", function () { }; _(numbers).forEach(isEven); - + expect(msg).toEqual(FILL_ME_IN); expect(numbers).toEqual(FILL_ME_IN); }); - + it("should use 'all' to test whether all items pass condition", function () { var onlyEven = [2,4,6]; var mixedBag = [2,4,5,6]; @@ -55,7 +55,7 @@ describe("About Higher Order Functions", function () { expect(_(onlyEven).all(isEven)).toBe(FILL_ME_IN); expect(_(mixedBag).all(isEven)).toBe(FILL_ME_IN); }); - + it("should use 'any' to test if any items passes condition" , function () { var onlyEven = [2,4,6]; var mixedBag = [2,4,5,6]; diff --git a/koans/AboutInheritance.js b/koans/AboutInheritance.js index 7e305a711..5dba545b0 100644 --- a/koans/AboutInheritance.js +++ b/koans/AboutInheritance.js @@ -1,7 +1,7 @@ function Muppet(age, hobby) { this.age = age; - this.hobby = hobby; - + this.hobby = hobby; + this.answerNanny = function(){ return "Everything's cool!"; } @@ -10,7 +10,7 @@ function Muppet(age, hobby) { function SwedishChef(age, hobby, mood) { Muppet.call(this, age, hobby); this.mood = mood; - + this.cook = function() { return "Mmmm soup!"; } @@ -23,20 +23,20 @@ describe("About inheritance", function() { this.muppet = new Muppet(2, "coding"); this.swedishChef = new SwedishChef(2, "cooking", "chillin"); }); - + it("should be able to call a method on the derived object", function() { expect(this.swedishChef.cook()).toEqual(FILL_ME_IN); }); - + it("should be able to call a method on the base object", function() { expect(this.swedishChef.answerNanny()).toEqual(FILL_ME_IN); }); - + it("should set constructor parameters on the base object", function() { expect(this.swedishChef.age).toEqual(FILL_ME_IN); expect(this.swedishChef.hobby).toEqual(FILL_ME_IN); }); - + it("should set constructor parameters on the derived object", function() { expect(this.swedishChef.mood).toEqual(FILL_ME_IN); }); @@ -52,7 +52,7 @@ Object.prototype.beget = function () { function Gonzo(age, hobby, trick) { Muppet.call(this, age, hobby); this.trick = trick; - + this.doTrick = function() { return this.trick; } @@ -65,20 +65,20 @@ describe("About Crockford's inheritance improvement", function() { beforeEach(function(){ this.gonzo = new Gonzo(3, "daredevil performer", "eat a tire"); }); - + it("should be able to call a method on the derived object", function() { expect(this.gonzo.doTrick()).toEqual(FILL_ME_IN); }); - + it("should be able to call a method on the base object", function() { expect(this.gonzo.answerNanny()).toEqual(FILL_ME_IN); }); - + it("should set constructor parameters on the base object", function() { expect(this.gonzo.age).toEqual(FILL_ME_IN); expect(this.gonzo.hobby).toEqual(FILL_ME_IN); }); - + it("should set constructor parameters on the derived object", function() { expect(this.gonzo.trick).toEqual(FILL_ME_IN); }); diff --git a/koans/AboutMutability.js b/koans/AboutMutability.js index 1e4511758..fd9b69af2 100644 --- a/koans/AboutMutability.js +++ b/koans/AboutMutability.js @@ -3,7 +3,7 @@ describe("About Mutability", function() { it("should expect object properties to be public and mutable", function () { var aPerson = {firstname: "John", lastname: "Smith" }; aPerson.firstname = "Alan"; - + expect(aPerson.firstname).toBe(FILL_ME_IN); }); @@ -15,7 +15,7 @@ describe("About Mutability", function() { } var aPerson = new Person ("John", "Smith"); aPerson.firstname = "Alan"; - + expect(aPerson.firstname).toBe(FILL_ME_IN); }); @@ -28,14 +28,14 @@ describe("About Mutability", function() { Person.prototype.getFullName = function () { return this.firstname + " " + this.lastname; }; - + var aPerson = new Person ("John", "Smith"); expect(aPerson.getFullName()).toBe(FILL_ME_IN); - + aPerson.getFullName = function () { return this.lastname + ", " + this.firstname; }; - + expect(aPerson.getFullName()).toBe(FILL_ME_IN); }); @@ -43,7 +43,7 @@ describe("About Mutability", function() { function Person(firstname, lastname) { var fullName = firstname + " " + lastname; - + this.getFirstName = function () { return firstname; }; this.getLastName = function () { return lastname; }; this.getFullName = function () { return fullName; }; @@ -53,7 +53,7 @@ describe("About Mutability", function() { aPerson.firstname = "Penny"; aPerson.lastname = "Andrews"; aPerson.fullName = "Penny Andrews"; - + expect(aPerson.getFirstName()).toBe(FILL_ME_IN); expect(aPerson.getLastName()).toBe(FILL_ME_IN); expect(aPerson.getFullName()).toBe(FILL_ME_IN); @@ -61,7 +61,7 @@ describe("About Mutability", function() { aPerson.getFullName = function () { return aPerson.lastname + ", " + aPerson.firstname; }; - + expect(aPerson.getFullName()).toBe(FILL_ME_IN); }); diff --git a/koans/AboutObjects.js b/koans/AboutObjects.js index ca537f17e..9f9ed93cc 100644 --- a/koans/AboutObjects.js +++ b/koans/AboutObjects.js @@ -1,58 +1,58 @@ describe("About Objects", function () { describe("Properties", function () { - var meglomaniac; + var megalomaniac; beforeEach(function () { - meglomaniac = { mastermind: "Joker", henchwoman: "Harley" }; + megalomaniac = { mastermind: "Joker", henchwoman: "Harley" }; }); it("should confirm objects are collections of properties", function () { - expect(meglomaniac.mastermind).toBe(FILL_ME_IN); - }); + expect(megalomaniac.mastermind).toBe(FILL_ME_IN); + }); it("should confirm that properties are case sensitive", function () { - expect(meglomaniac.henchwoman).toBe(FILL_ME_IN); - expect(meglomaniac.henchWoman).toBe(FILL_ME_IN); + expect(megalomaniac.henchwoman).toBe(FILL_ME_IN); + expect(megalomaniac.henchWoman).toBe(FILL_ME_IN); }); }); - + it("should know properties that are functions act like methods", function () { - var meglomaniac = { - mastermind : "Brain", + var megalomaniac = { + mastermind : "Brain", henchman: "Pinky", battleCry: function (noOfBrains) { return "They are " + this.henchman + " and the" + Array(noOfBrains + 1).join(" " + this.mastermind); } }; - - battleCry = meglomaniac.battleCry(4); + + var battleCry = megalomaniac.battleCry(4); expect(FILL_ME_IN).toMatch(battleCry); }); it("should confirm that when a function is attached to an object, 'this' refers to the object", function () { - var currentDate = new Date() + var currentDate = new Date(); var currentYear = (currentDate.getFullYear()); - var meglomaniac = { - mastermind: "James Wood", + var megalomaniac = { + mastermind: "James Wood", henchman: "Adam West", birthYear: 1970, calculateAge: function () { - return currentYear - this.birthYear; + return currentYear - this.birthYear; } }; - + expect(currentYear).toBe(FILL_ME_IN); - expect(meglomaniac.calculateAge()).toBe(FILL_ME_IN); + expect(megalomaniac.calculateAge()).toBe(FILL_ME_IN); }); describe("'in' keyword", function () { - var meglomaniac; + var megalomaniac; beforeEach(function () { - meglomaniac = { - mastermind: "The Monarch", + megalomaniac = { + mastermind: "The Monarch", henchwoman: "Dr Girlfriend", theBomb: true }; @@ -60,29 +60,29 @@ describe("About Objects", function () { it("should have the bomb", function () { - hasBomb = "theBomb" in meglomaniac; - + var hasBomb = "theBomb" in megalomaniac; + expect(hasBomb).toBe(FILL_ME_IN); }); it("should not have the detonator however", function () { - hasDetonator = "theDetonator" in meglomaniac; - + var hasDetonator = "theDetonator" in megalomaniac; + expect(hasDetonator).toBe(FILL_ME_IN); - }); + }); }); it("should know that properties can be added and deleted", function () { - var meglomaniac = { mastermind : "Agent Smith", henchman: "Agent Smith" }; + var megalomaniac = { mastermind : "Agent Smith", henchman: "Agent Smith" }; + + expect("secretary" in megalomaniac).toBe(FILL_ME_IN); - expect("secretary" in meglomaniac).toBe(FILL_ME_IN); + megalomaniac.secretary = "Agent Smith"; + expect("secretary" in megalomaniac).toBe(FILL_ME_IN); - meglomaniac.secretary = "Agent Smith"; - expect("secretary" in meglomaniac).toBe(FILL_ME_IN); - - delete meglomaniac.henchman; - expect("henchman" in meglomaniac).toBe(FILL_ME_IN); + delete megalomaniac.henchman; + expect("henchman" in megalomaniac).toBe(FILL_ME_IN); }); @@ -95,14 +95,14 @@ describe("About Objects", function () { var simpleCircle = new Circle(10); var colouredCircle = new Circle(5); colouredCircle.colour = "red"; - + expect(simpleCircle.colour).toBe(FILL_ME_IN); expect(colouredCircle.colour).toBe(FILL_ME_IN); - + Circle.prototype.describe = function () { return "This circle has a radius of: " + this.radius; }; - + expect(simpleCircle.describe()).toBe(FILL_ME_IN); expect(colouredCircle.describe()).toBe(FILL_ME_IN); }); diff --git a/lib/jasmine/jskoans-jasmine-html.js b/lib/jasmine/jskoans-jasmine-html.js index 7b63e9448..06faea060 100644 --- a/lib/jasmine/jskoans-jasmine-html.js +++ b/lib/jasmine/jskoans-jasmine-html.js @@ -189,7 +189,7 @@ JsKoansReporter.prototype.reportSpecResults = function(spec) { this.createDom('div', { className: 'errorMessage' }, result.message) ); messagesDiv.appendChild( - this.createDom('div', { className: 'description' }, "Please meditiate on the following code:") + this.createDom('div', { className: 'description' }, "Please meditate on the following code:") ); if (result.trace.stack) {