Skip to content

Commit

Permalink
+ js specs
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Jan 8, 2012
1 parent 63414c7 commit e174332
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/javascripts/source/picky.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ Array.prototype.include = function(val) {
Array.prototype.remove = function(index) {
this.splice(index, 1);
return this;
};

Array.prototype.compare = function(other) {
return this.join('') == other.join('');
};
16 changes: 16 additions & 0 deletions client/javascripts/spec/picky.allocation_renderer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var renderer;
describe(
"AllocationRenderer",
function() {
renderer = new AllocationRenderer(function() {
//
}, {});
},
function() {
describe("makeUpMissingFormat", function() {
it("should be tasty", function() {
expect(renderer.makeUpMissingFormat('someKey')).toMatch('');
});
});
}
);
23 changes: 23 additions & 0 deletions client/javascripts/spec/picky.data.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var data;
describe(
"Non-Empty Data",
function() {
data = new PickyData({
total: 123,
duration: 0.000123,
offset: 12,
allocations: ['test', 3.14, 123, [['attr1', 'Original1', 'parsed1'], ['attr2', 'Original2', 'parsed2']]]
});
},
function() {
describe(
"isEmpty",
null,
function() {
it("is correct", function() {
return !data.isEmpty();
});
}
);
}
);
57 changes: 57 additions & 0 deletions client/javascripts/spec/picky.extensions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var array;
describe(
"Array",
function() {
array = [1,2,3,4,5];
},
function() {
describe(
"index",
null,
function() {
it("indexes correctly", function() {
return array.index(0) == null;
});
it("indexes correctly", function() {
return array.index(3) == 2;
});
}
);
describe(
"include",
null,
function() {
it("is correct", function() {
return !array.include(0);
});
it("is correct", function() {
return array.include(3);
});
}
);
describe(
"compare",
null,
function() {
it("is correct", function() {
return [].compare([]);
});
it("is correct", function() {
return [1,2,3].compare([1,2,3]);
});
}
);
describe(
"include",
null,
function() {
it("is correct", function() {
return array.remove(0).compare([2,3,4,5]);
});
it("is correct", function() {
return array.remove(3).compare([2,3,4]);
});
}
);
}
);
38 changes: 38 additions & 0 deletions client/javascripts/spec_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file defines global helper functions for specs
//
// js specs are intended to be run with the mozilla js standalone lib:
// http://www.ossp.org/pkg/lib/js/
//
// Output is intended to be used in a html wrapper, as in TextMate.

// The tester function.
//
it = function(should, callback) {
var result = callback();
if (result) {
print('.');
} else {
print('F');
};
};

// For defining a context.
//
context = function(description, setup, specs, breakdown) {
var old_description = this.context_description;
var pre_description = old_description ? old_description + ' ' : '';

// framework setup
this.context_description = pre_description + description; // sets the description on the global object

if (setup) { setup(); };
specs();
if (breakdown) { breakdown(); };

// framework breakdown
this.context_description = old_description;
};

// Alias describe to context.
//
describe = context;
12 changes: 12 additions & 0 deletions client/javascripts/specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# js -f spec_helper.js \
# -f source/picky.translations.js \
# -f source/picky.allocation_renderer.js \
# spec/picky.allocation_renderer.spec.js

js -f spec_helper.js \
-f source/picky.extensions.js \
spec/picky.extensions.spec.js

js -f spec_helper.js \
-f source/picky.data.js \
spec/picky.data.spec.js

0 comments on commit e174332

Please sign in to comment.