ninjs-framework 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/.DS_Store +0 -0
  2. data/.bundle/config +2 -0
  3. data/.travis.yml +2 -0
  4. data/Gemfile +10 -0
  5. data/Gemfile.lock +47 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +4 -0
  8. data/Rakefile +76 -0
  9. data/VERSION +1 -0
  10. data/lib/.DS_Store +0 -0
  11. data/lib/ninjs-framework.rb +164 -0
  12. data/lib/ninjs-framework/assets/jasmine/jasmine-html.js +190 -0
  13. data/lib/ninjs-framework/assets/jasmine/jasmine.css +166 -0
  14. data/lib/ninjs-framework/assets/jasmine/jasmine.js +2476 -0
  15. data/lib/ninjs-framework/assets/jasmine/jasmine_favicon.png +0 -0
  16. data/lib/ninjs-framework/core/.core.pdoc.yaml +0 -0
  17. data/lib/ninjs-framework/core/.existence.pdoc.yaml +12 -0
  18. data/lib/ninjs-framework/core/.extend.pdoc.yaml +0 -0
  19. data/lib/ninjs-framework/core/.nin.pdoc.yaml +0 -0
  20. data/lib/ninjs-framework/core/application.js +17 -0
  21. data/lib/ninjs-framework/core/dom.js +164 -0
  22. data/lib/ninjs-framework/core/existence.js +60 -0
  23. data/lib/ninjs-framework/core/extend.js +14 -0
  24. data/lib/ninjs-framework/core/module.js +66 -0
  25. data/lib/ninjs-framework/core/nin.js +5 -0
  26. data/lib/ninjs-framework/extensions/jquery.elements.js +60 -0
  27. data/lib/ninjs-framework/templates/application.js.erb +3 -0
  28. data/lib/ninjs-framework/templates/autoload.js.erb +3 -0
  29. data/lib/ninjs-framework/templates/core.js.erb +3 -0
  30. data/lib/ninjs-framework/templates/dependency.js.erb +3 -0
  31. data/lib/ninjs-framework/templates/jasmine.yml.erb +75 -0
  32. data/lib/ninjs-framework/templates/test-index.html.erb +51 -0
  33. data/lib/ninjs-framework/utilities/all.js +5 -0
  34. data/lib/ninjs-framework/utilities/array.js +29 -0
  35. data/lib/ninjs-framework/utilities/cookie.js +59 -0
  36. data/lib/ninjs-framework/utilities/css.js +51 -0
  37. data/lib/ninjs-framework/utilities/number.js +11 -0
  38. data/lib/ninjs-framework/utilities/string.js +61 -0
  39. data/spec/fixtures/myapp.js +530 -0
  40. data/spec/fixtures/nin.js +297 -0
  41. data/spec/fixtures/ninjs.conf +9 -0
  42. data/spec/fixtures/test.elements.js +3 -0
  43. data/spec/fixtures/test.js +14 -0
  44. data/spec/fixtures/test.model.js +3 -0
  45. data/spec/fixtures/test.module.js +10 -0
  46. data/spec/fixtures/utilities.js +211 -0
  47. data/spec/javascripts/application_spec.js +22 -0
  48. data/spec/javascripts/array_utility_spec.js +49 -0
  49. data/spec/javascripts/existence_spec.js +71 -0
  50. data/spec/javascripts/extension_spec.js +22 -0
  51. data/spec/javascripts/helpers/SpecHelper.js +3 -0
  52. data/spec/javascripts/module_spec.js +30 -0
  53. data/spec/javascripts/string_utility_spec.js +85 -0
  54. data/spec/javascripts/support/jasmine.yml +75 -0
  55. data/spec/javascripts/support/jasmine_config.rb +23 -0
  56. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  57. data/spec/ninjs_framework_spec.rb +121 -0
  58. data/spec/spec_helper.rb +41 -0
  59. data/spec/tmp/Rakefile +76 -0
  60. data/spec/tmp/application/myapp.js +530 -0
  61. data/spec/tmp/application/test.js +14 -0
  62. data/spec/tmp/elements/test.elements.js +3 -0
  63. data/spec/tmp/lib/nin.js +297 -0
  64. data/spec/tmp/lib/utilities.js +211 -0
  65. data/spec/tmp/models/test.model.js +3 -0
  66. data/spec/tmp/modules/test.module.js +10 -0
  67. data/spec/tmp/ninjs.conf +9 -0
  68. data/spec/tmp/spec/index.html +51 -0
  69. data/spec/tmp/spec/javascripts/application_spec.js +22 -0
  70. data/spec/tmp/spec/javascripts/array_utility_spec.js +49 -0
  71. data/spec/tmp/spec/javascripts/existence_spec.js +71 -0
  72. data/spec/tmp/spec/javascripts/extension_spec.js +22 -0
  73. data/spec/tmp/spec/javascripts/module_spec.js +30 -0
  74. data/spec/tmp/spec/javascripts/string_utility_spec.js +85 -0
  75. data/spec/tmp/spec/javascripts/support/jasmine-html.js +190 -0
  76. data/spec/tmp/spec/javascripts/support/jasmine.css +166 -0
  77. data/spec/tmp/spec/javascripts/support/jasmine.js +2476 -0
  78. data/spec/tmp/spec/javascripts/support/jasmine.yml.erb +75 -0
  79. data/spec/tmp/spec/javascripts/support/jasmine_config.rb +23 -0
  80. data/spec/tmp/spec/javascripts/support/jasmine_favicon.png +0 -0
  81. data/spec/tmp/spec/javascripts/support/jasmine_runner.rb +32 -0
  82. metadata +285 -0
