jasmine-core 2.0.0.rc3 → 2.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/lib/console/console.js +160 -0
  2. data/lib/jasmine-core/boot.js +84 -8
  3. data/lib/jasmine-core/boot/boot.js +84 -8
  4. data/lib/jasmine-core/jasmine-html.js +6 -3
  5. data/lib/jasmine-core/jasmine.js +236 -260
  6. data/lib/jasmine-core/spec/core/AnySpec.js +1 -1
  7. data/lib/jasmine-core/spec/core/ClockSpec.js +0 -20
  8. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +149 -96
  9. data/lib/jasmine-core/spec/core/EnvSpec.js +7 -39
  10. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +13 -19
  11. data/lib/jasmine-core/spec/core/ExpectationSpec.js +74 -1
  12. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +0 -1
  13. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +1 -1
  14. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +28 -20
  15. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +1 -1
  16. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +0 -1
  17. data/lib/jasmine-core/spec/core/SpecSpec.js +2 -11
  18. data/lib/jasmine-core/spec/core/SuiteSpec.js +2 -50
  19. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +13 -1
  20. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +4 -4
  21. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +3 -2
  22. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +1 -1
  23. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +0 -1
  24. data/lib/jasmine-core/spec/html/QueryStringSpec.js +1 -1
  25. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +1 -1
  26. data/lib/jasmine-core/spec/node_suite.js +13 -11
  27. data/lib/jasmine-core/spec/support/dev_boot.js +17 -6
  28. data/lib/jasmine-core/version.rb +1 -1
  29. metadata +41 -13
  30. checksums.yaml +0 -7
