screw-unit 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGES +7 -1
  2. data/core/CHANGES +10 -0
  3. data/core/example/models/man.js +2 -2
  4. data/core/lib/jquery.print.js +2 -2
  5. data/core/lib/screw.behaviors.js +3 -2
  6. data/core/lib/screw.builder.js +15 -15
  7. data/core/lib/screw.css +2 -2
  8. data/core/lib/screw.events.js +3 -2
  9. data/core/lib/screw.matchers.js +53 -11
  10. data/core/spec/behaviors_spec.js +11 -1
  11. data/core/spec/matchers_spec.js +144 -9
  12. data/core/spec/print_spec.js +14 -8
  13. data/lib/screw_unit/resources/spec.rb +66 -3
  14. data/spec/functional/functional_spec_helper.rb +1 -1
  15. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +7 -8
  16. data/spec/unit/js_test_core/specs/spec_file_spec.rb +5 -6
  17. data/spec/unit/unit_spec_helper.rb +1 -3
  18. data/vendor/js-test-core/CHANGES +5 -0
  19. data/vendor/js-test-core/Rakefile +1 -1
  20. data/vendor/js-test-core/lib/js_test_core/client.rb +19 -16
  21. data/vendor/js-test-core/lib/js_test_core/resources.rb +2 -2
  22. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +9 -18
  23. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +17 -15
  24. data/vendor/js-test-core/lib/js_test_core/resources/{suite.rb → session.rb} +8 -4
  25. data/vendor/js-test-core/lib/js_test_core/resources/{suite_finish.rb → session_finish.rb} +5 -5
  26. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +6 -3
  27. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +22 -21
  28. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +0 -38
  29. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +83 -63
  30. data/vendor/js-test-core/spec/unit/js_test_core/resources/{suite_finish_spec.rb → session_finish_spec.rb} +15 -18
  31. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +82 -0
  32. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +3 -3
  33. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +37 -10
  34. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +4 -0
  35. metadata +88 -89
  36. data/core/lib/screw.assets.js +0 -36
  37. data/core/lib/screw.server.js +0 -21
  38. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -86
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ 0.3.3
2
+ - Fixed for latest version of Selenium, Rack, and Thin
3
+
4
+ 0.3.2
5
+ - Upgrading to ScrewUnit 0.3.2
6
+
1
7
  0.3.1
2
8
  - Client accepts selenium_server_start_command parameter, which allows the user to parameterize the selenium_server_start_command
3
9
  - Added support for running specs in Internet Explorer via POST /runners/iexplore
@@ -8,4 +14,4 @@
8
14
  - Uses ScrewUnit 0.3.0
9
15
 
10
16
  0.1.0
11
- - Initial Release
17
+ - Initial Release
@@ -0,0 +1,10 @@
1
+ 0.3.3
2
+ - Fixed for latest version of Selenium, Rack, and Thin
3
+
4
+ 0.3.2
5
+ - Adding IE support
6
+ - Fix printing of 0 as 'NaN'
7
+
8
+ 0.2.0
9
+ - Added elapsed time information in test suite run.
10
+ - Equal matchers works with complex hash structures
@@ -8,8 +8,8 @@ function Man(options) {
8
8
  return luck;
9
9
  };
