screw_server 0.1.4
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.
- data/Gemfile.run +3 -0
- data/Gemfile.run.lock +41 -0
- data/assets/screw-jslint.js +69 -0
- data/assets/screw-server.js +120 -0
- data/assets/screw.css +70 -0
- data/assets/vendor/fulljslint.js +5699 -0
- data/assets/vendor/screw-unit/CHANGES +7 -0
- data/assets/vendor/screw-unit/EXAMPLE.html +68 -0
- data/assets/vendor/screw-unit/LICENSE +22 -0
- data/assets/vendor/screw-unit/README.markdown +307 -0
- data/assets/vendor/screw-unit/example/models/cat.js +5 -0
- data/assets/vendor/screw-unit/example/models/man.js +17 -0
- data/assets/vendor/screw-unit/example/spec/matchers/have.js +8 -0
- data/assets/vendor/screw-unit/example/spec/models/cat_spec.js +31 -0
- data/assets/vendor/screw-unit/example/spec/models/man_spec.js +34 -0
- data/assets/vendor/screw-unit/example/spec/spec_helper.js +5 -0
- data/assets/vendor/screw-unit/example/spec/suite.html +25 -0
- data/assets/vendor/screw-unit/lib/jquery-1.2.6.js +3549 -0
- data/assets/vendor/screw-unit/lib/jquery.fn.js +29 -0
- data/assets/vendor/screw-unit/lib/jquery.print.js +109 -0
- data/assets/vendor/screw-unit/lib/screw.behaviors.js +101 -0
- data/assets/vendor/screw-unit/lib/screw.builder.js +90 -0
- data/assets/vendor/screw-unit/lib/screw.css +90 -0
- data/assets/vendor/screw-unit/lib/screw.events.js +45 -0
- data/assets/vendor/screw-unit/lib/screw.matchers.js +203 -0
- data/assets/vendor/screw-unit/spec/behaviors_spec.js +188 -0
- data/assets/vendor/screw-unit/spec/matchers_spec.js +391 -0
- data/assets/vendor/screw-unit/spec/print_spec.js +158 -0
- data/assets/vendor/screw-unit/spec/spec_helper.js +0 -0
- data/assets/vendor/screw-unit/spec/suite.html +18 -0
- data/assets/vendor/smoke/LICENSE +22 -0
- data/assets/vendor/smoke/README.markdown +68 -0
- data/assets/vendor/smoke/lib/smoke.core.js +49 -0
- data/assets/vendor/smoke/lib/smoke.mock.js +219 -0
- data/assets/vendor/smoke/lib/smoke.stub.js +29 -0
- data/assets/vendor/smoke/plugins/screw.mocking.js +26 -0
- data/assets/vendor/smoke/spec/core_spec.js +115 -0
- data/assets/vendor/smoke/spec/mock_spec.js +431 -0
- data/assets/vendor/smoke/spec/screw_integration_spec.js +17 -0
- data/assets/vendor/smoke/spec/spec_helper.js +0 -0
- data/assets/vendor/smoke/spec/stub_spec.js +17 -0
- data/assets/vendor/smoke/spec/su/jquery-1.2.3.js +3408 -0
- data/assets/vendor/smoke/spec/su/jquery.fn.js +29 -0
- data/assets/vendor/smoke/spec/su/jquery.print.js +108 -0
- data/assets/vendor/smoke/spec/su/screw.behaviors.js +91 -0
- data/assets/vendor/smoke/spec/su/screw.builder.js +80 -0
- data/assets/vendor/smoke/spec/su/screw.css +74 -0
- data/assets/vendor/smoke/spec/su/screw.events.js +38 -0
- data/assets/vendor/smoke/spec/su/screw.matchers.js +65 -0
- data/assets/vendor/smoke/spec/suite.html +29 -0
- data/bin/screw_server +43 -0
- data/lib/screw_server/app.rb +197 -0
- data/lib/screw_server/base.rb +21 -0
- data/lib/screw_server/fixture_file.rb +17 -0
- data/lib/screw_server/jslint_suite.rb +51 -0
- data/lib/screw_server/spec_file.rb +76 -0
- data/lib/screw_server.rb +2 -0
- data/screw_server.gemspec +28 -0
- data/views/index.haml +13 -0
- data/views/missing_spec_helper.haml +12 -0
- data/views/no_specs.haml +11 -0
- data/views/run_spec.haml +30 -0
- data/views/sample_spec.js +7 -0
- data/views/sample_spec_helper.js +2 -0
- metadata +257 -0
@@ -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 (typeof obj == 'number')
|
86
|
+
return obj.toString();
|
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,101 @@
|
|
1
|
+
(function($) {
|
2
|
+
$(Screw).bind('loaded', function() {
|
3
|
+
$('.status').fn({
|
4
|
+
display: function() {
|
5
|
+
$(this).html(
|
6
|
+
$('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)<br />' +
|
7
|
+
((new Date() - Screw.suite_start_time)/1000.0).toString() + " seconds elapsed"
|
8
|
+
);
|
9
|
+
}
|
10
|
+
});
|
11
|
+
|
12
|
+
$('.describe').fn({
|
13
|
+
parent: function() {
|
14
|
+
return $(this).parent('.describes').parent('.describe');
|
15
|
+
},
|
16
|
+
|
17
|
+
run_befores: function() {
|
18
|
+
$(this).fn('parent').fn('run_befores');
|
19
|
+
$(this).children('.befores').children('.before').fn('run');
|
20
|
+
},
|
21
|
+
|
22
|
+
run_afters: function() {
|
23
|
+
$(this).fn('parent').fn('run_afters');
|
24
|
+
$(this).children('.afters').children('.after').fn('run');
|
25
|
+
},
|
26
|
+
|
27
|
+
enqueue: function() {
|
28
|
+
$(this).children('.its').children('.it').fn('enqueue');
|
29
|
+
$(this).children('.describes').children('.describe').fn('enqueue');
|
30
|
+
},
|
31
|
+
|
32
|
+
selector: function() {
|
33
|
+
return $(this).fn('parent').fn('selector')
|
34
|
+
+ ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
$('body > .describe').fn({
|
39
|
+
selector: function() { return 'body > .describe' }
|
40
|
+
});
|
41
|
+
|
42
|
+
$('.it').fn({
|
43
|
+
parent: function() {
|
44
|
+
return $(this).parent('.its').parent('.describe');
|
45
|
+
},
|
46
|
+
|
47
|
+
run: function() {
|
48
|
+
var exception_during_spec;
|
49
|
+
try {
|
50
|
+
try {
|
51
|
+
$(this).fn('parent').fn('run_befores');
|
52
|
+
$(this).data('screwunit.run')();
|
53
|
+
} catch(e) {
|
54
|
+
exception_during_spec = e;
|
55
|
+
throw e;
|
56
|
+
}
|
57
|
+
finally {
|
58
|
+
$(this).fn('parent').fn('run_afters');
|
59
|
+
}
|
60
|
+
$(this).trigger('passed');
|
61
|
+
} catch(any_exception) {
|
62
|
+
// If exceptions are thrown both during and after the spec,
|
63
|
+
// report the one thrown first
|
64
|
+
// (because the one thrown afterwards is likely to be a subsequent error)
|
65
|
+
var exception_to_report = exception_during_spec || any_exception;
|
66
|
+
$(this).trigger('failed', [exception_to_report]);
|
67
|
+
}
|
68
|
+
},
|
69
|
+
|
70
|
+
enqueue: function() {
|
71
|
+
var self = $(this).trigger('enqueued');
|
72
|
+
$(Screw)
|
73
|
+
.queue(function() {
|
74
|
+
self.fn('run');
|
75
|
+
setTimeout(function() { $(Screw).dequeue() }, 0);
|
76
|
+
});
|
77
|
+
},
|
78
|
+
|
79
|
+
selector: function() {
|
80
|
+
return $(this).fn('parent').fn('selector')
|
81
|
+
+ ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
|
82
|
+
}
|
83
|
+
});
|
84
|
+
|
85
|
+
$('.before').fn({
|
86
|
+
run: function() { $(this).data('screwunit.run')() }
|
87
|
+
});
|
88
|
+
|
89
|
+
$('.after').fn({
|
90
|
+
run: function() { $(this).data('screwunit.run')() }
|
91
|
+
});
|
92
|
+
|
93
|
+
$(Screw).trigger('before');
|
94
|
+
var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
|
95
|
+
$(to_run)
|
96
|
+
.focus()
|
97
|
+
.eq(0).trigger('scroll').end()
|
98
|
+
.fn('enqueue');
|
99
|
+
$(Screw).queue(function() { $(Screw).trigger('after') });
|
100
|
+
})
|
101
|
+
})(jQuery);
|
@@ -0,0 +1,90 @@
|
|
1
|
+
var Screw = (function($) {
|
2
|
+
var screw = {
|
3
|
+
Unit: function(fn) {
|
4
|
+
var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
|
5
|
+
var fn = new Function("matchers", "specifications",
|
6
|
+
"with (specifications) { with (matchers) { " + contents + " } }"
|
7
|
+
);
|
8
|
+
|
9
|
+
$(Screw).queue(function() {
|
10
|
+
var this_element = this;
|
11
|
+
setTimeout(function() {
|
12
|
+
Screw.Specifications.context.push($('body > .describe'));
|
13
|
+
fn.call(this_element, Screw.Matchers, Screw.Specifications);
|
14
|
+
Screw.Specifications.context.pop();
|
15
|
+
$(this_element).dequeue();
|
16
|
+
}, 0);
|
17
|
+
});
|
18
|
+
},
|
19
|
+
|
20
|
+
Specifications: {
|
21
|
+
context: [],
|
22
|
+
|
23
|
+
describe: function(name, fn) {
|
24
|
+
var describe = $('<li class="describe"></li>')
|
25
|
+
.append($('<h1></h1>').text(name))
|
26
|
+
.append('<ol class="befores"></ol>')
|
27
|
+
.append('<ul class="its"></ul>')
|
28
|
+
.append('<ul class="describes"></ul>')
|
29
|
+
.append('<ol class="afters"></ol>');
|
30
|
+
|
31
|
+
this.context.push(describe);
|
32
|
+
fn.call();
|
33
|
+
this.context.pop();
|
34
|
+
|
35
|
+
this.context[this.context.length-1]
|
36
|
+
.children('.describes')
|
37
|
+
.append(describe);
|
38
|
+
},
|
39
|
+
|
40
|
+
it: function(name, fn) {
|
41
|
+
var it = $('<li class="it"></li>')
|
42
|
+
.append($('<h2></h2>').text(name))
|
43
|
+
.data('screwunit.run', fn);
|
44
|
+
|
45
|
+
this.context[this.context.length-1]
|
46
|
+
.children('.its')
|
47
|
+
.append(it);
|
48
|
+
},
|
49
|
+
|
50
|
+
before: function(fn) {
|
51
|
+
var before = $('<li class="before"></li>')
|
52
|
+
.data('screwunit.run', fn);
|
53
|
+
|
54
|
+
this.context[this.context.length-1]
|
55
|
+
.children('.befores')
|
56
|
+
.append(before);
|
57
|
+
},
|
58
|
+
|
59
|
+
after: function(fn) {
|
60
|
+
var after = $('<li class="after"></li>')
|
61
|
+
.data('screwunit.run', fn);
|
62
|
+
|
63
|
+
this.context[this.context.length-1]
|
64
|
+
.children('.afters')
|
65
|
+
.append(after);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
$(screw).queue(function() { $(screw).trigger('loading') });
|
71
|
+
|
72
|
+
$(window).load(function(){
|
73
|
+
$('<div class="describe"></div>')
|
74
|
+
.append('<h3 class="status"></h3>')
|
75
|
+
.append('<ol class="befores"></ol>')
|
76
|
+
.append('<ul class="describes"></ul>')
|
77
|
+
.append('<ol class="afters"></ol>')
|
78
|
+
.appendTo('body');
|
79
|
+
|
80
|
+
$('.status').text('Scanning for specs...');
|
81
|
+
|
82
|
+
$(Screw).queue(function() {
|
83
|
+
$(screw).trigger('loaded');
|
84
|
+
$(screw).dequeue();
|
85
|
+
});
|
86
|
+
$(screw).dequeue();
|
87
|
+
});
|
88
|
+
|
89
|
+
return screw;
|
90
|
+
})(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 #999;
|
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
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
(function($) {
|
2
|
+
$(Screw)
|
3
|
+
.bind('loaded', function() {
|
4
|
+
$('.describe, .it')
|
5
|
+
.click(function() {
|
6
|
+
document.location = location.href.split('?')[0] + '?' + $(this).fn('selector');
|
7
|
+
return false;
|
8
|
+
})
|
9
|
+
.focus(function() {
|
10
|
+
return $(this).addClass('focused');
|
11
|
+
})
|
12
|
+
.bind('scroll', function() {
|
13
|
+
document.body.scrollTop = $(this).offset().top;
|
14
|
+
});
|
15
|
+
|
16
|
+
$('.it')
|
17
|
+
.bind('enqueued', function() {
|
18
|
+
$(this).addClass('enqueued');
|
19
|
+
})
|
20
|
+
.bind('running', function() {
|
21
|
+
$(this).addClass('running');
|
22
|
+
})
|
23
|
+
.bind('passed', function() {
|
24
|
+
$(this).addClass('passed');
|
25
|
+
})
|
26
|
+
.bind('failed', function(e, reason) {
|
27
|
+
$(this)
|
28
|
+
.addClass('failed')
|
29
|
+
.append($('<p class="error"></p>').text(reason.toString()));
|
30
|
+
|
31
|
+
var file = reason.fileName || reason.sourceURL;
|
32
|
+
var line = reason.lineNumber || reason.line;
|
33
|
+
if (file || line) {
|
34
|
+
$(this).append($('<p class="error"></p>').text('line ' + line + ', ' + file));
|
35
|
+
}
|
36
|
+
})
|
37
|
+
})
|
38
|
+
.bind('before', function() {
|
39
|
+
Screw.suite_start_time = new Date();
|
40
|
+
$('.status').text('Running...');
|
41
|
+
})
|
42
|
+
.bind('after', function() {
|
43
|
+
$('.status').fn('display')
|
44
|
+
})
|
45
|
+
})(jQuery);
|
@@ -0,0 +1,203 @@
|
|
1
|
+
Screw.Matchers = (function($) {
|
2
|
+
return matchers = {
|
3
|
+
expect: function(actual) {
|
4
|
+
return {
|
5
|
+
to: function(matcher, expected, not) {
|
6
|
+
var matched = matcher.match(expected, actual);
|
7
|
+
if (not ? matched : !matched) {
|
8
|
+
throw(matcher.failure_message(expected, actual, not));
|
9
|
+
}
|
10
|
+
},
|
11
|
+
|
12
|
+
to_not: function(matcher, expected) {
|
13
|
+
this.to(matcher, expected, true);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
},
|
17
|
+
|
18
|
+
equal: {
|
19
|
+
match: function(expected, actual) {
|
20
|
+
if(expected == actual) return true;
|
21
|
+
if(actual == undefined) return false;
|
22
|
+
|
23
|
+
if (expected instanceof Array) {
|
24
|
+
for (var i = 0; i < actual.length; i++)
|
25
|
+
if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
|
26
|
+
return actual.length == expected.length;
|
27
|
+
} else if (expected instanceof Object) {
|
28
|
+
for (var key in expected)
|
29
|
+
if (!this.match(expected[key], actual[key])) return false;
|
30
|
+
for (var key in actual)
|
31
|
+
if (!this.match(actual[key], expected[key])) return false;
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
return false;
|
35
|
+
},
|
36
|
+
|
37
|
+
failure_message: function(expected, actual, not) {
|
38
|
+
return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
|
39
|
+
}
|
40
|
+
},
|
41
|
+
|
42
|
+
be_gt: {
|
43
|
+
match: function(expected, actual) {
|
44
|
+
return actual > expected;
|
45
|
+
},
|
46
|
+
|
47
|
+
failure_message: function(expected, actual, not) {
|
48
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than ' + $.print(expected);
|
49
|
+
}
|
50
|
+
},
|
51
|
+
|
52
|
+
be_gte: {
|
53
|
+
match: function(expected, actual) {
|
54
|
+
return actual >= expected;
|
55
|
+
},
|
56
|
+
|
57
|
+
failure_message: function(expected, actual, not) {
|
58
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than or equal to ' + $.print(expected);
|
59
|
+
}
|
60
|
+
},
|
61
|
+
|
62
|
+
be_lt: {
|
63
|
+
match: function(expected, actual) {
|
64
|
+
return actual < expected;
|
65
|
+
},
|
66
|
+
|
67
|
+
failure_message: function(expected, actual, not) {
|
68
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than ' + $.print(expected);
|
69
|
+
}
|
70
|
+
},
|
71
|
+
|
72
|
+
be_lte: {
|
73
|
+
match: function(expected, actual) {
|
74
|
+
return actual <= expected;
|
75
|
+
},
|
76
|
+
|
77
|
+
failure_message: function(expected, actual, not) {
|
78
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than or equal to ' + $.print(expected);
|
79
|
+
}
|
80
|
+
},
|
81
|
+
|
82
|
+
match: {
|
83
|
+
match: function(expected, actual) {
|
84
|
+
if (expected.constructor == RegExp)
|
85
|
+
return expected.exec(actual.toString());
|
86
|
+
else
|
87
|
+
return actual.indexOf(expected) > -1;
|
88
|
+
},
|
89
|
+
|
90
|
+
failure_message: function(expected, actual, not) {
|
91
|
+
return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
|
92
|
+
}
|
93
|
+
},
|
94
|
+
|
95
|
+
be_empty: {
|
96
|
+
match: function(expected, actual) {
|
97
|
+
if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
|
98
|
+
|
99
|
+
return actual.length == 0;
|
100
|
+
},
|
101
|
+
|
102
|
+
failure_message: function(expected, actual, not) {
|
103
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
|
104
|
+
}
|
105
|
+
},
|
106
|
+
|
107
|
+
have_length: {
|
108
|
+
match: function(expected, actual) {
|
109
|
+
if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
|
110
|
+
|
111
|
+
return actual.length == expected;
|
112
|
+
},
|
113
|
+
|
114
|
+
failure_message: function(expected, actual, not) {
|
115
|
+
return 'expected ' + $.print(actual) + (not ? ' to not' : ' to') + ' have length ' + expected;
|
116
|
+
}
|
117
|
+
},
|
118
|
+
|
119
|
+
be_null: {
|
120
|
+
match: function(expected, actual) {
|
121
|
+
return actual == null;
|
122
|
+
},
|
123
|
+
|
124
|
+
failure_message: function(expected, actual, not) {
|
125
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
|
126
|
+
}
|
127
|
+
},
|
128
|
+
|
129
|
+
be_undefined: {
|
130
|
+
match: function(expected, actual) {
|
131
|
+
return actual == undefined;
|
132
|
+
},
|
133
|
+
|
134
|
+
failure_message: function(expected, actual, not) {
|
135
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
|
136
|
+
}
|
137
|
+
},
|
138
|
+
|
139
|
+
be_true: {
|
140
|
+
match: function(expected, actual) {
|
141
|
+
return actual;
|
142
|
+
},
|
143
|
+
|
144
|
+
failure_message: function(expected, actual, not) {
|
145
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
|
146
|
+
}
|
147
|
+
},
|
148
|
+
|
149
|
+
be_false: {
|
150
|
+
match: function(expected, actual) {
|
151
|
+
return !actual;
|
152
|
+
},
|
153
|
+
|
154
|
+
failure_message: function(expected, actual, not) {
|
155
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
|
156
|
+
}
|
157
|
+
},
|
158
|
+
|
159
|
+
match_selector: {
|
160
|
+
match: function(expected, actual) {
|
161
|
+
if (!(actual instanceof jQuery)) {
|
162
|
+
throw expected.toString() + " must be an instance of jQuery to match against a selector"
|
163
|
+
}
|
164
|
+
|
165
|
+
return actual.is(expected);
|
166
|
+
},
|
167
|
+
|
168
|
+
failure_message: function(expected, actual, not) {
|
169
|
+
return 'expected ' + $.print(actual) + (not ? ' to not match selector ' : ' to match selector ') + expected;
|
170
|
+
}
|
171
|
+
},
|
172
|
+
|
173
|
+
contain_selector: {
|
174
|
+
match: function(expected, actual) {
|
175
|
+
if (!(actual instanceof jQuery)) {
|
176
|
+
throw expected.toString() + " must be an instance of jQuery to match against a selector"
|
177
|
+
}
|
178
|
+
|
179
|
+
return actual.find(expected).length > 0;
|
180
|
+
},
|
181
|
+
|
182
|
+
failure_message: function(expected, actual, not) {
|
183
|
+
return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
|
184
|
+
}
|
185
|
+
},
|
186
|
+
|
187
|
+
throw_exception: {
|
188
|
+
match: function(expected, actual) {
|
189
|
+
try {
|
190
|
+
actual();
|
191
|
+
}
|
192
|
+
catch(e) {
|
193
|
+
return true;
|
194
|
+
}
|
195
|
+
return false;
|
196
|
+
},
|
197
|
+
failure_message: function(expected, actual, not) {
|
198
|
+
var content = actual.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
|
199
|
+
return 'expected ' + content + (not ? ' not' : '') + ' to throw an exception';
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
})(jQuery);
|