@@ -0,0 +1,160 @@
1
+ /*
2
+ Copyright (c) 2008-2013 Pivotal Labs
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ function getJasmineRequireObj() {
24
+ if (typeof module !== "undefined" && module.exports) {
25
+ return exports;
26
+ } else {
27
+ window.jasmineRequire = window.jasmineRequire || {};
28
+ return window.jasmineRequire;
29
+ }
30
+ }
31
+
32
+ getJasmineRequireObj().console = function(jRequire, j$) {
33
+ j$.ConsoleReporter = jRequire.ConsoleReporter();
34
+ };
35
+
36
+ getJasmineRequireObj().ConsoleReporter = function() {
37
+
38
+ var noopTimer = {
39
+ start: function(){},
40
+ elapsed: function(){ return 0; }
41
+ };
42
+
43
+ function ConsoleReporter(options) {
44
+ var print = options.print,
45
+ showColors = options.showColors || false,
46
+ onComplete = options.onComplete || function() {},
47
+ timer = options.timer || noopTimer,
48
+ specCount,
49
+ failureCount,
50
+ failedSpecs = [],
51
+ pendingCount,
52
+ ansi = {
53
+ green: '\033[32m',
54
+ red: '\033[31m',
55
+ yellow: '\033[33m',
56
+ none: '\033[0m'
57
+ };
58
+
59
+ this.jasmineStarted = function() {
60
+ specCount = 0;
61
+ failureCount = 0;
62
+ pendingCount = 0;
63
+ print("Started");
64
+ printNewline();
65
+ timer.start();
66
+ };
67
+
68
+ this.jasmineDone = function() {
69
+ printNewline();
70
+ for (var i = 0; i < failedSpecs.length; i++) {
71
+ specFailureDetails(failedSpecs[i]);
72
+ }
73
+
74
+ printNewline();
75
+ var specCounts = specCount + " " + plural("spec", specCount) + ", " +
76
+ failureCount + " " + plural("failure", failureCount);
77
+
78
+ if (pendingCount) {
79
+ specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount);
80
+ }
81
+
82
+ print(specCounts);
83
+
84
+ printNewline();
85
+ var seconds = timer.elapsed() / 1000;
86
+ print("Finished in " + seconds + " " + plural("second", seconds));
87
+
88
+ printNewline();
89
+
90
+ onComplete(failureCount === 0);
91
+ };
92
+
93
+ this.specDone = function(result) {
94
+ specCount++;
95
+
96
+ if (result.status == "pending") {
97
+ pendingCount++;
98
+ print(colored("yellow", "*"));
99
+ return;
100
+ }
101
+
102
+ if (result.status == "passed") {
103
+ print(colored("green", '.'));
104
+ return;
105
+ }
106
+
107
+ if (result.status == "failed") {
108
+ failureCount++;
109
+ failedSpecs.push(result);
110
+ print(colored("red", 'F'));
111
+ }
112
+ };
113
+
114
+ return this;
115
+
116
+ function printNewline() {
117
+ print("\n");
118
+ }
119
+
120
+ function colored(color, str) {
121
+ return showColors ? (ansi[color] + str + ansi.none) : str;
122
+ }
123
+
124
+ function plural(str, count) {
125
+ return count == 1 ? str : str + "s";
126
+ }
127
+
128
+ function repeat(thing, times) {
129
+ var arr = [];
130
+ for (var i = 0; i < times; i++) {
131
+ arr.push(thing);
132
+ }
133
+ return arr;
134
+ }
135
+
136
+ function indent(str, spaces) {
137
+ var lines = (str || '').split("\n");
138
+ var newArr = [];
139
+ for (var i = 0; i < lines.length; i++) {
140
+ newArr.push(repeat(" ", spaces).join("") + lines[i]);
141
+ }
142
+ return newArr.join("\n");
143
+ }
144
+
145
+ function specFailureDetails(result) {
146
+ printNewline();
147
+ print(result.fullName);
148
+
149
+ for (var i = 0; i < result.failedExpectations.length; i++) {
150
+ var failedExpectation = result.failedExpectations[i];
151
+ printNewline();
152
+ print(indent(failedExpectation.stack, 2));
153
+ }
154
+
155
+ printNewline();
156
+ }
157
+ }
158
+
159
+ return ConsoleReporter;
160
+ };
@@ -20,13 +20,40 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
20
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
- // Jasmine boot.js for browser runners - exposes external/global interface, builds the Jasmine environment and executes it.
23
+ /**
24
+ Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
25
+
26
+ If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
27
+
28
+ The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
29
+
30
+ [jasmine-gem]: http://github.com/pivotal/jasmine-gem
31
+ */
32
+
24
33
  (function() {
34
+
35
+ /**
36
+ * ## Require &amp; Instantiate
37
+ *
38
+ * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
39
+ */
25
40
  window.jasmine = jasmineRequire.core(jasmineRequire);
41
+
42
+ /**
43
+ * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
44
+ */
26
45
  jasmineRequire.html(jasmine);
27
46
 
47
+ /**
48
+ * Create the Jasmine environment. This is used to run all specs in a project.
49
+ */
28
50
  var env = jasmine.getEnv();
29
51
 
52
+ /**
53
+ * ## The Global Interface
54
+ *
55
+ * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
56
+ */
30
57
  var jasmineInterface = {
31
58
  describe: function(description, specDefinitions) {
32
59
  return env.describe(description, specDefinitions);
@@ -60,37 +87,64 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60
87
  return env.pending();
61
88
  },
62
89
 
63
- addMatchers: function(matchers) {
64
- return env.addMatchers(matchers);
65
- },
66
-
67
90
  spyOn: function(obj, methodName) {
68
91
  return env.spyOn(obj, methodName);
69
92
  },
70
93
 
71
- clock: env.clock,
72
94
  jsApiReporter: new jasmine.JsApiReporter({
73
95
  timer: new jasmine.Timer()
74
96
  })
75
97
  };
76
98
 
99
+ /**
100
+ * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
101
+ */
77
102
  if (typeof window == "undefined" && typeof exports == "object") {
78
103
  extend(exports, jasmineInterface);
79
104
  } else {
80
105
  extend(window, jasmineInterface);
81
106
  }
82
107
 
108
+ /**
109
+ * Expose the interface for adding custom equality testers.
110
+ */
111
+ jasmine.addCustomEqualityTester = function(tester) {
112
+ env.addCustomEqualityTester(tester);
113
+ };
114
+
115
+ /**
116
+ * Expose the interface for adding custom expectation matchers
117
+ */
118
+ jasmine.addMatchers = function(matchers) {
119
+ return env.addMatchers(matchers);
120
+ };
121
+
122
+ /**
123
+ * Expose the mock interface for the JavaScript timeout functions
124
+ */
125
+ jasmine.clock = function() {
126
+ return env.clock;
127
+ };
128
+
129
+ /**
130
+ * ## Runner Parameters
131
+ *
132
+ * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
133
+ */
134
+
83
135
  var queryString = new jasmine.QueryString({
84
136
  getWindowLocation: function() { return window.location; }
85
137
  });
86
138
 
87
- // TODO: move all of catching to raise so we don't break our brains
88
139
  var catchingExceptions = queryString.getParam("catch");
89
140
  env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
90
141
 
142
+ /**
143
+ * ## Reporters
144
+ * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
145
+ */
91
146
  var htmlReporter = new jasmine.HtmlReporter({
92
147
  env: env,
93
- queryString: queryString,
94
148
  onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
95
149
  getContainer: function() { return document.body; },
96
150
  createElement: function() { return document.createElement.apply(document, arguments); },
@@ -98,9 +152,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
98
152
  timer: new jasmine.Timer()
99
153
  });
100
154
 
155
+ /**
156
+ * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
157
+ */
101
158
  env.addReporter(jasmineInterface.jsApiReporter);
102
159
  env.addReporter(htmlReporter);
103
160
 
161
+ /**
162
+ * Filter which specs will be run by matching the start of the full name against the `spec` query param.
163
+ */
104
164
  var specFilter = new jasmine.HtmlSpecFilter({
105
165
  filterString: function() { return queryString.getParam("spec"); }
106
166
  });
@@ -109,6 +169,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
109
169
  return specFilter.matches(spec.getFullName());
110
170
  };
111
171
 
172
+ /**
173
+ * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
174
+ */
175
+ window.setTimeout = window.setTimeout;
176
+ window.setInterval = window.setInterval;
177
+ window.clearTimeout = window.clearTimeout;
178
+ window.clearInterval = window.clearInterval;
179
+
180
+ /**
181
+ * ## Execution
182
+ *
183
+ * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
184
+ */
112
185
  var currentWindowOnload = window.onload;
113
186
 
114
187
  window.onload = function() {
@@ -119,6 +192,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
119
192
  env.execute();
120
193
  };
121
194
 
195
+ /**
196
+ * Helper function for readability above.
197
+ */
122
198
  function extend(destination, source) {
123
199
  for (var property in source) destination[property] = source[property];
124
200
  return destination;
@@ -1,10 +1,37 @@
1
- // Jasmine boot.js for browser runners - exposes external/global interface, builds the Jasmine environment and executes it.
1
+ /**
2
+ Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
3
+
4
+ If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
5
+
6
+ The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
7
+
8
+ [jasmine-gem]: http://github.com/pivotal/jasmine-gem
9
+ */
10
+
2
11
  (function() {
12
+
13
+ /**
14
+ * ## Require &amp; Instantiate
15
+ *
16
+ * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
17
+ */
3
18
  window.jasmine = jasmineRequire.core(jasmineRequire);
19
+
20
+ /**
21
+ * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
22
+ */
4
23
  jasmineRequire.html(jasmine);
5
24
 
25
+ /**
26
+ * Create the Jasmine environment. This is used to run all specs in a project.
27
+ */
6
28
  var env = jasmine.getEnv();
7
29
 
30
+ /**
31
+ * ## The Global Interface
32
+ *
33
+ * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
34
+ */
8
35
  var jasmineInterface = {
9
36
  describe: function(description, specDefinitions) {
10
37
  return env.describe(description, specDefinitions);
@@ -38,37 +65,64 @@
38
65
  return env.pending();
39
66
  },
40
67
 
41
- addMatchers: function(matchers) {
42
- return env.addMatchers(matchers);
43
- },
44
-
45
68
  spyOn: function(obj, methodName) {
46
69
  return env.spyOn(obj, methodName);
47
70
  },
48
71
 
49
- clock: env.clock,
50
72
  jsApiReporter: new jasmine.JsApiReporter({
51
73
  timer: new jasmine.Timer()
52
74
  })
53
75
  };
54
76
 
77
+ /**
78
+ * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
79
+ */
55
80
  if (typeof window == "undefined" && typeof exports == "object") {
56
81
  extend(exports, jasmineInterface);
57
82
  } else {
58
83
  extend(window, jasmineInterface);
59
84
  }
60
85
 
86
+ /**
87
+ * Expose the interface for adding custom equality testers.
88
+ */
89
+ jasmine.addCustomEqualityTester = function(tester) {
90
+ env.addCustomEqualityTester(tester);
91
+ };
92
+
93
+ /**
94
+ * Expose the interface for adding custom expectation matchers
95
+ */
96
+ jasmine.addMatchers = function(matchers) {
97
+ return env.addMatchers(matchers);
98
+ };
99
+
100
+ /**
101
+ * Expose the mock interface for the JavaScript timeout functions
102
+ */
103
+ jasmine.clock = function() {
104
+ return env.clock;
105
+ };
106
+
107
+ /**
108
+ * ## Runner Parameters
109
+ *
110
+ * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
111
+ */
112
+
61
113
  var queryString = new jasmine.QueryString({
62
114
  getWindowLocation: function() { return window.location; }
63
115
  });
64
116
 
65
- // TODO: move all of catching to raise so we don't break our brains
66
117
  var catchingExceptions = queryString.getParam("catch");
67
118
  env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
68
119
 
120
+ /**
121
+ * ## Reporters
122
+ * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
123
+ */
69
124
  var htmlReporter = new jasmine.HtmlReporter({
70
125
  env: env,
71
- queryString: queryString,
72
126
  onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
73
127
  getContainer: function() { return document.body; },
74
128
  createElement: function() { return document.createElement.apply(document, arguments); },
@@ -76,9 +130,15 @@
76
130
  timer: new jasmine.Timer()
77
131
  });
78
132
 
133
+ /**
134
+ * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
135
+ */
79
136
  env.addReporter(jasmineInterface.jsApiReporter);
80
137
  env.addReporter(htmlReporter);
81
138
 
139
+ /**
140
+ * Filter which specs will be run by matching the start of the full name against the `spec` query param.
141
+ */
82
142
  var specFilter = new jasmine.HtmlSpecFilter({
83
143
  filterString: function() { return queryString.getParam("spec"); }
84
144
  });
@@ -87,6 +147,19 @@
87
147
  return specFilter.matches(spec.getFullName());
88
148
  };
89
149
 
150
+ /**
151
+ * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
152
+ */
153
+ window.setTimeout = window.setTimeout;
154
+ window.setInterval = window.setInterval;
155
+ window.clearTimeout = window.clearTimeout;
156
+ window.clearInterval = window.clearInterval;
157
+
158
+ /**
159
+ * ## Execution
160
+ *
161
+ * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
162
+ */
90
163
  var currentWindowOnload = window.onload;
91
164
 
92
165
  window.onload = function() {
@@ -97,6 +170,9 @@
97
170
  env.execute();
98
171
  };
99
172
 
173
+ /**
174
+ * Helper function for readability above.
175
+ */
100
176
  function extend(destination, source) {
101
177
  for (var property in source) destination[property] = source[property];
102
178
  return destination;