Permalink
Browse files

switch to using chai instead of expect

  • Loading branch information...
rmurphey committed Nov 20, 2012
1 parent 26df5d6 commit c87e21369c81107e85ea08410cff0ef4ba8d9a0f
View
@@ -12,7 +12,7 @@ module.exports = function(opts) {
}, opts || {});
site.configure(function() {
- [ 'app', 'lib', 'tests', 'data' ].forEach(function(dir) {
+ [ 'app', 'lib', 'tests', 'data', 'answers' ].forEach(function(dir) {
site.use('/' + dir, staticDir(opts.baseDir + dir));
});
site.use(express.bodyParser());
View
@@ -12,20 +12,20 @@ define([
});
it("you should be able to determine the location of an item in an array", function() {
- expect(answers.indexOf(a, 3)).to.be(2);
- expect(answers.indexOf(a, 5)).to.be(-1);
+ expect(answers.indexOf(a, 3)).to.eql(2);
+ expect(answers.indexOf(a, 5)).to.eql(-1);
});
it("you should be able to add the values of an array", function() {
- expect(answers.sum(a)).to.be(10);
+ expect(answers.sum(a)).to.eql(10);
});
it("you should be able to remove a value from an array", function() {
a.push(2); // Make sure the value appears more than one time
var result = answers.remove(a, 2);
expect(result).to.have.length(3);
- expect(result.join(' ')).to.be('1 3 4');
+ expect(result.join(' ')).to.eql('1 3 4');
});
it("you should be able to remove a value from an array, returning the original array", function() {
@@ -34,7 +34,7 @@ define([
var result = answers.removeWithoutCopy(a, 2);
expect(result).to.have.length(3);
- expect(result.join(' ')).to.be('1 3 4');
+ expect(result.join(' ')).to.eql('1 3 4');
// make sure that you return the same array instance
expect(result).equal(a);
@@ -44,55 +44,55 @@ define([
var result = answers.append(a, 10);
expect(result).to.have.length(5);
- expect(result[result.length - 1]).to.be(10);
+ expect(result[result.length - 1]).to.eql(10);
});
it("you should be able to remove the last item of an array", function() {
var result = answers.truncate(a);
expect(result).to.have.length(3);
- expect(result.join(' ')).to.be('1 2 3');
+ expect(result.join(' ')).to.eql('1 2 3');
});
it("you should be able to join together two arrays", function() {
var c = [ 'a', 'b', 'c', 1 ],
result = answers.concat(a, c);
expect(result).to.have.length(8);
- expect(result.join(' ')).to.be('1 2 3 4 a b c 1');
+ expect(result.join(' ')).to.eql('1 2 3 4 a b c 1');
});
it("you should be able to add an item anywhere in an array", function() {
var result = answers.insert(a, 'z', 2);
expect(result).to.have.length(5);
- expect(result.join(' ')).to.be('1 2 z 3 4');
+ expect(result.join(' ')).to.eql('1 2 z 3 4');
});
it("you should be able to count the occurences of an item in an array", function() {
var result = answers.count([ 1, 1, 1, 2, 1, 3 ], 1);
- expect(result).to.be(4);
+ expect(result).to.eql(4);
});
it("you should be able to find duplicates in an array", function() {
var result = answers.duplicates([ 1, 2, 4, 4, 3, 3, 1, 5 ]);
expect(result).to.have.length(3);
- expect(result.sort().join(' ')).to.be('1 3 4');
+ expect(result.sort().join(' ')).to.eql('1 3 4');
});
it("you should be able to square each number in an array", function() {
var result = answers.square(a);
expect(result).to.have.length(4);
- expect(result.join(' ')).to.be('1 4 9 16');
+ expect(result.join(' ')).to.eql('1 4 9 16');
});
it("you should be able to find all occurrences of an item in an array", function() {
var result = answers.findAllOccurrences('abcdefabc'.split(''), 'a');
- expect(result.join(' ')).to.be('0 6');
+ expect(result.join(' ')).to.eql('0 6');
});
});
View
@@ -16,25 +16,25 @@ define([
answers.async(true).then(function(result) {
flag = result;
- expect(flag).to.be(true);
+ expect(flag).to.eql(true);
finish(done);
});
answers.async('success').then(function(result) {
flag = result;
- expect(flag).to.be('success');
+ expect(flag).to.eql('success');
finish(done);
});
- expect(flag).to.be(false);
+ expect(flag).to.eql(false);
});
it("you should be able to receive data from the server and manipulate it", function(done) {
var url = '/data/testdata.json';
answers.manipulateRemoteData(url).then(function(result) {
expect(result).to.have.length(5);
- expect(result.join(' ')).to.be('Adam Alex Matt Paul Rebecca');
+ expect(result.join(' ')).to.eql('Adam Alex Matt Paul Rebecca');
done();
});
});
View
@@ -8,24 +8,24 @@ define([
describe("best practices", function(){
it("you should avoid global variables", function() {
answers.globals();
- expect(window.myObject).not.to.be.ok();
+ expect(window.myObject).not.to.be.ok;
});
it("you should declare functions safely", function() {
var val = answers.functions(true);
- expect(val).to.be('a');
+ expect(val).to.eql('a');
});
it("you should use parseInt correctly", function() {
- expect(answers.parseInt('12')).to.be(12);
- expect(answers.parseInt('12px')).to.be(12);
- expect(answers.parseInt('012')).to.be(12);
+ expect(answers.parseInt('12')).to.eql(12);
+ expect(answers.parseInt('12px')).to.eql(12);
+ expect(answers.parseInt('012')).to.eql(12);
});
it("you should understand strict comparison", function() {
- expect(answers.identity(1, '1')).to.be(false);
- expect(answers.identity(1, 1)).to.be(true);
- expect(answers.identity(0, false)).to.be(false);
+ expect(answers.identity(1, '1')).to.eql(false);
+ expect(answers.identity(1, 1)).to.eql(true);
+ expect(answers.identity(0, false)).to.eql(false);
});
});
View
@@ -12,20 +12,20 @@ define([
num = Math.floor(Math.random() * 10) + 1;
}
- expect(answers.fizzBuzz()).not.to.be.ok();
- expect(answers.fizzBuzz(2)).to.be(2);
- expect(answers.fizzBuzz(101)).to.be(101);
+ expect(answers.fizzBuzz()).not.to.be.ok;
+ expect(answers.fizzBuzz(2)).to.eql(2);
+ expect(answers.fizzBuzz(101)).to.eql(101);
- expect(answers.fizzBuzz(3)).to.be('fizz');
- expect(answers.fizzBuzz(6)).to.be('fizz');
- expect(answers.fizzBuzz(num * 3)).to.be('fizz');
+ expect(answers.fizzBuzz(3)).to.eql('fizz');
+ expect(answers.fizzBuzz(6)).to.eql('fizz');
+ expect(answers.fizzBuzz(num * 3)).to.eql('fizz');
- expect(answers.fizzBuzz(5)).to.be('buzz');
- expect(answers.fizzBuzz(10)).to.be('buzz');
- expect(answers.fizzBuzz(num * 5)).to.be('buzz');
+ expect(answers.fizzBuzz(5)).to.eql('buzz');
+ expect(answers.fizzBuzz(10)).to.eql('buzz');
+ expect(answers.fizzBuzz(num * 5)).to.eql('buzz');
- expect(answers.fizzBuzz(15)).to.be('fizzbuzz');
- expect(answers.fizzBuzz(num * 3 * 5)).to.be('fizzbuzz');
+ expect(answers.fizzBuzz(15)).to.eql('fizzbuzz');
+ expect(answers.fizzBuzz(num * 3 * 5)).to.eql('fizzbuzz');
});
});
});
View
@@ -19,8 +19,8 @@ define([
it("you should be able to use an array as arguments when calling a function", function() {
var result = answers.argsAsArray(sayIt, [ 'Hello', 'Ellie', '!' ]);
- expect(result).to.be('Hello, Ellie!');
- expect(sayItCalled).to.be.ok();
+ expect(result).to.eql('Hello, Ellie!');
+ expect(sayItCalled).to.be.ok;
});
it("you should be able to change the context in which a function is called", function() {
@@ -33,13 +33,13 @@ define([
};
var result = answers.speak(speak, obj);
- expect(result).to.be('Hello, Rebecca!!!');
- expect(sayItCalled).to.be.ok();
+ expect(result).to.eql('Hello, Rebecca!!!');
+ expect(sayItCalled).to.be.ok;
});
it("you should be able to return a function from a function", function() {
- expect(answers.functionFunction('Hello')('world')).to.be('Hello, world');
- expect(answers.functionFunction('Hai')('can i haz funxtion?')).to.be('Hai, can i haz funxtion?');
+ expect(answers.functionFunction('Hello')('world')).to.eql('Hello, world');
+ expect(answers.functionFunction('Hai')('can i haz funxtion?')).to.eql('Hai, can i haz funxtion?');
});
it('you should be able to use closures', function () {
@@ -52,14 +52,14 @@ define([
expect(funcs).to.have.length(arr.length);
for (var i = 0; i < arr.length; i++) {
- expect(funcs[i]()).to.be(doSomeStuff(arr[i]));
+ expect(funcs[i]()).to.eql(doSomeStuff(arr[i]));
}
});
it("you should be able to create a 'partial' function", function() {
var partial = answers.partial(sayIt, 'Hello', 'Ellie');
- expect(partial('!!!')).to.be('Hello, Ellie!!!');
- expect(sayItCalled).to.be.ok();
+ expect(partial('!!!')).to.eql('Hello, Ellie!!!');
+ expect(sayItCalled).to.be.ok;
});
it("you should be able to use arguments", function () {
@@ -68,10 +68,10 @@ define([
c = Math.random(),
d = Math.random();
- expect(answers.useArguments(a)).to.be(a);
- expect(answers.useArguments(a, b)).to.be(a + b);
- expect(answers.useArguments(a, b, c)).to.be(a + b + c);
- expect(answers.useArguments(a, b, c, d)).to.be(a + b + c + d);
+ expect(answers.useArguments(a)).to.eql(a);
+ expect(answers.useArguments(a, b)).to.eql(a + b);
+ expect(answers.useArguments(a, b, c)).to.eql(a + b + c);
+ expect(answers.useArguments(a, b, c, d)).to.eql(a + b + c + d);
});
it("you should be able to apply functions with arbitrary numbers of arguments", function () {
@@ -80,28 +80,28 @@ define([
var wasITake2ArgumentsCalled = false;
var iTake2Arguments = function (firstArgument, secondArgument) {
- expect(arguments.length).to.be(2);
- expect(firstArgument).to.be(a);
- expect(secondArgument).to.be(b);
+ expect(arguments.length).to.eql(2);
+ expect(firstArgument).to.eql(a);
+ expect(secondArgument).to.eql(b);
wasITake2ArgumentsCalled = true;
};
var wasITake3ArgumentsCalled = false;
var iTake3Arguments = function (firstArgument, secondArgument, thirdArgument) {
- expect(arguments.length).to.be(3);
- expect(firstArgument).to.be(a);
- expect(secondArgument).to.be(b);
- expect(thirdArgument).to.be(c);
+ expect(arguments.length).to.eql(3);
+ expect(firstArgument).to.eql(a);
+ expect(secondArgument).to.eql(b);
+ expect(thirdArgument).to.eql(c);
wasITake3ArgumentsCalled = true;
};
answers.callIt(iTake2Arguments, a, b);
answers.callIt(iTake3Arguments, a, b, c);
- expect(wasITake2ArgumentsCalled).to.be.ok();
- expect(wasITake3ArgumentsCalled).to.be.ok();
+ expect(wasITake2ArgumentsCalled).to.be.ok;
+ expect(wasITake3ArgumentsCalled).to.be.ok;
})();
});
@@ -111,11 +111,11 @@ define([
};
var a = Math.random(), b = Math.random(), c = Math.random();
- expect(answers.curryIt(curryMe)(a, b, c)).to.be(curryMe(a, b, c));
- expect(answers.curryIt(curryMe, a)(b, c)).to.be(curryMe(a, b, c));
- expect(answers.curryIt(curryMe, a, b)(c)).to.be(curryMe(a, b, c));
- expect(answers.curryIt(curryMe, a, b, c)()).to.be(curryMe(a, b, c));
- expect(answers.curryIt(curryMe, b, a, c)()).to.be(curryMe(b, a, c));
+ expect(answers.curryIt(curryMe)(a, b, c)).to.eql(curryMe(a, b, c));
+ expect(answers.curryIt(curryMe, a)(b, c)).to.eql(curryMe(a, b, c));
+ expect(answers.curryIt(curryMe, a, b)(c)).to.eql(curryMe(a, b, c));
+ expect(answers.curryIt(curryMe, a, b, c)()).to.eql(curryMe(a, b, c));
+ expect(answers.curryIt(curryMe, b, a, c)()).to.eql(curryMe(b, a, c));
});
});
});
@@ -3,18 +3,18 @@ if (typeof expect !== 'function') { var expect = require('expect.js'); }
define([
'app/logicalOperators'
-], function(answers) {
- describe("logical operators", function(){
+], function(answers) {
+ describe("logical operators", function(){
it("you should be able to work with logical and", function() {
- expect(answers.and(false, false)).not.to.be.ok();
- expect(answers.and(true, false)).not.to.be.ok();
- expect(answers.and(true, true)).to.be.ok();
+ expect(answers.and(false, false)).not.to.be.ok;
+ expect(answers.and(true, false)).not.to.be.ok;
+ expect(answers.and(true, true)).to.be.ok;
});
-
+
it("you should be able to work with logical or", function() {
- expect(answers.or(true, false)).to.be.ok();
- expect(answers.or(true, true)).to.be.ok();
- expect(answers.or(false, false)).not.to.be.ok();
+ expect(answers.or(true, false)).to.be.ok;
+ expect(answers.or(true, true)).to.be.ok;
+ expect(answers.or(false, false)).not.to.be.ok;
});
});
});
View
@@ -9,15 +9,15 @@ define([
var module = answers.createModule('hello', 'matt');
expect(module.sayIt).to.be.a('function');
- expect(module.name).to.be.ok('matt');
- expect(module.greeting).to.be.ok('hello');
- expect(module.sayIt()).to.be('hello, matt');
+ expect(module.name).to.eql('matt');
+ expect(module.greeting).to.eql('hello');
+ expect(module.sayIt()).to.eql('hello, matt');
module.name = 'katniss';
module.greeting = 'hi';
- expect(module.name).to.be.ok('katniss');
- expect(module.greeting).to.be.ok('hi');
- expect(module.sayIt()).to.be('hi, katniss');
+ expect(module.name).to.eql('katniss');
+ expect(module.greeting).to.eql('hi');
+ expect(module.sayIt()).to.eql('hi, katniss');
});
});
});
View
@@ -28,7 +28,7 @@ define([ 'app/objects' ], function(answers) {
it("you should be able to alter the context in which a method runs", function() {
// define a function for fn so that the following will pass
- expect(answers.alterContext(a.sayIt, b)).to.be('Yo, Rebecca!');
+ expect(answers.alterContext(a.sayIt, b)).to.eql('Yo, Rebecca!');
});
it("you should be able to alter multiple objects at once", function() {
@@ -39,9 +39,9 @@ define([ 'app/objects' ], function(answers) {
answers.alterObjects(C, greeting);
- expect(obj1.greeting).to.be(greeting);
- expect(obj2.greeting).to.be(greeting);
- expect(new C('Ellie').greeting).to.be(greeting);
+ expect(obj1.greeting).to.eql(greeting);
+ expect(obj2.greeting).to.eql(greeting);
+ expect(new C('Ellie').greeting).to.eql(greeting);
});
it("you should be able to iterate over an object's 'own' properties", function() {
Oops, something went wrong.

0 comments on commit c87e213

Please sign in to comment.