scratch – Blame information for rev 133

Subversion Repositories:
Rev:
Rev Author Line No. Line
75 office 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  
11 (function() {
12  
13 /**
14 * ## Require & Instantiate
15 *
16 * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
17 */
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 */
23 jasmineRequire.html(jasmine);
24  
25 /**
26 * Create the Jasmine environment. This is used to run all specs in a project.
27 */
28 var env = jasmine.getEnv();
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 */
35 var jasmineInterface = {
36 describe: function(description, specDefinitions) {
37 return env.describe(description, specDefinitions);
38 },
39  
40 xdescribe: function(description, specDefinitions) {
41 return env.xdescribe(description, specDefinitions);
42 },
43  
44 it: function(desc, func) {
45 return env.it(desc, func);
46 },
47  
48 xit: function(desc, func) {
49 return env.xit(desc, func);
50 },
51  
52 beforeEach: function(beforeEachFunction) {
53 return env.beforeEach(beforeEachFunction);
54 },
55  
56 afterEach: function(afterEachFunction) {
57 return env.afterEach(afterEachFunction);
58 },
59  
60 expect: function(actual) {
61 return env.expect(actual);
62 },
63  
64 pending: function() {
65 return env.pending();
66 },
67  
68 spyOn: function(obj, methodName) {
69 return env.spyOn(obj, methodName);
70 },
71  
72 jsApiReporter: new jasmine.JsApiReporter({
73 timer: new jasmine.Timer()
74 })
75 };
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 */
80 if (typeof window == "undefined" && typeof exports == "object") {
81 extend(exports, jasmineInterface);
82 } else {
83 extend(window, jasmineInterface);
84 }
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  
113 var queryString = new jasmine.QueryString({
114 getWindowLocation: function() { return window.location; }
115 });
116  
117 var catchingExceptions = queryString.getParam("catch");
118 env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
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 */
124 var htmlReporter = new jasmine.HtmlReporter({
125 env: env,
126 onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
127 getContainer: function() { return document.body; },
128 createElement: function() { return document.createElement.apply(document, arguments); },
129 createTextNode: function() { return document.createTextNode.apply(document, arguments); },
130 timer: new jasmine.Timer()
131 });
132  
133 /**
134 * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
135 */
136 env.addReporter(jasmineInterface.jsApiReporter);
137 env.addReporter(htmlReporter);
138  
139 /**
140 * Filter which specs will be run by matching the start of the full name against the `spec` query param.
141 */
142 var specFilter = new jasmine.HtmlSpecFilter({
143 filterString: function() { return queryString.getParam("spec"); }
144 });
145  
146 env.specFilter = function(spec) {
147 return specFilter.matches(spec.getFullName());
148 };
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 */
163 var currentWindowOnload = window.onload;
164  
165 window.onload = function() {
166 if (currentWindowOnload) {
167 currentWindowOnload();
168 }
169 htmlReporter.initialize();
170 env.execute();
171 };
172  
173 /**
174 * Helper function for readability above.
175 */
176 function extend(destination, source) {
177 for (var property in source) destination[property] = source[property];
178 return destination;
179 }
180  
181 }());