10
10
  this.render = function() {
11
- return $('<ul class="man">')
12
- .append('<li class="hair">')
11
+ return $('<ul class="man"></ul>')
12
+ .append('<li class="hair"></li>')
13
13
  .click(function() {
14
14
  $(this).children('.hair').remove();
15
15
  });
@@ -82,8 +82,8 @@
82
82
  return "undefined";
83
83
  else if (typeof obj == 'boolean')
84
84
  return obj.toString();
85
- else if (!obj && typeof obj == 'number')
86
- return 'NaN';
85
+ else if (typeof obj == 'number')
86
+ return obj.toString();
87
87
  else if (!obj)
88
88
  return "null";
89
89
  else if (typeof obj == 'string')
@@ -2,8 +2,9 @@
2
2
  $(Screw).bind('loaded', function() {
3
3
  $('.status').fn({
4
4
  display: function() {
5
- $(this).text(
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
  });
@@ -18,12 +18,12 @@ var Screw = (function($) {
18
18
  context: [],
19
19
 
20
20
  describe: function(name, fn) {
21
- var describe = $('<li class="describe">')
22
- .append($('<h1>').text(name))
23
- .append('<ol class="befores">')
24
- .append('<ul class="its">')
25
- .append('<ul class="describes">')
26
- .append('<ol class="afters">');
21
+ var describe = $('<li class="describe"></li>')
22
+ .append($('<h1></h1>').text(name))
23
+ .append('<ol class="befores"></ol>')
24
+ .append('<ul class="its"></ul>')
25
+ .append('<ul class="describes"></ul>')
26
+ .append('<ol class="afters"></ol>');
27
27
 
28
28
  this.context.push(describe);
29
29
  fn.call();
@@ -35,8 +35,8 @@ var Screw = (function($) {
35
35
  },
36
36
 
37
37
  it: function(name, fn) {
38
- var it = $('<li class="it">')
39
- .append($('<h2>').text(name))
38
+ var it = $('<li class="it"></li>')
39
+ .append($('<h2></h2>').text(name))
40
40
  .data('screwunit.run', fn);
41
41
 
42
42
  this.context[this.context.length-1]
@@ -45,7 +45,7 @@ var Screw = (function($) {
45
45
  },
46
46
 
47
47
  before: function(fn) {
48
- var before = $('<li class="before">')
48
+ var before = $('<li class="before"></li>')
49
49
  .data('screwunit.run', fn);
50
50
 
51
51
  this.context[this.context.length-1]
@@ -54,7 +54,7 @@ var Screw = (function($) {
54
54
  },
55
55
 
56
56
  after: function(fn) {
57
- var after = $('<li class="after">')
57
+ var after = $('<li class="after"></li>')
58
58
  .data('screwunit.run', fn);
59
59
 
60
60
  this.context[this.context.length-1]
@@ -66,11 +66,11 @@ var Screw = (function($) {
66
66
 
67
67
  $(screw).queue(function() { $(screw).trigger('loading') });
68
68
  $(function() {
69
- $('<div class="describe">')
70
- .append('<h3 class="status">')
71
- .append('<ol class="befores">')
72
- .append('<ul class="describes">')
73
- .append('<ol class="afters">')
69
+ $('<div class="describe"></div>')
70
+ .append('<h3 class="status"></h3>')
71
+ .append('<ol class="befores"></ol>')
72
+ .append('<ul class="describes"></ul>')
73
+ .append('<ol class="afters"></ol>')
74
74
  .appendTo('body');
75
75
 
76
76
  $(screw).dequeue();
@@ -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 grey;
45
+ border: 1px dashed #999;
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
+ }
@@ -26,16 +26,17 @@
26
26
  .bind('failed', function(e, reason) {
27
27
  $(this)
28
28
  .addClass('failed')
29
- .append($('<p class="error">').text(reason.toString()))
29
+ .append($('<p class="error"></p>').text(reason.toString()));
30
30
 
31
31
  var file = reason.fileName || reason.sourceURL;
32
32
  var line = reason.lineNumber || reason.line;
33
33
  if (file || line) {
34
- $(this).append($('<p class="error">').text('line ' + line + ', ' + file));
34
+ $(this).append($('<p class="error"></p>').text('line ' + line + ', ' + file));
35
35
  }
36
36
  })
37
37
  })
38
38
  .bind('before', function() {
39
+ Screw.suite_start_time = new Date();
39
40
  $('.status').text('Running...');
40
41
  })
41
42
  .bind('after', function() {
@@ -8,35 +8,77 @@ Screw.Matchers = (function($) {
8
8
  throw(matcher.failure_message(expected, actual, not));
9
9
  }
10
10
  },
11
-
11
+
12
12
  to_not: function(matcher, expected) {
13
13
  this.to(matcher, expected, true);
14
14
  }
15
15
  }
16
16
  },
17
-
17
+
18
18
  equal: {
19
19
  match: function(expected, actual) {
20
+ if(expected == actual) return true;
21
+ if(actual == undefined) return false;
22
+
20
23
  if (expected instanceof Array) {
21
24
  for (var i = 0; i < actual.length; i++)
22
25
  if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
23
26
  return actual.length == expected.length;
24
27
  } else if (expected instanceof Object) {
25
28
  for (var key in expected)
26
- if (expected[key] != actual[key]) return false;
29
+ if (!this.match(expected[key], actual[key])) return false;
27
30
  for (var key in actual)
28
- if (actual[key] != expected[key]) return false;
31
+ if (!this.match(actual[key], expected[key])) return false;
29
32
  return true;
30
- } else {
31
- return expected == actual;
32
33
  }
34
+ return false;
33
35
  },
34
-
36
+
35
37
  failure_message: function(expected, actual, not) {
36
38
  return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
37
39
  }
38
40
  },
39
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
+
40
82
  match: {
41
83
  match: function(expected, actual) {
42
84
  if (expected.constructor == RegExp)
@@ -44,19 +86,19 @@ Screw.Matchers = (function($) {
44
86
  else
45
87
  return actual.indexOf(expected) > -1;
46
88
  },
47
-
89
+
48
90
  failure_message: function(expected, actual, not) {
49
91
  return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
50
92
  }
51
93
  },
52
-
94
+
53
95
  be_empty: {
54
96
  match: function(expected, actual) {
55
97
  if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
56
-
98
+
57
99
  return actual.length == 0;
58
100
  },
59
-
101
+
60
102
  failure_message: function(expected, actual, not) {
61
103
  return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
62
104
  }
@@ -2,9 +2,19 @@ Screw.Unit(function() {
2
2
  var global_before_invoked = false, global_after_invoked = false;
3
3
  before(function() { global_before_invoked = true });
4
4
  after(function() { global_after_invoked = true });
5
-
5
+
6
6
  describe('Behaviors', function() {
7
7
  describe('#run', function() {
8
+ describe("elapsed time", function() {
9
+ it("displays the elapsed time after the Suite finishes", function() {
10
+ var status = $(".status");
11
+ status.fn("display");
12
+ var time_elapsed_matches = /([0-9]+\.[0-9]+) seconds/.exec(status.html());
13
+ var time_elapsed = parseFloat(time_elapsed_matches[1]);
14
+ expect(time_elapsed > 0.0).to(be_true);
15
+ });
16
+ });
17
+
8
18
  describe("a simple [describe]", function() {
9
19
  it("invokes the global [before] before an [it]", function() {
10
20
  expect(global_before_invoked).to(equal, true);
@@ -6,15 +6,41 @@ Screw.Unit(function() {
6
6
  expect(true).to_not(equal, false);
7
7
  });
8
8
 
9
- describe('when given an object', function() {
10
- it("matches Objects with the same keys and values", function() {
11
- expect({a: 'b', c: 'd'}).to(equal, {a: 'b', c: 'd'});
12
- expect({a: 'b', c: 'd', e: 'f'}).to_not(equal, {a: 'b', c: 'd', e: 'G'});
9
+ describe('when actual is an object', function() {
10
+ describe("when expected has the same keys and values", function() {
11
+ it("matches successfully", function() {
12
+ expect({a: 'b', c: 'd'}).to(equal, {a: 'b', c: 'd'});
13
+ });
13
14
  });
14
15
 
16
+ describe("when expected has different keys and values", function() {
17
+ it("does not match", function() {
18
+ expect({a: 'b', c: 'd', e: 'f'}).to_not(equal, {a: 'b', c: 'd', e: 'G'});
19
+ });
20
+ });
21
+
22
+ describe("when expected is undefined", function() {
23
+ it("does not match", function() {
24
+ expect({}).to_not(equal, undefined);
25
+ });
26
+ });
15
27
  });
16
28
 
17
- describe('when given an array', function() {
29
+ describe("when actual is undefined", function() {
30
+ describe("when expected is undefined", function() {
31
+ it("matches successfully", function() {
32
+ expect(undefined).to(equal, undefined);
33
+ });
34
+ });
35
+
36
+ describe("when expected is an empty object", function() {
37
+ it("does not match", function() {
38
+ expect(undefined).to_not(equal, {});
39
+ });
40
+ });
41
+ });
42
+
43
+ describe('when actual is an array', function() {
18
44
  it("matches Arrays with the same elements", function() {
19
45
  expect([1, 2, 4]).to(equal, [1, 2, 4]);
20
46
  expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
@@ -25,7 +51,21 @@ Screw.Unit(function() {
25
51
  expect([{a: 'b'}, {c: 'd'}]).to_not(equal, [{a: 'b'}, {c: 'E'}]);
26
52
  });
27
53
  });
28
-
54
+
55
+ describe("when actual is a hash", function() {
56
+ it("matches hashes with the same key-value pairs", function() {
57
+ expect({"a":"b", "c":"d"}).to(equal, {"a":"b", "c":"d"});
58
+ expect({"a":"b", "c":"e"}).to_not(equal, {"a":"b", "c":"d"});
59
+ expect({"a":"b", "d":"d"}).to_not(equal, {"a":"b", "c":"d"});
60
+ });
61
+
62
+ it("recursively applies equality to complex hashes", function() {
63
+ expect({"a":"b", "c": {"e":"f", "g":"h"}}).to(equal, {"a":"b", "c": {"e":"f", "g":"h"}});
64
+ expect({"a":"b", "c": {"e":"f", "g":"i"}}).to_not(equal, {"a":"b", "c": {"e":"f", "g":"h"}});
65
+ expect({"a":"b", "c": {"e":"f", "h":"h"}}).to_not(equal, {"a":"b", "c": {"e":"f", "g":"h"}});
66
+ });
67
+ });
68
+
29
69
  describe(".failure_message", function() {
30
70
  it('prints "expected [expected] to (not) be equal [actual]"', function() {
31
71
  var message = null;
@@ -39,21 +79,21 @@ Screw.Unit(function() {
39
79
  });
40
80
 
41
81
  describe('#match', function() {
42
- describe('when given a regular expression', function() {
82
+ describe('when actual is a regular expression', function() {
43
83
  it("matches Strings produced by the grammar", function() {
44
84
  expect("The wheels of the bus").to(match, /bus/);
45
85
  expect("The wheels of the bus").to_not(match, /boat/);
46
86
  });
47
87
  });
48
88
 
49
- describe('when given a string', function() {
89
+ describe('when actual is a string', function() {
50
90
  it("matches [expected]s containing [actual]s", function() {
51
91
  expect("The wheels of the bus").to(match, "wheels");
52
92
  expect("The wheels of the bus").to_not(match, "oars");
53
93
  });
54
94
  });
55
95
 
56
- describe('when given an integer', function() {
96
+ describe('when actual is an integer', function() {
57
97
  it("matches [expected]s containing [actual]s", function() {
58
98
  expect("1 time").to(match, 1);
59
99
  expect("2 times").to_not(match, 3);
@@ -233,5 +273,100 @@ Screw.Unit(function() {
233
273
  });
234
274
  });
235
275
 
276
+ describe('#be_gt', function() {
277
+ it('matches integers greater than the expected value', function() {
278
+ expect(2).to(be_gt, 1);
279
+ expect(1).to(be_gt, 0);
280
+ expect(0).to(be_gt, -1);
281
+ expect(0).to_not(be_gt, 0);
282
+ expect(-1).to_not(be_gt, 0);
283
+ expect(0).to_not(be_gt, 1);
284
+ expect(1).to_not(be_gt, 5);
285
+ });
286
+
287
+ describe(".failure_message", function() {
288
+ it('prints "expected [expected] to (not) be greater than [actual]"', function() {
289
+ var message = null;
290
+ try { expect(1).to(be_gt, 2) } catch(e) { message = e }
291
+ expect(message).to(equal, 'expected 1 to be greater than 2');
292
+
293
+ try { expect(2).to_not(be_gt, 1) } catch(e) { message = e }
294
+ expect(message).to(equal, 'expected 2 to not be greater than 1');
295
+ });
296
+ });
297
+ });
298
+
299
+ describe('#be_gte', function() {
300
+ it('matches integers greater than or equal to the expected value', function() {
301
+ expect(2).to(be_gte, 1);
302
+ expect(1).to(be_gte, 0);
303
+ expect(0).to(be_gte, -1);
304
+ expect(-1).to(be_gte, -1);
305
+ expect(0).to(be_gte, 0);
306
+ expect(1).to(be_gte, 1);
307
+ expect(-1).to_not(be_gte, 0);
308
+ expect(0).to_not(be_gte, 1);
309
+ expect(1).to_not(be_gte, 5);
310
+ });
311
+
312
+ describe(".failure_message", function() {
313
+ it('prints "expected [expected] to (not) be greater than or equal to [actual]"', function() {
314
+ var message = null;
315
+ try { expect(1).to(be_gte, 2) } catch(e) { message = e }
316
+ expect(message).to(equal, 'expected 1 to be greater than or equal to 2');
317
+
318
+ try { expect(2).to_not(be_gte, 1) } catch(e) { message = e }
319
+ expect(message).to(equal, 'expected 2 to not be greater than or equal to 1');
320
+ });
321
+ });
322
+ });
323
+
324
+ describe('#be_lt', function() {
325
+ it('matches integers less than the expected value', function() {
326
+ expect(1).to(be_lt, 2);
327
+ expect(0).to(be_lt, 1);
328
+ expect(-1).to(be_lt, 0);
329
+ expect(0).to_not(be_lt, 0);
330
+ expect(0).to_not(be_lt, -1);
331
+ expect(1).to_not(be_lt, 0);
332
+ expect(5).to_not(be_lt, 1);
333
+ });
334
+
335
+ describe(".failure_message", function() {
336
+ it('prints "expected [expected] to (not) be less than [actual]"', function() {
337
+ var message = null;
338
+ try { expect(2).to(be_lt, 1) } catch(e) { message = e }
339
+ expect(message).to(equal, 'expected 2 to be less than 1');
340
+
341
+ try { expect(1).to_not(be_lt, 2) } catch(e) { message = e }
342
+ expect(message).to(equal, 'expected 1 to not be less than 2');
343
+ });
344
+ });
345
+ });
346
+
347
+ describe('#be_lte', function() {
348
+ it('matches integers less than or equal to the expected value', function() {
349
+ expect(1).to(be_lte, 2);
350
+ expect(0).to(be_lte, 1);
351
+ expect(-1).to(be_lte, 0);
352
+ expect(-1).to(be_lte, -1);
353
+ expect(0).to(be_lte, 0);
354
+ expect(1).to(be_lte, 1);
355
+ expect(0).to_not(be_lte, -1);
356
+ expect(1).to_not(be_lte, 0);
357
+ expect(5).to_not(be_lte, 1);
358
+ });
359
+
360
+ describe(".failure_message", function() {
361
+ it('prints "expected [expected] to (not) be less than or equal to [actual]"', function() {
362
+ var message = null;
363
+ try { expect(2).to(be_lte, 1) } catch(e) { message = e }
364
+ expect(message).to(equal, 'expected 2 to be less than or equal to 1');
365
+
366
+ try { expect(1).to_not(be_lte, 2) } catch(e) { message = e }
367
+ expect(message).to(equal, 'expected 1 to not be less than or equal to 2');
368
+ });
369
+ });
370
+ });
236
371
  });
237
372
  });