@@ -0,0 +1,3 @@
1
+ m.set_data({
2
+ some_prop: 'some value'
3
+ });
@@ -0,0 +1,10 @@
1
+ (function(app) {
2
+ var m = app.add_module('test');
3
+ //= require "../models/test.model.js"
4
+ //= require "../elements/test.elements.js"
5
+ m.actions = function() {
6
+
7
+ };
8
+
9
+ m.run();
10
+ })();
@@ -0,0 +1,9 @@
1
+ name: myapp
2
+ framework: ninjs
3
+ src_dir: modules
4
+ dest_dir: application
5
+ output: expanded
6
+ asset_root: ../
7
+ dependencies: ['<jquery/latest>']
8
+ autoload: ['../lib/utilities']
9
+ module_alias: m
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Jasmine Spec Runner: Ninjs</title>
6
+
7
+ <link rel="shortcut icon" type="image/png" href="javascripts/support/jasmine_favicon.png">
8
+ <link rel="stylesheet" href="javascripts/support/jasmine.css" />
9
+ <script src="javascripts/support/jasmine.js"></script>
10
+ <script src="javascripts/support/jasmine-html.js"></script>
11
+
12
+ <!-- NinJs source files -->
13
+ <script type="text/javascript" src="../lib/nin.js"></script>
14
+ <script type="text/javascript" src="../lib/utilities.js"></script>
15
+
16
+ <!-- spec files -->
17
+ <script src="javascripts/existence_spec.js"></script>
18
+ <script src="javascripts/extension_spec.js"></script>
19
+ <script src="javascripts/application_spec.js"></script>
20
+ <script src="javascripts/module_spec.js"></script>
21
+ <script src="javascripts/array_utility_spec.js"></script>
22
+ <script src="javascripts/string_utility_spec.js"></script>
23
+
24
+ <script type="text/javascript">
25
+ (function() {
26
+ var jasmineEnv = jasmine.getEnv();
27
+ var trivialReporter = new jasmine.TrivialReporter();
28
+ var currentWindowOnload = window.onload;
29
+
30
+ jasmineEnv.updateInterval = 1000;
31
+ jasmineEnv.addReporter(trivialReporter);
32
+ jasmineEnv.specFilter = function(spec) {
33
+ return trivialReporter.specFilter(spec);
34
+ };
35
+
36
+ window.onload = function() {
37
+ if (currentWindowOnload) {
38
+ currentWindowOnload();
39
+ }
40
+ execJasmine();
41
+ };
42
+
43
+ function execJasmine() {
44
+ jasmineEnv.execute();
45
+ }
46
+
47
+ })();
48
+ </script>
49
+ </head>
50
+ <body></body>
51
+ </html>
@@ -0,0 +1,22 @@
1
+ describe("NinjsApplication", function() {
2
+ var app;
3
+
4
+ beforeEach(function() {
5
+ app = new NinjsApplication('myapp');
6
+ });
7
+
8
+ afterEach(function() {
9
+ app = undefined;
10
+ });
11
+
12
+ it("should create a ninjs application object", function() {
13
+ expect(is_defined(app)).toBeTruthy();
14
+ expect(is_typeof(NinjsApplication, app)).toBeTruthy();
15
+ });
16
+
17
+ it("should create a NinjsModule", function() {
18
+ app.add_module('mymod');
19
+ expect(is_typeof(NinjsModule, app.mymod)).toBeTruthy();
20
+ });
21
+
22
+ });
@@ -0,0 +1,49 @@
1
+ describe("Array Extensions", function() {
2
+
3
+ it("should test for emptiness with is_empty and not_empty", function() {
4
+ expect([].is_empty()).toBeTruthy();
5
+ expect(['one', 'two', 'three'].is_empty()).toBeFalsy();
6
+ expect(['one', 'two', 'three'].not_empty()).toBeTruthy();
7
+ expect([].not_empty()).toBeFalsy();
8
+ });
9
+
10
+ it("should iterate over each element with each", function() {
11
+ var iteration_count = 0,
12
+ test_array_values = [],
13
+ test_array_indices = [];
14
+
15
+ ['one', 'two', 'three'].each(function(value, index) {
16
+ iteration_count++;
17
+ test_array_values.push(value);
18
+ test_array_indices.push(index);
19
+ });
20
+
21
+ expect(test_array_values[0]).toEqual('one');
22
+ expect(test_array_values[1]).toEqual('two');
23
+ expect(test_array_values[2]).toEqual('three');
24
+
25
+ expect(test_array_indices[0]).toEqual(0);
26
+ expect(test_array_indices[1]).toEqual(1);
27
+ expect(test_array_indices[2]).toEqual(2);
28
+
29
+ expect(iteration_count).toEqual(3);
30
+ });
31
+
32
+ it("should test if an array contains an element", function() {
33
+ var array = ['one', 'two', 'three'],
34
+ string = 'hello',
35
+ object = {
36
+ name: 'some object'
37
+ },
38
+ number = 45,
39
+ date = new Date(),
40
+ test_array = [array, string, object, number, date];
41
+
42
+ expect(test_array.contains(array)).toBeTruthy();
43
+ expect(test_array.contains(string)).toBeTruthy();
44
+ expect(test_array.contains(object)).toBeTruthy();
45
+ expect(test_array.contains(number)).toBeTruthy();
46
+ expect(test_array.contains(date)).toBeTruthy();
47
+ expect(test_array.contains('not in there')).toBeFalsy();
48
+ });
49
+ });
@@ -0,0 +1,71 @@
1
+ describe("Existence:", function() {
2
+
3
+ it("should test for existence with is_defined", function() {
4
+ var nonexistent;
5
+ var existent = 'I think';
6
+ expect(is_defined(existent)).toBeTruthy();
7
+ expect(is_defined(nonexistent)).toBeFalsy();
8
+ });
9
+
10
+ it("should test for non-existence with is_undefined", function() {
11
+ var existent = 'I think';
12
+ var nonexistent;
13
+ expect(is_undefined(nonexistent)).toBeTruthy();
14
+ expect(is_undefined(existent)).toBeFalsy();
15
+ });
16
+
17
+ it("should check for type strictly with is_typeof", function() {
18
+ var foo = function(){};
19
+ var bar = {
20
+ name: 'SomeObject',
21
+ method: function() {}
22
+ };
23
+ var SomeClass = function(){};
24
+ var some_instance = new SomeClass();
25
+
26
+ expect(is_typeof(Number, 4)).toBeTruthy();
27
+ expect(is_typeof(String, 'Hello World')).toBeTruthy();
28
+ expect(is_typeof(Array, ['one', 'two', 'three'])).toBeTruthy();
29
+ expect(is_typeof(Function, foo)).toBeTruthy();
30
+ expect(is_typeof(Object, bar)).toBeTruthy();
31
+ expect(is_typeof(RegExp, /pattern/)).toBeTruthy();
32
+ expect(is_typeof(SomeClass, some_instance)).toBeTruthy();
33
+
34
+ expect(is_typeof(Object, 4)).toBeFalsy();
35
+ expect(is_typeof(Object, 'Hello World')).toBeFalsy();
36
+ expect(is_typeof(Object, ['one', 'two', 'three'])).toBeFalsy();
37
+ expect(is_typeof(Object, foo)).toBeFalsy();
38
+ expect(is_typeof(Function, bar)).toBeFalsy();
39
+ expect(is_typeof(Object, some_instance)).toBeFalsy();
40
+ expect(is_typeof(Function, some_instance)).toBeFalsy();
41
+ });
42
+
43
+ it("should check for default types with convenience methods", function() {
44
+ var today = new Date();
45
+ var easy_as = [1,2,3];
46
+ var pattern = new RegExp(/pattern/);
47
+
48
+ expect(is_string('hello')).toBeTruthy();
49
+ expect(is_number(42)).toBeTruthy();
50
+ expect(is_array(easy_as)).toBeTruthy();
51
+ expect(is_bool(false)).toBeTruthy();
52
+ expect(is_date(today)).toBeTruthy();
53
+ expect(is_regex(pattern)).toBeTruthy();
54
+
55
+ expect(is_regex('hello')).toBeFalsy();
56
+ expect(is_date(42)).toBeFalsy();
57
+ expect(is_bool(easy_as)).toBeFalsy();
58
+ expect(is_array(today)).toBeFalsy();
59
+ expect(is_number(true)).toBeFalsy();
60
+ expect(is_string(pattern)).toBeFalsy();
61
+ });
62
+
63
+ it("should determine if a given string is numerical", function() {
64
+ expect(is_numeric(2)).toBeTruthy();
65
+ expect(is_numeric(-2)).toBeTruthy();
66
+ expect(is_numeric(45.6)).toBeTruthy();
67
+ expect(is_numeric(-45.6)).toBeTruthy();
68
+ expect(is_numeric('45.6')).toBeTruthy();
69
+ expect(is_numeric('Hello')).toBeFalsy();
70
+ });
71
+ });
@@ -0,0 +1,22 @@
1
+ describe("Extensions", function() {
2
+ it("should test a negated conditional with unless", function() {
3
+ var is_true = false,
4
+ does_fallback_work = false;
5
+
6
+ unless (false,
7
+ function() {
8
+ is_true = true;
9
+ }
10
+ );
11
+
12
+ unless (true,
13
+ function() {},
14
+ function() {
15
+ does_fallback_work = true;
16
+ }
17
+ );
18
+
19
+ expect(is_true).toBeTruthy();
20
+ expect(does_fallback_work).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,30 @@
1
+ describe("NinjsModule", function() {
2
+
3
+ var app;
4
+
5
+ beforeEach(function() {
6
+ app = new NinjsApplication('myapp');
7
+ });
8
+
9
+ it("should return the module when added", function() {
10
+ var module = app.add_module('mymod');
11
+ expect(module).toEqual(app.mymod);
12
+ });
13
+
14
+ it("should have the correct default values", function() {
15
+ app.add_module('testmodule');
16
+ // properties
17
+ expect(is_defined(app.testmodule.data)).toBeTruthy();
18
+ expect(is_defined(app.testmodule.name)).toBeTruthy();
19
+ expect(app.testmodule.name).toEqual('testmodule');
20
+
21
+ // methods
22
+ expect(is_defined(app.testmodule.actions)).toBeTruthy();
23
+ expect(is_typeof(Function, app.testmodule.actions)).toBeTruthy();
24
+ expect(is_defined(app.testmodule.run)).toBeTruthy();
25
+ expect(is_typeof(Function, app.testmodule.run)).toBeTruthy();
26
+ expect(is_defined(app.testmodule.execute)).toBeTruthy();
27
+ expect(is_defined(app.testmodule.elements)).toBeTruthy();
28
+ expect(is_defined(app.testmodule.set_data)).toBeTruthy();
29
+ });
30
+ });
@@ -0,0 +1,85 @@
1
+ describe("String utility tests", function() {
2
+
3
+ it("should test for emptiness with is_empty and not_empty", function() {
4
+ expect(''.is_empty()).toBeTruthy();
5
+ expect('hey there'.is_empty()).toBeFalsy();
6
+ expect('hey there'.not_empty()).toBeTruthy();
7
+ expect(''.not_empty()).toBeFalsy();
8
+ });
9
+
10
+ it("should test for a numeric value", function() {
11
+ expect('34'.is_numeric()).toBeTruthy();
12
+ expect('0.5'.is_numeric()).toBeTruthy();
13
+ expect('-34'.is_numeric()).toBeTruthy();
14
+ expect('-0.5'.is_numeric()).toBeTruthy();
15
+ expect('hello'.is_numeric()).toBeFalsy();
16
+ });
17
+
18
+ it("should trim a string with trim, ltrim, and rtrim", function() {
19
+ expect(' hello '.trim()).toEqual('hello');
20
+ expect(' hello '.ltrim()).toEqual('hello ');
21
+ expect(' hello '.rtrim()).toEqual(' hello');
22
+ });
23
+
24
+ it("should iterate over each character with each", function() {
25
+ var iteration_count = 0,
26
+ test_chars = [],
27
+ test_indices = [];
28
+
29
+ '123'.each(function(character, index) {
30
+ test_chars.push(character);
31
+ test_indices.push(index);
32
+ iteration_count++;
33
+ });
34
+
35
+ expect(test_chars[0]).toEqual('1');
36
+ expect(test_chars[1]).toEqual('2');
37
+ expect(test_chars[2]).toEqual('3');
38
+
39
+ expect(test_indices[0]).toEqual(0);
40
+ expect(test_indices[1]).toEqual(1);
41
+ expect(test_indices[2]).toEqual(2);
42
+
43
+ expect(iteration_count).toEqual(3);
44
+ });
45
+
46
+ it("should capitalize a String with capitalize", function() {
47
+ expect('hello world'.capitalize()).toEqual('Hello world');
48
+ });
49
+
50
+ it("should reverse a string with reverse", function() {
51
+ expect('hello world'.reverse()).toEqual('dlrow olleh');
52
+ expect('satan oscillate my metallic sonatas'.reverse()).toEqual('satanos cillatem ym etallicso natas');
53
+ });
54
+
55
+ it("should convert to a number", function() {
56
+ var whole_number = '32',
57
+ decimal = '0.08',
58
+ negative_number = '-32',
59
+ negative_float = '-0.08';
60
+
61
+ expect(whole_number.to_n()).toBe(32);
62
+ expect(decimal.to_n()).toBe(0.08);
63
+ expect(negative_number.to_n()).toBe(-32);
64
+ expect(negative_float.to_n()).toBe(-0.08);
65
+ });
66
+
67
+ it("should pluck all instances of a sup-string within a string", function() {
68
+ expect('one, two, three'.pluck(',')).toEqual('one two three');
69
+ });
70
+
71
+ it("should compress a string to single spaces", function() {
72
+ var hard_space = 'one&nbsp;two&nbsp;&nbsp;three&nbsp;&nbsp;&nbsp;four&nbsp;&nbsp;&nbsp;&nbsp;five&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;six',
73
+ soft_space = 'one two three four five six',
74
+ mixed_space = 'one two &nbsp; three &nbsp;&nbsp;four &nbsp;&nbsp;&nbsp;five &nbsp;&nbsp;&nbsp;&nbsp;six';
75
+
76
+ expect(hard_space.single_space()).toBe('one two three four five six');
77
+ expect(soft_space.single_space()).toBe('one two three four five six');
78
+ expect(mixed_space.single_space()).toBe('one two three four five six');
79
+ });
80
+
81
+ it("should compress a string, removing all whitespace", function() {
82
+ var string = "satan\n\t oscillate\n\t my\n\t metallic\n sonatas";
83
+ expect(string.compress()).toBe('satanoscillatemymetallicsonatas');
84
+ });
85
+ });
@@ -0,0 +1,190 @@
1
+ jasmine.TrivialReporter = function(doc) {
2
+ this.document = doc || document;
3
+ this.suiteDivs = {};
4
+ this.logRunningSpecs = false;
5
+ };
6
+
7
+ jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
8
+ var el = document.createElement(type);
9
+
10
+ for (var i = 2; i < arguments.length; i++) {
11
+ var child = arguments[i];
12
+
13
+ if (typeof child === 'string') {
14
+ el.appendChild(document.createTextNode(child));
15
+ } else {
16
+ if (child) { el.appendChild(child); }
17
+ }
18
+ }
19
+
20
+ for (var attr in attrs) {
21
+ if (attr == "className") {
22
+ el[attr] = attrs[attr];
23
+ } else {
24
+ el.setAttribute(attr, attrs[attr]);
25
+ }
26
+ }
27
+
28
+ return el;
29
+ };
30
+
31
+ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
32
+ var showPassed, showSkipped;
33
+
34
+ this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
35
+ this.createDom('div', { className: 'banner' },
36
+ this.createDom('div', { className: 'logo' },
37
+ this.createDom('span', { className: 'title' }, "Jasmine"),
38
+ this.createDom('span', { className: 'version' }, runner.env.versionString())),
39
+ this.createDom('div', { className: 'options' },
40
+ "Show ",
41
+ showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
42
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
43
+ showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
44
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
45
+ )
46
+ ),
47
+
48
+ this.runnerDiv = this.createDom('div', { className: 'runner running' },
49
+ this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
50
+ this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
51
+ this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
52
+ );
53
+
54
+ this.document.body.appendChild(this.outerDiv);
55
+
56
+ var suites = runner.suites();
57
+ for (var i = 0; i < suites.length; i++) {
58
+ var suite = suites[i];
59
+ var suiteDiv = this.createDom('div', { className: 'suite' },
60
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
61
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
62
+ this.suiteDivs[suite.id] = suiteDiv;
63
+ var parentDiv = this.outerDiv;
64
+ if (suite.parentSuite) {
65
+ parentDiv = this.suiteDivs[suite.parentSuite.id];
66
+ }
67
+ parentDiv.appendChild(suiteDiv);
68
+ }
69
+
70
+ this.startedAt = new Date();
71
+
72
+ var self = this;
73
+ showPassed.onclick = function(evt) {
74
+ if (showPassed.checked) {
75
+ self.outerDiv.className += ' show-passed';
76
+ } else {
77
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
78
+ }
79
+ };
80
+
81
+ showSkipped.onclick = function(evt) {
82
+ if (showSkipped.checked) {
83
+ self.outerDiv.className += ' show-skipped';
84
+ } else {
85
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
86
+ }
87
+ };
88
+ };
89
+
90
+ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
91
+ var results = runner.results();
92
+ var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
93
+ this.runnerDiv.setAttribute("class", className);
94
+ //do it twice for IE
95
+ this.runnerDiv.setAttribute("className", className);
96
+ var specs = runner.specs();
97
+ var specCount = 0;
98
+ for (var i = 0; i < specs.length; i++) {
99
+ if (this.specFilter(specs[i])) {
100
+ specCount++;
101
+ }
102
+ }
103
+ var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
104
+ message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
105
+ this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
106
+
107
+ this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
108
+ };
109
+
110
+ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
111
+ var results = suite.results();
112
+ var status = results.passed() ? 'passed' : 'failed';
113
+ if (results.totalCount === 0) { // todo: change this to check results.skipped
114
+ status = 'skipped';
115
+ }
116
+ this.suiteDivs[suite.id].className += " " + status;
117
+ };
118
+
119
+ jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
120
+ if (this.logRunningSpecs) {
121
+ this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
122
+ }
123
+ };
124
+
125
+ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
126
+ var results = spec.results();
127
+ var status = results.passed() ? 'passed' : 'failed';
128
+ if (results.skipped) {
129
+ status = 'skipped';
130
+ }
131
+ var specDiv = this.createDom('div', { className: 'spec ' + status },
132
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
133
+ this.createDom('a', {
134
+ className: 'description',
135
+ href: '?spec=' + encodeURIComponent(spec.getFullName()),
136
+ title: spec.getFullName()
137
+ }, spec.description));
138
+
139
+
140
+ var resultItems = results.getItems();
141
+ var messagesDiv = this.createDom('div', { className: 'messages' });
142
+ for (var i = 0; i < resultItems.length; i++) {
143
+ var result = resultItems[i];
144
+
145
+ if (result.type == 'log') {
146
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
147
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
148
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
149
+
150
+ if (result.trace.stack) {
151
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
152
+ }
153
+ }
154
+ }
155
+
156
+ if (messagesDiv.childNodes.length > 0) {
157
+ specDiv.appendChild(messagesDiv);
158
+ }
159
+
160
+ this.suiteDivs[spec.suite.id].appendChild(specDiv);
161
+ };
162
+
163
+ jasmine.TrivialReporter.prototype.log = function() {
164
+ var console = jasmine.getGlobal().console;
165
+ if (console && console.log) {
166
+ if (console.log.apply) {
167
+ console.log.apply(console, arguments);
168
+ } else {
169
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
170
+ }
171
+ }
172
+ };
173
+
174
+ jasmine.TrivialReporter.prototype.getLocation = function() {
175
+ return this.document.location;
176
+ };
177
+
178
+ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
179
+ var paramMap = {};
180
+ var params = this.getLocation().search.substring(1).split('&');
181
+ for (var i = 0; i < params.length; i++) {
182
+ var p = params[i].split('=');
183
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
184
+ }
185
+
186
+ if (!paramMap.spec) {
187
+ return true;
188
+ }
189
+ return spec.getFullName().indexOf(paramMap.spec) === 0;
190
+ };