0
@@ -27,34 +27,32 @@ jspec = {
0
jspec.logger(jspec.TOP_LEVEL, str);
0
var it = function(str, fn) {
0
jspec.logger(jspec.DESCRIBE, str);
0
- Object.prototype.should = function(fn_str, to_compare, not) {
0
+ var Expectation = function(p) { this.expectation = p; };
0
+ Expectation.prototype.to = function(fn_str, to_compare, not) {
0
- var pass = jspec.matchers[fn_str].matches
.call(this, to_compare);
0
+ var pass = jspec.matchers[fn_str].matches
(this.expectation, to_compare);
0
if(not) var pass = !pass;
0
var should_string = (jspec.matchers[fn_str].describe &&
0
- jspec.matchers[fn_str].describe
.call(this, to_compare, not)) ||
0
+ jspec.matchers[fn_str].describe
(this.expectation, to_compare, not)) ||
0
this.toString() + " should " + (not ? "not " : "") + fn_str + " " + to_compare;
0
jspec.logger(jspec.IT_SHOULD, should_string + " (PASS)");
0
jspec.logger(jspec.IT_SHOULD, should_string + (pass == false ? " (FAIL)" : " (ERROR)"));
0
- jspec.logger(jspec.FAILURE, jspec.matchers[fn_str].failure_message
.call(this, to_compare, not))
0
+ jspec.logger(jspec.FAILURE, jspec.matchers[fn_str].failure_message
(this.expectation, to_compare, not))
0
- Object.prototype.should_not = function(fn_str, to_compare) {
0
- this.should(fn_str, to_compare, true);
0
+ Expectation.prototype.not_to = function(fn_str, to_compare) { this.to(fn_str, to_compare, true) }
0
+ var expect = function(p) { return new Expectation(p) };
0
var fn_body = this.fn_contents(desc);
0
- var fn = new Function("it", fn_body);
0
- delete Object.prototype.should
0
- delete Object.prototype.should_not
0
+ var fn = new Function("it", "expect", fn_body);
0
+ fn.call(this, it, expect);
0
@@ -65,6 +63,9 @@ jspec.print_object = function(obj) {
0
return obj.toString().match(/^([^\{]*) {/)[1];
0
} else if(obj instanceof Array) {
0
return "[" + obj.toString() + "]";
0
+ } else if(obj instanceof HTMLElement) {
0
+ return "<" + obj.tagName + " " + (obj.className != "" ? "class='" + obj.className + "'" : "") +
0
+ (obj.id != "" ? "id='" + obj.id + "'" : "") + ">";
0
return obj.toString().replace(/\n\s*/g, "");
0
@@ -75,43 +76,43 @@ jspec.print_object = function(obj) {
0
jspec.matchers["=="] = {
0
- describe: function(target, not) {
0
- return jspec.print_object(this) + " should " + (not ? "not " : "") + "equal " + jspec.print_object(target)
0
+ describe: function(self, target, not) {
0
+ return jspec.print_object(self) + " should " + (not ? "not " : "") + "equal " + jspec.print_object(target)
0
- matches: function(target) {
0
- return this == target;
0
+ matches: function(self, target) {
0
+ return self == target;
0
- failure_message: function(
target, not) {
0
+ failure_message: function(
self, target, not) {
0
- return "Expected " + jspec.print_object(
this) + " not to equal " + jspec.print_object(target);
0
+ return "Expected " + jspec.print_object(
self) + " not to equal " + jspec.print_object(target);
0
- return "Expected " + jspec.print_object(
this) + ". Got " + jspec.print_object(target);
0
+ return "Expected " + jspec.print_object(
self) + ". Got " + jspec.print_object(target);
0
jspec.matchers["include"] = {
0
- matches: function(target) {
0
- if(Array.prototype.indexOf) return Array.prototype.indexOf.call(this, target) != -1;
0
+ matches: function(self, target) {
0
+ if(Array.prototype.indexOf) return Array.prototype.indexOf.call(self, target) != -1;
0
- for(i=0,j=this.length;i<j;i++) {
0
- if(target == this[i]) return true;
0
+ for(i=0,j=self.length;i<j;i++) {
0
+ if(target == self[i]) return true;
0
- failure_message: function(target, not) {
0
- return "Expected [" + jspec.print_object(this) + "] " + (not ? "not " : "") + "to include " + target;
0
+ failure_message: function(self, target, not) {
0
+ return "Expected [" + jspec.print_object(self) + "] " + (not ? "not " : "") + "to include " + target;
0
jspec.matchers["exist"] = {
0
- describe: function(target, not) {
0
- return jspec.print_object(this) + " should " + (not ? "not " : "") + "exist."
0
+ describe: function(self, target, not) {
0
+ return jspec.print_object(self) + " should " + (not ? "not " : "") + "exist."
0
- matches: function(
target) {
0
+ matches: function(
self, target) {
0
- failure_message: function(target, not) {
0
- return "Expected " + (not ? "not " : "") + "to exist, but was " + jspec.print_object(this);
0
+ failure_message: function(self, target, not) {
0
+ return "Expected " + (not ? "not " : "") + "to exist, but was " + jspec.print_object(self);
0
\ No newline at end of file
Comments
No one has commented yet.