screw-unit-server 0.3.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +23 -1
- data/README.markdown +10 -3
- data/Rakefile +27 -55
- data/VERSION.yml +4 -0
- data/bin/screw_unit_server +14 -4
- data/core/CHANGES +10 -0
- data/core/EXAMPLE.html +4 -4
- data/core/README.markdown +7 -7
- data/core/example/models/man.js +2 -2
- data/core/example/spec/suite.html +1 -1
- data/core/lib/jquery-1.3.2.js +4376 -0
- data/core/lib/jquery.fn.js +2 -1
- data/core/lib/jquery.print.js +13 -12
- data/core/lib/screw.behaviors.js +11 -9
- data/core/lib/screw.builder.js +26 -11
- data/core/lib/screw.css +2 -2
- data/core/lib/screw.events.js +11 -4
- data/core/lib/screw.matchers.js +192 -13
- data/core/spec/behaviors_spec.js +11 -1
- data/core/spec/matchers_spec.js +288 -9
- data/core/spec/print_spec.js +47 -8
- data/core/spec/suite.html +2 -1
- data/core/spec/with_screw_context_spec.js +9 -0
- data/lib/screw_unit.rb +13 -16
- data/lib/screw_unit/representations.rb +2 -0
- data/lib/screw_unit/representations/spec.html.rb +117 -0
- data/spec/functional/functional_spec.rb +14 -3
- data/spec/functional/functional_spec_helper.rb +22 -34
- data/spec/functional/functional_spec_server_starter.rb +68 -0
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +45 -20
- data/spec/unit/unit_spec_helper.rb +24 -93
- data/vendor/js-test-core/CHANGES +19 -0
- data/vendor/js-test-core/Rakefile +2 -1
- data/vendor/js-test-core/lib/js_test_core.rb +26 -10
- data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +97 -18
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
- data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
- data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
- data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
- data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
- data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +13 -8
- data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +44 -14
- data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
- data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +5 -56
- data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
- data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
- data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +1 -1
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +1 -1
- data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
- data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
- data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
- data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +140 -85
- data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
- data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
- data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
- data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +16 -113
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- metadata +143 -129
- data/core/TODO +0 -2
- data/core/lib/jquery-1.2.3.js +0 -3408
- data/core/lib/screw.assets.js +0 -36
- data/core/lib/screw.server.js +0 -21
- data/lib/screw_unit/resources.rb +0 -2
- data/lib/screw_unit/resources/spec.rb +0 -37
- data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
- data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
- data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
- data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
- data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
- data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
- data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/server.rb +0 -111
- data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
- data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
- data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
- data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
- data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +0 -131
- data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
data/core/lib/jquery.fn.js
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
});
|
11
11
|
return self;
|
12
12
|
}
|
13
|
-
}
|
13
|
+
};
|
14
14
|
function define(self, name, fn) {
|
15
15
|
self.data(namespacedName(name), fn);
|
16
16
|
};
|
@@ -21,6 +21,7 @@
|
|
21
21
|
if (fn) result = fn.apply(item, args)
|
22
22
|
else throw(name + " is not defined");
|
23
23
|
});
|
24
|
+
|
24
25
|
return result;
|
25
26
|
};
|
26
27
|
function namespacedName(name) {
|
data/core/lib/jquery.print.js
CHANGED
@@ -18,10 +18,14 @@
|
|
18
18
|
var extra = {
|
19
19
|
'input': ['type', 'name', 'value'],
|
20
20
|
'a': ['href', 'target'],
|
21
|
-
'form': ['method', 'action']
|
21
|
+
'form': ['method', 'action'],
|
22
|
+
'script': ['src'],
|
23
|
+
'link': ['href'],
|
24
|
+
'img': ['src']
|
22
25
|
};
|
23
|
-
|
24
|
-
|
26
|
+
|
27
|
+
$.each(properties.concat(extra[obj.tagName.toLowerCase()] || []), function(){
|
28
|
+
if (obj[this])
|
25
29
|
result.push(' ' + this.replace('className', 'class') + "=" + $.print(obj[this]))
|
26
30
|
});
|
27
31
|
return "<" + obj.tagName.toLowerCase()
|
@@ -30,7 +34,7 @@
|
|
30
34
|
}
|
31
35
|
|
32
36
|
function print_object(obj, opts) {
|
33
|
-
var seen = opts.seen || [];
|
37
|
+
var seen = opts.seen || [ obj ];
|
34
38
|
|
35
39
|
var result = [], key, value;
|
36
40
|
for (var k in obj) {
|
@@ -45,9 +49,6 @@
|
|
45
49
|
return "{ " + result.join(", ") + " }";
|
46
50
|
}
|
47
51
|
|
48
|
-
function print_jquery(obj) {
|
49
|
-
}
|
50
|
-
|
51
52
|
function print_string(value, opts) {
|
52
53
|
var character_substitutions = {
|
53
54
|
'\b': '\\b',
|
@@ -81,18 +82,18 @@
|
|
81
82
|
return "undefined";
|
82
83
|
else if (typeof obj == 'boolean')
|
83
84
|
return obj.toString();
|
84
|
-
else if (
|
85
|
-
return
|
85
|
+
else if (typeof obj == 'number')
|
86
|
+
return obj.toString();
|
86
87
|
else if (!obj)
|
87
88
|
return "null";
|
88
89
|
else if (typeof obj == 'string')
|
89
90
|
return print_string(obj, opts);
|
90
91
|
else if (obj instanceof RegExp)
|
91
92
|
return obj.toString();
|
93
|
+
else if (obj instanceof Array || obj.callee || obj.item)
|
94
|
+
return print_array(obj, opts);
|
92
95
|
else if (typeof obj == 'function' || obj instanceof Function)
|
93
96
|
return obj.toString().match(/^([^)]*\))/)[1];
|
94
|
-
else if (obj instanceof Array)
|
95
|
-
return print_array(obj, opts);
|
96
97
|
else if (obj.nodeType)
|
97
98
|
return print_element(obj);
|
98
99
|
else if (obj instanceof jQuery)
|
@@ -104,5 +105,5 @@
|
|
104
105
|
else
|
105
106
|
return obj.toString().replace(/\n\s*/g, '');
|
106
107
|
}
|
107
|
-
|
108
|
+
|
108
109
|
})(jQuery);
|
data/core/lib/screw.behaviors.js
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
$(Screw).bind('loaded', function() {
|
3
3
|
$('.status').fn({
|
4
4
|
display: function() {
|
5
|
-
$(this).
|
6
|
-
$('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)'
|
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"
|
7
8
|
);
|
8
9
|
}
|
9
10
|
});
|
@@ -35,7 +36,7 @@
|
|
35
36
|
});
|
36
37
|
|
37
38
|
$('body > .describe').fn({
|
38
|
-
selector: function() { return 'body > .describe' }
|
39
|
+
selector: function() { return 'body > .describe'; }
|
39
40
|
});
|
40
41
|
|
41
42
|
$('.it').fn({
|
@@ -62,7 +63,7 @@
|
|
62
63
|
$(Screw)
|
63
64
|
.queue(function() {
|
64
65
|
self.fn('run');
|
65
|
-
setTimeout(function() { $(Screw).dequeue() }, 0);
|
66
|
+
setTimeout(function() { $(Screw).dequeue(); }, 0);
|
66
67
|
});
|
67
68
|
},
|
68
69
|
|
@@ -72,12 +73,13 @@
|
|
72
73
|
}
|
73
74
|
});
|
74
75
|
|
75
|
-
$('.before').fn({
|
76
|
-
run: function() { $(this).data('screwunit.run')() }
|
76
|
+
$('body .before').fn({
|
77
|
+
run: function() { $(this).data('screwunit.run')(); }
|
77
78
|
});
|
78
79
|
|
79
|
-
$('.after').fn({
|
80
|
-
run: function() {
|
80
|
+
$('body .after').fn({
|
81
|
+
run: function() {
|
82
|
+
$(this).data('screwunit.run')(); }
|
81
83
|
});
|
82
84
|
|
83
85
|
$(Screw).trigger('before');
|
@@ -87,5 +89,5 @@
|
|
87
89
|
.eq(0).trigger('scroll').end()
|
88
90
|
.fn('enqueue');
|
89
91
|
$(Screw).queue(function() { $(Screw).trigger('after') });
|
90
|
-
})
|
92
|
+
});
|
91
93
|
})(jQuery);
|
data/core/lib/screw.builder.js
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
var Screw = (function($) {
|
2
2
|
var screw = {
|
3
3
|
Unit: function(fn) {
|
4
|
-
var
|
5
|
-
|
4
|
+
var wrappedFn;
|
5
|
+
if(fn.length == 0) {
|
6
|
+
var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
|
7
|
+
wrappedFn = new Function("matchers", "specifications",
|
6
8
|
"with (specifications) { with (matchers) { " + contents + " } }"
|
7
|
-
|
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
|
+
}
|
8
22
|
|
9
23
|
$(Screw).queue(function() {
|
10
24
|
Screw.Specifications.context.push($('body > .describe'));
|
11
|
-
|
25
|
+
wrappedFn.call(this, Screw.Matchers, Screw.Specifications);
|
12
26
|
Screw.Specifications.context.pop();
|
13
27
|
$(this).dequeue();
|
14
28
|
});
|
@@ -19,7 +33,7 @@ var Screw = (function($) {
|
|
19
33
|
|
20
34
|
describe: function(name, fn) {
|
21
35
|
var describe = $('<li class="describe">')
|
22
|
-
.append($('<h1
|
36
|
+
.append($('<h1 />').text(name))
|
23
37
|
.append('<ol class="befores">')
|
24
38
|
.append('<ul class="its">')
|
25
39
|
.append('<ul class="describes">')
|
@@ -36,7 +50,7 @@ var Screw = (function($) {
|
|
36
50
|
|
37
51
|
it: function(name, fn) {
|
38
52
|
var it = $('<li class="it">')
|
39
|
-
.append($('<h2
|
53
|
+
.append($('<h2 />').text(name))
|
40
54
|
.data('screwunit.run', fn);
|
41
55
|
|
42
56
|
this.context[this.context.length-1]
|
@@ -45,7 +59,7 @@ var Screw = (function($) {
|
|
45
59
|
},
|
46
60
|
|
47
61
|
before: function(fn) {
|
48
|
-
var before = $('<li class="before">')
|
62
|
+
var before = $('<li class="before"></li>')
|
49
63
|
.data('screwunit.run', fn);
|
50
64
|
|
51
65
|
this.context[this.context.length-1]
|
@@ -54,7 +68,7 @@ var Screw = (function($) {
|
|
54
68
|
},
|
55
69
|
|
56
70
|
after: function(fn) {
|
57
|
-
var after = $('<li class="after">')
|
71
|
+
var after = $('<li class="after"></li>')
|
58
72
|
.data('screwunit.run', fn);
|
59
73
|
|
60
74
|
this.context[this.context.length-1]
|
@@ -65,16 +79,17 @@ var Screw = (function($) {
|
|
65
79
|
};
|
66
80
|
|
67
81
|
$(screw).queue(function() { $(screw).trigger('loading') });
|
68
|
-
$(function()
|
82
|
+
$(window).load(function(){
|
69
83
|
$('<div class="describe">')
|
70
|
-
.append('<h3 class="status"
|
84
|
+
.append('<h3 class="status" />')
|
71
85
|
.append('<ol class="befores">')
|
72
86
|
.append('<ul class="describes">')
|
73
87
|
.append('<ol class="afters">')
|
74
88
|
.appendTo('body');
|
75
|
-
|
89
|
+
|
76
90
|
$(screw).dequeue();
|
77
91
|
$(screw).trigger('loaded');
|
78
92
|
});
|
93
|
+
|
79
94
|
return screw;
|
80
95
|
})(jQuery);
|
data/core/lib/screw.css
CHANGED
@@ -42,7 +42,7 @@ html {
|
|
42
42
|
.describes .describe {
|
43
43
|
margin-left: 0.6em;
|
44
44
|
padding-left: 0.6em;
|
45
|
-
border: 1px dashed
|
45
|
+
border: 1px dashed #6E6E6E;
|
46
46
|
}
|
47
47
|
|
48
48
|
.describes .describe .its {}
|
@@ -87,4 +87,4 @@ html {
|
|
87
87
|
cursor: pointer;
|
88
88
|
color: #000 !important;
|
89
89
|
border-bottom: 1px solid #9A8E51;
|
90
|
-
}
|
90
|
+
}
|
data/core/lib/screw.events.js
CHANGED
@@ -27,12 +27,19 @@
|
|
27
27
|
$(this)
|
28
28
|
.addClass('failed')
|
29
29
|
.append($('<p class="error">').text(reason.toString()));
|
30
|
-
|
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
|
+
});
|
31
37
|
})
|
32
38
|
.bind('before', function() {
|
39
|
+
Screw.suite_start_time = new Date();
|
33
40
|
$('.status').text('Running...');
|
34
41
|
})
|
35
42
|
.bind('after', function() {
|
36
|
-
$('.status').fn('display')
|
37
|
-
})
|
38
|
-
})(jQuery);
|
43
|
+
$('body .status').fn('display');
|
44
|
+
});
|
45
|
+
})(jQuery);
|
data/core/lib/screw.matchers.js
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
Screw.Matchers = (function($) {
|
2
2
|
return matchers = {
|
3
3
|
expect: function(actual) {
|
4
|
+
var funcname = function(f) {
|
5
|
+
var s = f.toString().match(/function (\w*)/)[1];
|
6
|
+
if ((s == null) || (s.length == 0)) return "anonymous";
|
7
|
+
return s;
|
8
|
+
};
|
9
|
+
|
10
|
+
var stacktrace = function() {
|
11
|
+
var s = "";
|
12
|
+
for(var a = arguments.caller; a != null; a = a.caller) {
|
13
|
+
s += funcname(a.callee) + "\n";
|
14
|
+
if (a.caller == a) break;
|
15
|
+
}
|
16
|
+
return s;
|
17
|
+
};
|
18
|
+
|
4
19
|
return {
|
5
20
|
to: function(matcher, expected, not) {
|
6
21
|
var matched = matcher.match(expected, actual);
|
@@ -8,35 +23,77 @@ Screw.Matchers = (function($) {
|
|
8
23
|
throw(matcher.failure_message(expected, actual, not));
|
9
24
|
}
|
10
25
|
},
|
11
|
-
|
26
|
+
|
12
27
|
to_not: function(matcher, expected) {
|
13
28
|
this.to(matcher, expected, true);
|
14
29
|
}
|
15
30
|
}
|
16
31
|
},
|
17
|
-
|
32
|
+
|
18
33
|
equal: {
|
19
34
|
match: function(expected, actual) {
|
35
|
+
if(expected == actual) return true;
|
36
|
+
if(actual == undefined) return false;
|
37
|
+
|
20
38
|
if (expected instanceof Array) {
|
21
39
|
for (var i = 0; i < actual.length; i++)
|
22
40
|
if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
|
23
41
|
return actual.length == expected.length;
|
24
42
|
} else if (expected instanceof Object) {
|
25
43
|
for (var key in expected)
|
26
|
-
if (expected[key]
|
44
|
+
if (!this.match(expected[key], actual[key])) return false;
|
27
45
|
for (var key in actual)
|
28
|
-
if (actual[key]
|
46
|
+
if (!this.match(actual[key], expected[key])) return false;
|
29
47
|
return true;
|
30
|
-
} else {
|
31
|
-
return expected == actual;
|
32
48
|
}
|
49
|
+
return false;
|
33
50
|
},
|
34
|
-
|
51
|
+
|
35
52
|
failure_message: function(expected, actual, not) {
|
36
53
|
return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
|
37
54
|
}
|
38
55
|
},
|
39
|
-
|
56
|
+
|
57
|
+
be_gt: {
|
58
|
+
match: function(expected, actual) {
|
59
|
+
return actual > expected;
|
60
|
+
},
|
61
|
+
|
62
|
+
failure_message: function(expected, actual, not) {
|
63
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than ' + $.print(expected);
|
64
|
+
}
|
65
|
+
},
|
66
|
+
|
67
|
+
be_gte: {
|
68
|
+
match: function(expected, actual) {
|
69
|
+
return actual >= expected;
|
70
|
+
},
|
71
|
+
|
72
|
+
failure_message: function(expected, actual, not) {
|
73
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than or equal to ' + $.print(expected);
|
74
|
+
}
|
75
|
+
},
|
76
|
+
|
77
|
+
be_lt: {
|
78
|
+
match: function(expected, actual) {
|
79
|
+
return actual < expected;
|
80
|
+
},
|
81
|
+
|
82
|
+
failure_message: function(expected, actual, not) {
|
83
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than ' + $.print(expected);
|
84
|
+
}
|
85
|
+
},
|
86
|
+
|
87
|
+
be_lte: {
|
88
|
+
match: function(expected, actual) {
|
89
|
+
return actual <= expected;
|
90
|
+
},
|
91
|
+
|
92
|
+
failure_message: function(expected, actual, not) {
|
93
|
+
return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than or equal to ' + $.print(expected);
|
94
|
+
}
|
95
|
+
},
|
96
|
+
|
40
97
|
match: {
|
41
98
|
match: function(expected, actual) {
|
42
99
|
if (expected.constructor == RegExp)
|
@@ -44,22 +101,144 @@ Screw.Matchers = (function($) {
|
|
44
101
|
else
|
45
102
|
return actual.indexOf(expected) > -1;
|
46
103
|
},
|
47
|
-
|
104
|
+
|
48
105
|
failure_message: function(expected, actual, not) {
|
49
106
|
return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
|
50
107
|
}
|
51
108
|
},
|
52
|
-
|
109
|
+
|
53
110
|
be_empty: {
|
54
111
|
match: function(expected, actual) {
|
55
112
|
if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
|
56
|
-
|
113
|
+
|
57
114
|
return actual.length == 0;
|
58
115
|
},
|
59
|
-
|
116
|
+
|
60
117
|
failure_message: function(expected, actual, not) {
|
61
118
|
return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
|
62
119
|
}
|
120
|
+
},
|
121
|
+
|
122
|
+
be_blank: {
|
123
|
+
match: function(expected, actual) {
|
124
|
+
if (actual == undefined) return true;
|
125
|
+
if (typeof(actual) == "string") actual = actual.replace(/^\s*(.*?)\s*$/, "$1");
|
126
|
+
return Screw.Matchers.be_empty.match(expected, actual);
|
127
|
+
},
|
128
|
+
|
129
|
+
failure_message: function(expected, actual, not) {
|
130
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be blank' : ' to be blank');
|
131
|
+
}
|
132
|
+
},
|
133
|
+
|
134
|
+
have_length: {
|
135
|
+
match: function(expected, actual) {
|
136
|
+
if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
|
137
|
+
|
138
|
+
return actual.length == expected;
|
139
|
+
},
|
140
|
+
|
141
|
+
failure_message: function(expected, actual, not) {
|
142
|
+
return 'expected ' + $.print(actual) + (not ? ' to not' : ' to') + ' have length ' + expected;
|
143
|
+
}
|
144
|
+
},
|
145
|
+
|
146
|
+
be_null: {
|
147
|
+
match: function(expected, actual) {
|
148
|
+
return actual == null;
|
149
|
+
},
|
150
|
+
|
151
|
+
failure_message: function(expected, actual, not) {
|
152
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
|
153
|
+
}
|
154
|
+
},
|
155
|
+
|
156
|
+
be_undefined: {
|
157
|
+
match: function(expected, actual) {
|
158
|
+
return actual == undefined;
|
159
|
+
},
|
160
|
+
|
161
|
+
failure_message: function(expected, actual, not) {
|
162
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
|
163
|
+
}
|
164
|
+
},
|
165
|
+
|
166
|
+
be_true: {
|
167
|
+
match: function(expected, actual) {
|
168
|
+
return actual;
|
169
|
+
},
|
170
|
+
|
171
|
+
failure_message: function(expected, actual, not) {
|
172
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
|
173
|
+
}
|
174
|
+
},
|
175
|
+
|
176
|
+
be_false: {
|
177
|
+
match: function(expected, actual) {
|
178
|
+
return !actual;
|
179
|
+
},
|
180
|
+
|
181
|
+
failure_message: function(expected, actual, not) {
|
182
|
+
return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
|
183
|
+
}
|
184
|
+
},
|
185
|
+
|
186
|
+
match_html: {
|
187
|
+
munge: function(mungee) {
|
188
|
+
if (mungee instanceof jQuery) {
|
189
|
+
mungee = mungee.html();
|
190
|
+
} else if (typeof(mungee) == "string") {
|
191
|
+
var span = document.createElement("span");
|
192
|
+
span.innerHTML = mungee;
|
193
|
+
mungee = span.innerHTML;
|
194
|
+
}
|
195
|
+
|
196
|
+
var regEx = /\sjQuery\d+=['"]\d+['"]/g;
|
197
|
+
mungee = mungee.replace(regEx, "");
|
198
|
+
|
199
|
+
return mungee;
|
200
|
+
},
|
201
|
+
|
202
|
+
match: function(expected, actual) {
|
203
|
+
var trimmedExpected = this.munge(expected);
|
204
|
+
var trimmedActual = this.munge(actual);
|
205
|
+
return trimmedActual.indexOf(trimmedExpected) > -1;
|
206
|
+
},
|
207
|
+
|
208
|
+
failure_message: function(expected, actual, not) {
|
209
|
+
var trimmedExpected = this.munge(expected);
|
210
|
+
var trimmedActual = this.munge(actual);
|
211
|
+
return 'expected ' + $.print(trimmedActual, { max_string: 300 }) +
|
212
|
+
(not ? ' to not contain ' : ' to contain ') + $.print(trimmedExpected, { max_string: 300 });
|
213
|
+
}
|
214
|
+
},
|
215
|
+
|
216
|
+
match_selector: {
|
217
|
+
match: function(expected, actual) {
|
218
|
+
if (!(actual instanceof jQuery)) {
|
219
|
+
throw expected.toString() + " must be an instance of jQuery to match against a selector"
|
220
|
+
}
|
221
|
+
|
222
|
+
return actual.is(expected);
|
223
|
+
},
|
224
|
+
|
225
|
+
failure_message: function(expected, actual, not) {
|
226
|
+
return 'expected ' + $.print(actual) + (not ? ' to not match selector ' : ' to match selector ') + expected;
|
227
|
+
}
|
228
|
+
},
|
229
|
+
|
230
|
+
contain_selector: {
|
231
|
+
match: function(expected, actual) {
|
232
|
+
if (!(actual instanceof jQuery)) {
|
233
|
+
throw expected.toString() + " must be an instance of jQuery to match against a selector"
|
234
|
+
}
|
235
|
+
|
236
|
+
return actual.find(expected).length > 0;
|
237
|
+
},
|
238
|
+
|
239
|
+
failure_message: function(expected, actual, not) {
|
240
|
+
return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
|
241
|
+
}
|
63
242
|
}
|
64
243
|
}
|
65
|
-
})(jQuery);
|
244
|
+
})(jQuery);
|