another 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ (function($) {
2
+ $.fn.fn = function() {
3
+ var self = this;
4
+ var extension = arguments[0], name = arguments[0];
5
+ if (typeof name == "string") {
6
+ return apply(self, name, $.makeArray(arguments).slice(1, arguments.length));
7
+ } else {
8
+ $.each(extension, function(key, value) {
9
+ define(self, key, value);
10
+ });
11
+ return self;
12
+ }
13
+ }
14
+ function define(self, name, fn) {
15
+ self.data(namespacedName(name), fn);
16
+ };
17
+ function apply(self, name, args) {
18
+ var result;
19
+ self.each(function(i, item) {
20
+ var fn = $(item).data(namespacedName(name));
21
+ if (fn) result = fn.apply(item, args)
22
+ else throw(name + " is not defined");
23
+ });
24
+ return result;
25
+ };
26
+ function namespacedName(name) {
27
+ return 'fn.' + name;
28
+ }
29
+ })(jQuery);
@@ -0,0 +1,109 @@
1
+ (function($) {
2
+
3
+ function print_array(obj, opts) {
4
+ var result = [];
5
+ for (var i = 0; i < Math.min(opts.max_array, obj.length); i++)
6
+ result.push($.print(obj[i], $.extend({}, opts, { max_array: 3, max_string: 40 })));
7
+
8
+ if (obj.length > opts.max_array)
9
+ result.push((obj.length - opts.max_array) + ' more...');
10
+ if (result.length == 0) return "[]"
11
+ return "[ " + result.join(", ") + " ]";
12
+ }
13
+
14
+ function print_element(obj) {
15
+ if (obj.nodeType == 1) {
16
+ var result = [];
17
+ var properties = [ 'className', 'id' ];
18
+ var extra = {
19
+ 'input': ['type', 'name', 'value'],
20
+ 'a': ['href', 'target'],
21
+ 'form': ['method', 'action'],
22
+ 'script': ['src'],
23
+ 'link': ['href'],
24
+ 'img': ['src']
25
+ };
26
+
27
+ $.each(properties.concat(extra[obj.tagName.toLowerCase()] || []), function(){
28
+ if (obj[this])
29
+ result.push(' ' + this.replace('className', 'class') + "=" + $.print(obj[this]))
30
+ });
31
+ return "<" + obj.tagName.toLowerCase()
32
+ + result.join('') + ">";
33
+ }
34
+ }
35
+
36
+ function print_object(obj, opts) {
37
+ var seen = opts.seen || [ obj ];
38
+
39
+ var result = [], key, value;
40
+ for (var k in obj) {
41
+ if (obj.hasOwnProperty(k) && $.inArray(obj[k], seen) < 0) {
42
+ seen.push(obj[k]);
43
+ value = $.print(obj[k], $.extend({}, opts, { max_array: 6, max_string: 40, seen: seen }));
44
+ } else
45
+ value = "...";
46
+ result.push(k + ": " + value);
47
+ }
48
+ if (result.length == 0) return "{}";
49
+ return "{ " + result.join(", ") + " }";
50
+ }
51
+
52
+ function print_string(value, opts) {
53
+ var character_substitutions = {
54
+ '\b': '\\b',
55
+ '\t': '\\t',
56
+ '\n': '\\n',
57
+ '\f': '\\f',
58
+ '\r': '\\r',
59
+ '"' : '\\"',
60
+ '\\': '\\\\'
61
+ };
62
+ var r = /["\\\x00-\x1f\x7f-\x9f]/g;
63
+
64
+ var str = r.test(value)
65
+ ? '"' + value.replace(r, function (a) {
66
+ var c = character_substitutions[a];
67
+ if (c) return c;
68
+ c = a.charCodeAt();
69
+ return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
70
+ }) + '"'
71
+ : '"' + value + '"';
72
+ if (str.length > opts.max_string)
73
+ return str.slice(0, opts.max_string + 1) + '..."';
74
+ else
75
+ return str;
76
+ }
77
+
78
+ $.print = function(obj, options) {
79
+ var opts = $.extend({}, { max_array: 10, max_string: 100 }, options);
80
+
81
+ if (typeof obj == 'undefined')
82
+ return "undefined";
83
+ else if (typeof obj == 'boolean')
84
+ return obj.toString();
85
+ else if (!obj && typeof obj == 'number')
86
+ return 'NaN';
87
+ else if (!obj)
88
+ return "null";
89
+ else if (typeof obj == 'string')
90
+ return print_string(obj, opts);
91
+ else if (obj instanceof RegExp)
92
+ return obj.toString();
93
+ else if (obj instanceof Array || obj.callee || obj.item)
94
+ return print_array(obj, opts);
95
+ else if (typeof obj == 'function' || obj instanceof Function)
96
+ return obj.toString().match(/^([^)]*\))/)[1];
97
+ else if (obj.nodeType)
98
+ return print_element(obj);
99
+ else if (obj instanceof jQuery)
100
+ return "$(" + $.print(obj.get()) + ")";
101
+ else if (obj instanceof Error)
102
+ return print_object(obj, $.extend({}, options, { max_string: 200 }));
103
+ else if (obj instanceof Object)
104
+ return print_object(obj, opts);
105
+ else
106
+ return obj.toString().replace(/\n\s*/g, '');
107
+ }
108
+
109
+ })(jQuery);
@@ -0,0 +1,36 @@
1
+ (function() {
2
+ Screw.Assets = {};
3
+ Screw.Assets.use_cache_buster = false; // TODO: NS/CTI - make this configurable from the UI.
4
+ var required_paths = [];
5
+ var included_stylesheets = {};
6
+ var cache_buster = parseInt(new Date().getTime()/(1*1000));
7
+
8
+ Screw.Assets.require = function(javascript_path, onload) {
9
+ if(!required_paths[javascript_path]) {
10
+ var full_path = javascript_path + ".js";
11
+ if (Screw.Assets.use_cache_buster) {
12
+ full_path += '?' + cache_buster;
13
+ }
14
+ document.write("<script src='" + full_path + "' type='text/javascript'></script>");
15
+ if(onload) {
16
+ var scripts = document.getElementsByTagName('script');
17
+ scripts[scripts.length-1].onload = onload;
18
+ }
19
+ required_paths[javascript_path] = true;
20
+ }
21
+ };
22
+
23
+ Screw.Assets.stylesheet = function(stylesheet_path) {
24
+ if(!included_stylesheets[stylesheet_path]) {
25
+ var full_path = stylesheet_path + ".css";
26
+ if(Screw.Assets.use_cache_buster) {
27
+ full_path += '?' + cache_buster;
28
+ }
29
+ document.write("<link rel='stylesheet' type='text/css' href='" + full_path + "' />");
30
+ included_stylesheets[stylesheet_path] = true;
31
+ }
32
+ };
33
+
34
+ window.require = Screw.Assets.require;
35
+ window.stylesheet = Screw.Assets.stylesheet;
36
+ })();
@@ -0,0 +1,91 @@
1
+ (function($) {
2
+ $(Screw).bind('loaded', function() {
3
+ $('.status').fn({
4
+ display: function() {
5
+ $(this).text(
6
+ $('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)'
7
+ );
8
+ }
9
+ });
10
+
11
+ $('.describe').fn({
12
+ parent: function() {
13
+ return $(this).parent('.describes').parent('.describe');
14
+ },
15
+
16
+ run_befores: function() {
17
+ $(this).fn('parent').fn('run_befores');
18
+ $(this).children('.befores').children('.before').fn('run');
19
+ },
20
+
21
+ run_afters: function() {
22
+ $(this).fn('parent').fn('run_afters');
23
+ $(this).children('.afters').children('.after').fn('run');
24
+ },
25
+
26
+ enqueue: function() {
27
+ $(this).children('.its').children('.it').fn('enqueue');
28
+ $(this).children('.describes').children('.describe').fn('enqueue');
29
+ },
30
+
31
+ selector: function() {
32
+ return $(this).fn('parent').fn('selector')
33
+ + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
34
+ }
35
+ });
36
+
37
+ $('body > .describe').fn({
38
+ selector: function() { return 'body > .describe' }
39
+ });
40
+
41
+ $('.it').fn({
42
+ parent: function() {
43
+ return $(this).parent('.its').parent('.describe');
44
+ },
45
+
46
+ run: function() {
47
+ try {
48
+ try {
49
+ $(this).fn('parent').fn('run_befores');
50
+ $(this).data('screwunit.run')();
51
+ } finally {
52
+ $(this).fn('parent').fn('run_afters');
53
+ }
54
+ $(this).trigger('passed');
55
+ } catch(e) {
56
+ $(this).trigger('failed', [e]);
57
+ }
58
+ },
59
+
60
+ enqueue: function() {
61
+ var self = $(this).trigger('enqueued');
62
+ $(Screw)
63
+ .queue(function() {
64
+ self.fn('run');
65
+ setTimeout(function() { $(Screw).dequeue() }, 0);
66
+ });
67
+ },
68
+
69
+ selector: function() {
70
+ return $(this).fn('parent').fn('selector')
71
+ + ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
72
+ }
73
+ });
74
+
75
+ $('.before').fn({
76
+ run: function() { $(this).data('screwunit.run')() }
77
+ });
78
+
79
+ $('.after').fn({
80
+ run: function() { $(this).data('screwunit.run')() }
81
+ });
82
+
83
+ $(Screw).trigger('before');
84
+ var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
85
+ $(to_run)
86
+ .focus()
87
+ .eq(0).trigger('scroll').end()
88
+ .fn('enqueue');
89
+ $(Screw).queue(function() { $(Screw).trigger('after') });
90
+ })
91
+ })(jQuery);
@@ -0,0 +1,94 @@
1
+ var Screw = (function($) {
2
+ var screw = {
3
+ Unit: function(fn) {
4
+ var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
5
+ var wrappedFn;
6
+ if(fn.length == 0) {
7
+ wrappedFn = new Function("matchers", "specifications",
8
+ "with (specifications) { with (matchers) { " + contents + " } }"
9
+ );
10
+ } else {
11
+ wrappedFn = function(matchers, specifications) {
12
+ var screwContext = {};
13
+ for(var method in matchers) {
14
+ screwContext[method] = matchers[method];
15
+ }
16
+ for(var method in specifications) {
17
+ screwContext[method] = specifications[method];
18
+ }
19
+ fn(screwContext);
20
+ }
21
+ }
22
+
23
+ $(Screw).queue(function() {
24
+ Screw.Specifications.context.push($('body > .describe'));
25
+ wrappedFn.call(this, Screw.Matchers, Screw.Specifications);
26
+ Screw.Specifications.context.pop();
27
+ $(this).dequeue();
28
+ });
29
+ },
30
+
31
+ Specifications: {
32
+ context: [],
33
+
34
+ describe: function(name, fn) {
35
+ var describe = $('<li class="describe">')
36
+ .append($('<h1>').text(name))
37
+ .append('<ol class="befores">')
38
+ .append('<ul class="its">')
39
+ .append('<ul class="describes">')
40
+ .append('<ol class="afters">');
41
+
42
+ this.context.push(describe);
43
+ fn.call();
44
+ this.context.pop();
45
+
46
+ this.context[this.context.length-1]
47
+ .children('.describes')
48
+ .append(describe);
49
+ },
50
+
51
+ it: function(name, fn) {
52
+ var it = $('<li class="it">')
53
+ .append($('<h2>').text(name))
54
+ .data('screwunit.run', fn);
55
+
56
+ this.context[this.context.length-1]
57
+ .children('.its')
58
+ .append(it);
59
+ },
60
+
61
+ before: function(fn) {
62
+ var before = $('<li class="before">')
63
+ .data('screwunit.run', fn);
64
+
65
+ this.context[this.context.length-1]
66
+ .children('.befores')
67
+ .append(before);
68
+ },
69
+
70
+ after: function(fn) {
71
+ var after = $('<li class="after">')
72
+ .data('screwunit.run', fn);
73
+
74
+ this.context[this.context.length-1]
75
+ .children('.afters')
76
+ .append(after);
77
+ }
78
+ }
79
+ };
80
+
81
+ $(screw).queue(function() { $(screw).trigger('loading') });
82
+ $(function() {
83
+ $('<div class="describe">')
84
+ .append('<h3 class="status">')
85
+ .append('<ol class="befores">')
86
+ .append('<ul class="describes">')
87
+ .append('<ol class="afters">')
88
+ .appendTo('body');
89
+
90
+ $(screw).dequeue();
91
+ $(screw).trigger('loaded');
92
+ });
93
+ return screw;
94
+ })(jQuery);
@@ -0,0 +1,90 @@
1
+ html {
2
+ padding: 0.5em;
3
+ font-family: Georgia, serif;
4
+ background: #EDEBD5;
5
+ }
6
+
7
+ li {
8
+ list-style-type: none;
9
+ }
10
+
11
+ .focused {
12
+ background-color: #F4F2E4;
13
+ }
14
+
15
+ .focused * {
16
+ opacity: 1.0;
17
+ }
18
+
19
+ h1, h2, p {
20
+ opacity: 0.4;
21
+ }
22
+
23
+ .describes {
24
+ padding-left: 0;
25
+ }
26
+
27
+ .describes h1 {
28
+ font-size: 1.1em;
29
+ color: #877C21;
30
+ line-height: 1.8em;
31
+ margin: 0pt 0pt 0.6em;
32
+ border-bottom: 1px solid transparent;
33
+ }
34
+
35
+ .describes h1:hover {
36
+ cursor: pointer;
37
+ color: #000;
38
+ background-color: #F4F2E4;
39
+ border-bottom: 1px solid #9A8E51;
40
+ }
41
+
42
+ .describes .describe {
43
+ margin-left: 0.6em;
44
+ padding-left: 0.6em;
45
+ border: 1px dashed grey;
46
+ }
47
+
48
+ .describes .describe .its {}
49
+
50
+ .describes .describe .its .it {
51
+ list-style-type: lower-roman;
52
+ list-style-position: outside;
53
+ }
54
+
55
+ .describes .describe .its .it h2 {
56
+ font-weight: normal;
57
+ font-style: italic;
58
+ padding-left: 0.5em;
59
+ font-size: 1.0em;
60
+ color: #877C21;
61
+ line-height: 1.8em;
62
+ margin: 0 0 0.5em;
63
+ border-bottom: 1px solid transparent;
64
+ }
65
+
66
+ .describes .describe .its .it.enqueued h2 {
67
+ background-color: #CC6600;
68
+ color: white !important;
69
+ }
70
+
71
+ .describes .describe .its .it.passed h2 {
72
+ background-color: #5A753D;
73
+ color: white !important;
74
+ }
75
+
76
+ .describes .describe .its .it.failed h2 {
77
+ background-color: #993300;
78
+ color: white !important;
79
+ }
80
+
81
+ .describes .describe .its .it.failed p {
82
+ margin-left: 1em;
83
+ color: #993300;
84
+ }
85
+
86
+ .describes .describe .its .it h2:hover {
87
+ cursor: pointer;
88
+ color: #000 !important;
89
+ border-bottom: 1px solid #9A8E51;
90
+ }