Permalink
Browse files

cleaning up files

  • Loading branch information...
1 parent 2c34a20 commit 163aeb2c126c6a140f292cf1a4849a168ab5ef27 Phil Hagelberg committed Feb 5, 2008
Showing with 3 additions and 173 deletions.
  1. +1 −0 core.js
  2. BIN jspec.zip
  3. +0 −63 jspec/index.html
  4. +0 −110 jspec/jspec.js
  5. +2 −0 tester2.html
View
@@ -1,3 +1,4 @@
+// specs for jquery core
module("core");
test("Basic requirements", function() {
View
BIN jspec.zip
Binary file not shown.
View
@@ -1,63 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
- "http://www.w3.org/TR/html4/strict.dtd">
-
-<html lang="en">
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>tester2</title>
- <meta name="generator" content="TextMate http://macromates.com/">
- <meta name="author" content="Yehuda Katz">
- <script src="jspec.js"></script>
- <script>
- window.onload = function() {
- jspec.describe("JSpec", function() {
- it("should support ==", function() {
- (1).should("==", 1);
- var arr = [];
- arr.should("==", arr);
- var obj = new Object;
- obj.should("==", obj);
- document.should("==", document);
- });
-
- it("should support include", function() {
- [1,2,3,4,5].should("include", 3);
- [1,2,3,4,5].should_not("include", 3);
- document.getElementsByTagName("div").should("include", document.getElementById("hello"))
- });
-
- it("should support exists", function() {
- document.should("exist");
- });
-
- jspec.matchers["have_tag_name"] = {
- describe: function(target, not) {
- return jspec.compress_lines(this) + " should " + (not ? "not " : "") + "have " + target + " as its tag name."
- },
- matches: function(target) {
- return (this.tagName && this.tagName == target) ? true : false;
- },
- failure_message: function(target, not) {
- return "Expected " + this.toString() + (not ? " not " : " ") + "to have " + target + " as its tag name," +
- " but was " + this.tagName;
- }
- };
-
- it("should support custom matchers", function() {
- document.getElementById("wrapper").should("have_tag_name", "DIV");
- document.getElementById("wrapper").should_not("have_tag_name", "SPAN");
- document.getElementById("wrapper").should("have_tag_name", "SPAN");
- });
- });
- };
- </script>
- <style type="text/css">
- div#wrapper { display: none ;}
- </style>
-</head>
-<body>
-
- <div id="wrapper"><div id="hello">Hello</div></div>
-
-</body>
-</html>
View
@@ -1,110 +0,0 @@
-jspec = {
- fn_contents: function(fn) {
- return fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
- },
- DESCRIBE: 0,
- IT_SHOULD: 1,
- FAILURE: 2,
- logger: function(state, message) {
- switch(state) {
- case jspec.DESCRIBE:
- console.log("- " + message);
- break;
- case jspec.IT_SHOULD:
- console.log(" - " + message);
- break;
- case jspec.FAILURE:
- console.log(" " + message);
- break;
- }
-
- },
- describe: function(str, desc) {
- console.log(str);
- var it = function(str, fn) {
- jspec.logger(jspec.DESCRIBE, str)
- fn.call();
- };
- Object.prototype.should = function(fn_str, to_compare, not) {
- try {
- var pass = jspec.matchers[fn_str].matches.call(this, to_compare);
- if(not) var pass = !pass;
- } catch(e) {
- var pass = null;
- }
- var should_string = (jspec.matchers[fn_str].describe &&
- jspec.matchers[fn_str].describe.call(this, to_compare, not)) ||
- this.toString() + " should " + (not ? "not " : "") + fn_str + " " + to_compare;
- if(pass) {
- jspec.logger(jspec.IT_SHOULD, should_string + " (PASS)");
- } else {
- jspec.logger(jspec.IT_SHOULD, should_string + (pass == false ? " (FAIL)" : " (ERROR)"));
- jspec.logger(jspec.FAILURE, jspec.matchers[fn_str].failure_message.call(this, to_compare, not))
- }
- };
- Object.prototype.should_not = function(fn_str, to_compare) {
- this.should(fn_str, to_compare, true);
- };
- x = desc.toString()
- var fn_body = this.fn_contents(desc);
- var fn = new Function("it", fn_body);
- fn.call(this, it);
- delete Object.prototype.should
- delete Object.prototype.should_not
- }
-}
-
-jspec.compress_lines = function(obj) {
- if(obj instanceof Function) {
- console.log(obj)
- return obj.toString().match(/^([^\{]*) {/)[1];
- } else if(obj instanceof Array) {
- return "[" + obj.toString() + "]";
- } else {
- return obj.toString().replace(/\n\s*/g, "");
- }
-}
-
-jspec.matchers = {};
-
-jspec.matchers["=="] = {
- describe: function(target, not) {
- return jspec.compress_lines(this) + " should " + (not ? "not " : "") + "equal " + jspec.compress_lines(target)
- },
- matches: function(target) {
- return this == target;
- },
- failure_message: function(target, not) {
- if (not)
- return "Expected " + jspec.compress_lines(this) + " not to equal " + jspec.compress_lines(target);
- else
- return "Expected " + jspec.compress_lines(this) + ". Got " + jspec.compress_lines(target);
- }
-}
-
-jspec.matchers["include"] = {
- matches: function(target) {
- if(Array.prototype.indexOf) return Array.prototype.indexOf.call(this, target) != -1;
- else {
- for(i=0,j=this.length;i<j;i++) {
- if(target == this[i]) return true;
- }
- return false;
- }
- },
- failure_message: function(target, not) {
- return "Expected [" + jspec.compress_lines(this) + "] " + (not ? "not " : "") + "to include " + target;
- }
-}
-
-jspec.matchers["exist"] = {
- describe: function(target, not) {
- return jspec.compress_lines(this) + " should " + (not ? "not " : "") + "exist."
- },
- matches: function(target) {
- return !!this;
- },
- failure_message: function(target, not) {
- return "Expected " + (not ? "not " : "") + "to exist, but was " + jspec.compress_lines(this);
- }
-}
View
@@ -29,6 +29,8 @@
it("should support exists", function() {
expect(document).to("exist");
});
+
+ it("should support pending specs");
jspec.matchers["have_tag_name"] = {
describe: function(self, target, not) {

0 comments on commit 163aeb2

Please sign in to comment.