├── .gitignore ├── README.md ├── SpecRunner.html ├── lib ├── jasmine-2.0.1 │ ├── MIT.LICENSE │ ├── boot.js │ ├── console.js │ ├── jasmine-html.js │ ├── jasmine.css │ ├── jasmine.js │ └── jasmine_favicon.png ├── jasmine-jquery-2.0.5 │ └── jasmine-jquery.js └── jquery-2.1.1 │ └── jquery-2.1.1.js ├── spec ├── gilded_rose_spec.js └── spec_helper.js └── src └── gilded_rose.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *~ 3 | *.bak 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | If you want to get cracking on the JavaScript source then do this: 2 | 3 | git clone git@github.com:guyroyse/gilded-rose-javascript.git 4 | 5 | Hi and welcome to team Gilded Rose. 6 | 7 | As you know, we are a small inn with a prime location in a prominent city ran 8 | by a friendly innkeeper named Allison. We also buy and sell only the finest 9 | goods. Unfortunately, our goods are constantly degrading in quality as they 10 | approach their sell by date. 11 | 12 | We have a system in place that updates our inventory for us. It was developed 13 | by a no-nonsense type named Leeroy, who has moved on to new adventures. Your 14 | task is to add the new feature to our system so that we can begin selling a 15 | new category of items. 16 | 17 | First an introduction to our system: 18 | 19 | - All items have a *sell_in* value which denotes the number of days we have to 20 | sell the item 21 | 22 | - All items have a *quality* value which denotes how valuable the item is 23 | 24 | - At the end of each day our system lowers both values for every item 25 | 26 | Pretty simple, right? Well this is where it gets interesting: 27 | 28 | - Once the *sell_in* days is less then zero, *quality* degrades twice as fast 29 | 30 | - The *quality* of an item is never negative 31 | 32 | - "Aged Brie" actually increases in *quality* the older it gets 33 | 34 | - The *quality* of an item is never more than 50 35 | 36 | - "Sulfuras", being a legendary item, never has to be sold nor does it 37 | decrease in *quality* 38 | 39 | - "Backstage passes", like aged brie, increases in *quality* as it's *sell_in* 40 | value decreases; *quality* increases by 2 when there are 10 days or less 41 | and by 3 when there are 5 days or less but *quality* drops to 0 after the 42 | concert 43 | 44 | We have recently signed a supplier of conjured items. This requires an update 45 | to our system: 46 | 47 | - "Conjured" items degrade in *quality* twice as fast as normal items 48 | 49 | Feel free to make any changes to the *update_quality* method and add any new 50 | code as long as everything still works correctly. However, do not alter the 51 | *Item* class or *items* property as those belong to the goblin in the corner 52 | who will insta-rage and one-shot you as he doesn't believe in shared code 53 | ownership. 54 | 55 | Just for clarification, an item can never have its *quality* increase above 50, 56 | however "Sulfuras" is a legendary item and as such its *quality* is 80 and it 57 | never alters. 58 | 59 | Sources: 60 | 61 | 62 | -------------------------------------------------------------------------------- /SpecRunner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Jasmine Spec Runner v2.0.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2014 Pivotal Labs 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/boot.js: -------------------------------------------------------------------------------- 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 | }()); 182 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/console.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 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: '\x1B[32m', 54 | red: '\x1B[31m', 55 | yellow: '\x1B[33m', 56 | none: '\x1B[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 | if(specCount > 0) { 75 | printNewline(); 76 | 77 | var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' + 78 | failureCount + ' ' + plural('failure', failureCount); 79 | 80 | if (pendingCount) { 81 | specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount); 82 | } 83 | 84 | print(specCounts); 85 | } else { 86 | print('No specs found'); 87 | } 88 | 89 | printNewline(); 90 | var seconds = timer.elapsed() / 1000; 91 | print('Finished in ' + seconds + ' ' + plural('second', seconds)); 92 | 93 | printNewline(); 94 | 95 | onComplete(failureCount === 0); 96 | }; 97 | 98 | this.specDone = function(result) { 99 | specCount++; 100 | 101 | if (result.status == 'pending') { 102 | pendingCount++; 103 | print(colored('yellow', '*')); 104 | return; 105 | } 106 | 107 | if (result.status == 'passed') { 108 | print(colored('green', '.')); 109 | return; 110 | } 111 | 112 | if (result.status == 'failed') { 113 | failureCount++; 114 | failedSpecs.push(result); 115 | print(colored('red', 'F')); 116 | } 117 | }; 118 | 119 | return this; 120 | 121 | function printNewline() { 122 | print('\n'); 123 | } 124 | 125 | function colored(color, str) { 126 | return showColors ? (ansi[color] + str + ansi.none) : str; 127 | } 128 | 129 | function plural(str, count) { 130 | return count == 1 ? str : str + 's'; 131 | } 132 | 133 | function repeat(thing, times) { 134 | var arr = []; 135 | for (var i = 0; i < times; i++) { 136 | arr.push(thing); 137 | } 138 | return arr; 139 | } 140 | 141 | function indent(str, spaces) { 142 | var lines = (str || '').split('\n'); 143 | var newArr = []; 144 | for (var i = 0; i < lines.length; i++) { 145 | newArr.push(repeat(' ', spaces).join('') + lines[i]); 146 | } 147 | return newArr.join('\n'); 148 | } 149 | 150 | function specFailureDetails(result) { 151 | printNewline(); 152 | print(result.fullName); 153 | 154 | for (var i = 0; i < result.failedExpectations.length; i++) { 155 | var failedExpectation = result.failedExpectations[i]; 156 | printNewline(); 157 | print(indent(failedExpectation.stack, 2)); 158 | } 159 | 160 | printNewline(); 161 | } 162 | } 163 | 164 | return ConsoleReporter; 165 | }; 166 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/jasmine-html.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 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 | jasmineRequire.html = function(j$) { 24 | j$.ResultsNode = jasmineRequire.ResultsNode(); 25 | j$.HtmlReporter = jasmineRequire.HtmlReporter(j$); 26 | j$.QueryString = jasmineRequire.QueryString(); 27 | j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter(); 28 | }; 29 | 30 | jasmineRequire.HtmlReporter = function(j$) { 31 | 32 | var noopTimer = { 33 | start: function() {}, 34 | elapsed: function() { return 0; } 35 | }; 36 | 37 | function HtmlReporter(options) { 38 | var env = options.env || {}, 39 | getContainer = options.getContainer, 40 | createElement = options.createElement, 41 | createTextNode = options.createTextNode, 42 | onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, 43 | timer = options.timer || noopTimer, 44 | results = [], 45 | specsExecuted = 0, 46 | failureCount = 0, 47 | pendingSpecCount = 0, 48 | htmlReporterMain, 49 | symbols; 50 | 51 | this.initialize = function() { 52 | clearPrior(); 53 | htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'}, 54 | createDom('div', {className: 'banner'}, 55 | createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}), 56 | createDom('span', {className: 'version'}, j$.version) 57 | ), 58 | createDom('ul', {className: 'symbol-summary'}), 59 | createDom('div', {className: 'alert'}), 60 | createDom('div', {className: 'results'}, 61 | createDom('div', {className: 'failures'}) 62 | ) 63 | ); 64 | getContainer().appendChild(htmlReporterMain); 65 | 66 | symbols = find('.symbol-summary'); 67 | }; 68 | 69 | var totalSpecsDefined; 70 | this.jasmineStarted = function(options) { 71 | totalSpecsDefined = options.totalSpecsDefined || 0; 72 | timer.start(); 73 | }; 74 | 75 | var summary = createDom('div', {className: 'summary'}); 76 | 77 | var topResults = new j$.ResultsNode({}, '', null), 78 | currentParent = topResults; 79 | 80 | this.suiteStarted = function(result) { 81 | currentParent.addChild(result, 'suite'); 82 | currentParent = currentParent.last(); 83 | }; 84 | 85 | this.suiteDone = function(result) { 86 | if (currentParent == topResults) { 87 | return; 88 | } 89 | 90 | currentParent = currentParent.parent; 91 | }; 92 | 93 | this.specStarted = function(result) { 94 | currentParent.addChild(result, 'spec'); 95 | }; 96 | 97 | var failures = []; 98 | this.specDone = function(result) { 99 | if(noExpectations(result) && console && console.error) { 100 | console.error('Spec \'' + result.fullName + '\' has no expectations.'); 101 | } 102 | 103 | if (result.status != 'disabled') { 104 | specsExecuted++; 105 | } 106 | 107 | symbols.appendChild(createDom('li', { 108 | className: noExpectations(result) ? 'empty' : result.status, 109 | id: 'spec_' + result.id, 110 | title: result.fullName 111 | } 112 | )); 113 | 114 | if (result.status == 'failed') { 115 | failureCount++; 116 | 117 | var failure = 118 | createDom('div', {className: 'spec-detail failed'}, 119 | createDom('div', {className: 'description'}, 120 | createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName) 121 | ), 122 | createDom('div', {className: 'messages'}) 123 | ); 124 | var messages = failure.childNodes[1]; 125 | 126 | for (var i = 0; i < result.failedExpectations.length; i++) { 127 | var expectation = result.failedExpectations[i]; 128 | messages.appendChild(createDom('div', {className: 'result-message'}, expectation.message)); 129 | messages.appendChild(createDom('div', {className: 'stack-trace'}, expectation.stack)); 130 | } 131 | 132 | failures.push(failure); 133 | } 134 | 135 | if (result.status == 'pending') { 136 | pendingSpecCount++; 137 | } 138 | }; 139 | 140 | this.jasmineDone = function() { 141 | var banner = find('.banner'); 142 | banner.appendChild(createDom('span', {className: 'duration'}, 'finished in ' + timer.elapsed() / 1000 + 's')); 143 | 144 | var alert = find('.alert'); 145 | 146 | alert.appendChild(createDom('span', { className: 'exceptions' }, 147 | createDom('label', { className: 'label', 'for': 'raise-exceptions' }, 'raise exceptions'), 148 | createDom('input', { 149 | className: 'raise', 150 | id: 'raise-exceptions', 151 | type: 'checkbox' 152 | }) 153 | )); 154 | var checkbox = find('#raise-exceptions'); 155 | 156 | checkbox.checked = !env.catchingExceptions(); 157 | checkbox.onclick = onRaiseExceptionsClick; 158 | 159 | if (specsExecuted < totalSpecsDefined) { 160 | var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all'; 161 | alert.appendChild( 162 | createDom('span', {className: 'bar skipped'}, 163 | createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage) 164 | ) 165 | ); 166 | } 167 | var statusBarMessage = ''; 168 | var statusBarClassName = 'bar '; 169 | 170 | if (totalSpecsDefined > 0) { 171 | statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount); 172 | if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); } 173 | statusBarClassName += (failureCount > 0) ? 'failed' : 'passed'; 174 | } else { 175 | statusBarClassName += 'skipped'; 176 | statusBarMessage += 'No specs found'; 177 | } 178 | 179 | alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage)); 180 | 181 | var results = find('.results'); 182 | results.appendChild(summary); 183 | 184 | summaryList(topResults, summary); 185 | 186 | function summaryList(resultsTree, domParent) { 187 | var specListNode; 188 | for (var i = 0; i < resultsTree.children.length; i++) { 189 | var resultNode = resultsTree.children[i]; 190 | if (resultNode.type == 'suite') { 191 | var suiteListNode = createDom('ul', {className: 'suite', id: 'suite-' + resultNode.result.id}, 192 | createDom('li', {className: 'suite-detail'}, 193 | createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description) 194 | ) 195 | ); 196 | 197 | summaryList(resultNode, suiteListNode); 198 | domParent.appendChild(suiteListNode); 199 | } 200 | if (resultNode.type == 'spec') { 201 | if (domParent.getAttribute('class') != 'specs') { 202 | specListNode = createDom('ul', {className: 'specs'}); 203 | domParent.appendChild(specListNode); 204 | } 205 | var specDescription = resultNode.result.description; 206 | if(noExpectations(resultNode.result)) { 207 | specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; 208 | } 209 | specListNode.appendChild( 210 | createDom('li', { 211 | className: resultNode.result.status, 212 | id: 'spec-' + resultNode.result.id 213 | }, 214 | createDom('a', {href: specHref(resultNode.result)}, specDescription) 215 | ) 216 | ); 217 | } 218 | } 219 | } 220 | 221 | if (failures.length) { 222 | alert.appendChild( 223 | createDom('span', {className: 'menu bar spec-list'}, 224 | createDom('span', {}, 'Spec List | '), 225 | createDom('a', {className: 'failures-menu', href: '#'}, 'Failures'))); 226 | alert.appendChild( 227 | createDom('span', {className: 'menu bar failure-list'}, 228 | createDom('a', {className: 'spec-list-menu', href: '#'}, 'Spec List'), 229 | createDom('span', {}, ' | Failures '))); 230 | 231 | find('.failures-menu').onclick = function() { 232 | setMenuModeTo('failure-list'); 233 | }; 234 | find('.spec-list-menu').onclick = function() { 235 | setMenuModeTo('spec-list'); 236 | }; 237 | 238 | setMenuModeTo('failure-list'); 239 | 240 | var failureNode = find('.failures'); 241 | for (var i = 0; i < failures.length; i++) { 242 | failureNode.appendChild(failures[i]); 243 | } 244 | } 245 | }; 246 | 247 | return this; 248 | 249 | function find(selector) { 250 | return getContainer().querySelector('.jasmine_html-reporter ' + selector); 251 | } 252 | 253 | function clearPrior() { 254 | // return the reporter 255 | var oldReporter = find(''); 256 | 257 | if(oldReporter) { 258 | getContainer().removeChild(oldReporter); 259 | } 260 | } 261 | 262 | function createDom(type, attrs, childrenVarArgs) { 263 | var el = createElement(type); 264 | 265 | for (var i = 2; i < arguments.length; i++) { 266 | var child = arguments[i]; 267 | 268 | if (typeof child === 'string') { 269 | el.appendChild(createTextNode(child)); 270 | } else { 271 | if (child) { 272 | el.appendChild(child); 273 | } 274 | } 275 | } 276 | 277 | for (var attr in attrs) { 278 | if (attr == 'className') { 279 | el[attr] = attrs[attr]; 280 | } else { 281 | el.setAttribute(attr, attrs[attr]); 282 | } 283 | } 284 | 285 | return el; 286 | } 287 | 288 | function pluralize(singular, count) { 289 | var word = (count == 1 ? singular : singular + 's'); 290 | 291 | return '' + count + ' ' + word; 292 | } 293 | 294 | function specHref(result) { 295 | return '?spec=' + encodeURIComponent(result.fullName); 296 | } 297 | 298 | function setMenuModeTo(mode) { 299 | htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode); 300 | } 301 | 302 | function noExpectations(result) { 303 | return (result.failedExpectations.length + result.passedExpectations.length) === 0 && 304 | result.status === 'passed'; 305 | } 306 | } 307 | 308 | return HtmlReporter; 309 | }; 310 | 311 | jasmineRequire.HtmlSpecFilter = function() { 312 | function HtmlSpecFilter(options) { 313 | var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); 314 | var filterPattern = new RegExp(filterString); 315 | 316 | this.matches = function(specName) { 317 | return filterPattern.test(specName); 318 | }; 319 | } 320 | 321 | return HtmlSpecFilter; 322 | }; 323 | 324 | jasmineRequire.ResultsNode = function() { 325 | function ResultsNode(result, type, parent) { 326 | this.result = result; 327 | this.type = type; 328 | this.parent = parent; 329 | 330 | this.children = []; 331 | 332 | this.addChild = function(result, type) { 333 | this.children.push(new ResultsNode(result, type, this)); 334 | }; 335 | 336 | this.last = function() { 337 | return this.children[this.children.length - 1]; 338 | }; 339 | } 340 | 341 | return ResultsNode; 342 | }; 343 | 344 | jasmineRequire.QueryString = function() { 345 | function QueryString(options) { 346 | 347 | this.setParam = function(key, value) { 348 | var paramMap = queryStringToParamMap(); 349 | paramMap[key] = value; 350 | options.getWindowLocation().search = toQueryString(paramMap); 351 | }; 352 | 353 | this.getParam = function(key) { 354 | return queryStringToParamMap()[key]; 355 | }; 356 | 357 | return this; 358 | 359 | function toQueryString(paramMap) { 360 | var qStrPairs = []; 361 | for (var prop in paramMap) { 362 | qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])); 363 | } 364 | return '?' + qStrPairs.join('&'); 365 | } 366 | 367 | function queryStringToParamMap() { 368 | var paramStr = options.getWindowLocation().search.substring(1), 369 | params = [], 370 | paramMap = {}; 371 | 372 | if (paramStr.length > 0) { 373 | params = paramStr.split('&'); 374 | for (var i = 0; i < params.length; i++) { 375 | var p = params[i].split('='); 376 | var value = decodeURIComponent(p[1]); 377 | if (value === 'true' || value === 'false') { 378 | value = JSON.parse(value); 379 | } 380 | paramMap[decodeURIComponent(p[0])] = value; 381 | } 382 | } 383 | 384 | return paramMap; 385 | } 386 | 387 | } 388 | 389 | return QueryString; 390 | }; 391 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/jasmine.css: -------------------------------------------------------------------------------- 1 | body { overflow-y: scroll; } 2 | 3 | .jasmine_html-reporter { background-color: #eeeeee; padding: 5px; margin: -8px; font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; } 4 | .jasmine_html-reporter a { text-decoration: none; } 5 | .jasmine_html-reporter a:hover { text-decoration: underline; } 6 | .jasmine_html-reporter p, .jasmine_html-reporter h1, .jasmine_html-reporter h2, .jasmine_html-reporter h3, .jasmine_html-reporter h4, .jasmine_html-reporter h5, .jasmine_html-reporter h6 { margin: 0; line-height: 14px; } 7 | .jasmine_html-reporter .banner, .jasmine_html-reporter .symbol-summary, .jasmine_html-reporter .summary, .jasmine_html-reporter .result-message, .jasmine_html-reporter .spec .description, .jasmine_html-reporter .spec-detail .description, .jasmine_html-reporter .alert .bar, .jasmine_html-reporter .stack-trace { padding-left: 9px; padding-right: 9px; } 8 | .jasmine_html-reporter .banner { position: relative; } 9 | .jasmine_html-reporter .banner .title { background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAZCAMAAACGusnyAAACdlBMVEX/////AP+AgICqVaqAQICZM5mAVYCSSZKAQICOOY6ATYCLRouAQICJO4mSSYCIRIiPQICHPIeOR4CGQ4aMQICGPYaLRoCFQ4WKQICPPYWJRYCOQoSJQICNPoSIRICMQoSHQICHRICKQoOHQICKPoOJO4OJQYOMQICMQ4CIQYKLQICIPoKLQ4CKQICNPoKJQISMQ4KJQoSLQYKJQISLQ4KIQoSKQYKIQICIQISMQoSKQYKLQIOLQoOJQYGLQIOKQIOMQoGKQYOLQYGKQIOLQoGJQYOJQIOKQYGJQIOKQoGKQIGLQIKLQ4KKQoGLQYKJQIGKQYKJQIGKQIKJQoGKQYKLQIGKQYKLQIOJQoKKQoOJQYKKQIOJQoKKQoOKQIOLQoKKQYOLQYKJQIOKQoKKQYKKQoKJQYOKQYKLQIOKQoKLQYOKQYKLQIOJQoGKQYKJQYGJQoGKQYKLQoGLQYGKQoGJQYKKQYGJQIKKQoGJQYKLQIKKQYGLQYKKQYGKQYGKQYKJQYOKQoKJQYOKQYKLQYOLQYOKQYKLQYOKQoKKQYKKQYOKQYOJQYKKQYKLQYKKQIKKQoKKQYKKQYKKQoKJQIKKQYKLQYKKQYKKQIKKQYKKQYKKQYKKQIKKQYKJQYGLQYGKQYKKQYKKQYGKQIKKQYGKQYOJQoKKQYOLQYKKQYOKQoKKQYKKQoKKQYKKQYKJQYKLQYKKQYKKQYKKQYKKQYKKQYK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SIgLz48cGF0aAogICAgICAgICAgICAgZD0ibSA3MTYuMjg5LDM3Ni41OSAzNy42NDA2LDAgMCwxODQuODE2IC0zNy42NDA2LDAgMCwtMTg0LjgxNiB6IgogICAgICAgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIKICAgICAgICAgICAgIGlkPSJwYXRoNTYiCiAgICAgICAgICAgICBzdHlsZT0iZmlsbDojOGE0MTgyO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIiAvPjwvZz48L2c+PC9nPjwvZz48L3N2Zz4=') no-repeat, none; -webkit-background-size: 100%; -moz-background-size: 100%; -o-background-size: 100%; background-size: 100%; display: block; float: left; width: 90px; height: 25px; } 10 | .jasmine_html-reporter .banner .version { margin-left: 14px; position: relative; top: 6px; } 11 | .jasmine_html-reporter .banner .duration { position: absolute; right: 14px; top: 6px; } 12 | .jasmine_html-reporter #jasmine_content { position: fixed; right: 100%; } 13 | .jasmine_html-reporter .version { color: #aaaaaa; } 14 | .jasmine_html-reporter .banner { margin-top: 14px; } 15 | .jasmine_html-reporter .duration { color: #aaaaaa; float: right; } 16 | .jasmine_html-reporter .symbol-summary { overflow: hidden; *zoom: 1; margin: 14px 0; } 17 | .jasmine_html-reporter .symbol-summary li { display: inline-block; height: 8px; width: 14px; font-size: 16px; } 18 | .jasmine_html-reporter .symbol-summary li.passed { font-size: 14px; } 19 | .jasmine_html-reporter .symbol-summary li.passed:before { color: #007069; content: "\02022"; } 20 | .jasmine_html-reporter .symbol-summary li.failed { line-height: 9px; } 21 | .jasmine_html-reporter .symbol-summary li.failed:before { color: #ca3a11; content: "\d7"; font-weight: bold; margin-left: -1px; } 22 | .jasmine_html-reporter .symbol-summary li.disabled { font-size: 14px; } 23 | .jasmine_html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; } 24 | .jasmine_html-reporter .symbol-summary li.pending { line-height: 17px; } 25 | .jasmine_html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; } 26 | .jasmine_html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } 27 | .jasmine_html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } 28 | .jasmine_html-reporter .bar.failed { background-color: #ca3a11; } 29 | .jasmine_html-reporter .bar.passed { background-color: #007069; } 30 | .jasmine_html-reporter .bar.skipped { background-color: #bababa; } 31 | .jasmine_html-reporter .bar.menu { background-color: #fff; color: #aaaaaa; } 32 | .jasmine_html-reporter .bar.menu a { color: #333333; } 33 | .jasmine_html-reporter .bar a { color: white; } 34 | .jasmine_html-reporter.spec-list .bar.menu.failure-list, .jasmine_html-reporter.spec-list .results .failures { display: none; } 35 | .jasmine_html-reporter.failure-list .bar.menu.spec-list, .jasmine_html-reporter.failure-list .summary { display: none; } 36 | .jasmine_html-reporter .running-alert { background-color: #666666; } 37 | .jasmine_html-reporter .results { margin-top: 14px; } 38 | .jasmine_html-reporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; } 39 | .jasmine_html-reporter.showDetails .summaryMenuItem:hover { text-decoration: underline; } 40 | .jasmine_html-reporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; } 41 | .jasmine_html-reporter.showDetails .summary { display: none; } 42 | .jasmine_html-reporter.showDetails #details { display: block; } 43 | .jasmine_html-reporter .summaryMenuItem { font-weight: bold; text-decoration: underline; } 44 | .jasmine_html-reporter .summary { margin-top: 14px; } 45 | .jasmine_html-reporter .summary ul { list-style-type: none; margin-left: 14px; padding-top: 0; padding-left: 0; } 46 | .jasmine_html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; } 47 | .jasmine_html-reporter .summary li.passed a { color: #007069; } 48 | .jasmine_html-reporter .summary li.failed a { color: #ca3a11; } 49 | .jasmine_html-reporter .summary li.empty a { color: #ba9d37; } 50 | .jasmine_html-reporter .summary li.pending a { color: #ba9d37; } 51 | .jasmine_html-reporter .description + .suite { margin-top: 0; } 52 | .jasmine_html-reporter .suite { margin-top: 14px; } 53 | .jasmine_html-reporter .suite a { color: #333333; } 54 | .jasmine_html-reporter .failures .spec-detail { margin-bottom: 28px; } 55 | .jasmine_html-reporter .failures .spec-detail .description { background-color: #ca3a11; } 56 | .jasmine_html-reporter .failures .spec-detail .description a { color: white; } 57 | .jasmine_html-reporter .result-message { padding-top: 14px; color: #333333; white-space: pre; } 58 | .jasmine_html-reporter .result-message span.result { display: block; } 59 | .jasmine_html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; } 60 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/jasmine.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 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().core = function(jRequire) { 33 | var j$ = {}; 34 | 35 | jRequire.base(j$); 36 | j$.util = jRequire.util(); 37 | j$.Any = jRequire.Any(); 38 | j$.CallTracker = jRequire.CallTracker(); 39 | j$.MockDate = jRequire.MockDate(); 40 | j$.Clock = jRequire.Clock(); 41 | j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(); 42 | j$.Env = jRequire.Env(j$); 43 | j$.ExceptionFormatter = jRequire.ExceptionFormatter(); 44 | j$.Expectation = jRequire.Expectation(); 45 | j$.buildExpectationResult = jRequire.buildExpectationResult(); 46 | j$.JsApiReporter = jRequire.JsApiReporter(); 47 | j$.matchersUtil = jRequire.matchersUtil(j$); 48 | j$.ObjectContaining = jRequire.ObjectContaining(j$); 49 | j$.pp = jRequire.pp(j$); 50 | j$.QueueRunner = jRequire.QueueRunner(j$); 51 | j$.ReportDispatcher = jRequire.ReportDispatcher(); 52 | j$.Spec = jRequire.Spec(j$); 53 | j$.SpyStrategy = jRequire.SpyStrategy(); 54 | j$.Suite = jRequire.Suite(); 55 | j$.Timer = jRequire.Timer(); 56 | j$.version = jRequire.version(); 57 | 58 | j$.matchers = jRequire.requireMatchers(jRequire, j$); 59 | 60 | return j$; 61 | }; 62 | 63 | getJasmineRequireObj().requireMatchers = function(jRequire, j$) { 64 | var availableMatchers = [ 65 | 'toBe', 66 | 'toBeCloseTo', 67 | 'toBeDefined', 68 | 'toBeFalsy', 69 | 'toBeGreaterThan', 70 | 'toBeLessThan', 71 | 'toBeNaN', 72 | 'toBeNull', 73 | 'toBeTruthy', 74 | 'toBeUndefined', 75 | 'toContain', 76 | 'toEqual', 77 | 'toHaveBeenCalled', 78 | 'toHaveBeenCalledWith', 79 | 'toMatch', 80 | 'toThrow', 81 | 'toThrowError' 82 | ], 83 | matchers = {}; 84 | 85 | for (var i = 0; i < availableMatchers.length; i++) { 86 | var name = availableMatchers[i]; 87 | matchers[name] = jRequire[name](j$); 88 | } 89 | 90 | return matchers; 91 | }; 92 | 93 | getJasmineRequireObj().base = (function (jasmineGlobal) { 94 | if (typeof module !== 'undefined' && module.exports) { 95 | jasmineGlobal = global; 96 | } 97 | 98 | return function(j$) { 99 | j$.unimplementedMethod_ = function() { 100 | throw new Error('unimplemented method'); 101 | }; 102 | 103 | j$.MAX_PRETTY_PRINT_DEPTH = 40; 104 | j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100; 105 | j$.DEFAULT_TIMEOUT_INTERVAL = 5000; 106 | 107 | j$.getGlobal = function() { 108 | return jasmineGlobal; 109 | }; 110 | 111 | j$.getEnv = function(options) { 112 | var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options); 113 | //jasmine. singletons in here (setTimeout blah blah). 114 | return env; 115 | }; 116 | 117 | j$.isArray_ = function(value) { 118 | return j$.isA_('Array', value); 119 | }; 120 | 121 | j$.isString_ = function(value) { 122 | return j$.isA_('String', value); 123 | }; 124 | 125 | j$.isNumber_ = function(value) { 126 | return j$.isA_('Number', value); 127 | }; 128 | 129 | j$.isA_ = function(typeName, value) { 130 | return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; 131 | }; 132 | 133 | j$.isDomNode = function(obj) { 134 | return obj.nodeType > 0; 135 | }; 136 | 137 | j$.any = function(clazz) { 138 | return new j$.Any(clazz); 139 | }; 140 | 141 | j$.objectContaining = function(sample) { 142 | return new j$.ObjectContaining(sample); 143 | }; 144 | 145 | j$.createSpy = function(name, originalFn) { 146 | 147 | var spyStrategy = new j$.SpyStrategy({ 148 | name: name, 149 | fn: originalFn, 150 | getSpy: function() { return spy; } 151 | }), 152 | callTracker = new j$.CallTracker(), 153 | spy = function() { 154 | callTracker.track({ 155 | object: this, 156 | args: Array.prototype.slice.apply(arguments) 157 | }); 158 | return spyStrategy.exec.apply(this, arguments); 159 | }; 160 | 161 | for (var prop in originalFn) { 162 | if (prop === 'and' || prop === 'calls') { 163 | throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon'); 164 | } 165 | 166 | spy[prop] = originalFn[prop]; 167 | } 168 | 169 | spy.and = spyStrategy; 170 | spy.calls = callTracker; 171 | 172 | return spy; 173 | }; 174 | 175 | j$.isSpy = function(putativeSpy) { 176 | if (!putativeSpy) { 177 | return false; 178 | } 179 | return putativeSpy.and instanceof j$.SpyStrategy && 180 | putativeSpy.calls instanceof j$.CallTracker; 181 | }; 182 | 183 | j$.createSpyObj = function(baseName, methodNames) { 184 | if (!j$.isArray_(methodNames) || methodNames.length === 0) { 185 | throw 'createSpyObj requires a non-empty array of method names to create spies for'; 186 | } 187 | var obj = {}; 188 | for (var i = 0; i < methodNames.length; i++) { 189 | obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]); 190 | } 191 | return obj; 192 | }; 193 | }; 194 | })(this); 195 | 196 | getJasmineRequireObj().util = function() { 197 | 198 | var util = {}; 199 | 200 | util.inherit = function(childClass, parentClass) { 201 | var Subclass = function() { 202 | }; 203 | Subclass.prototype = parentClass.prototype; 204 | childClass.prototype = new Subclass(); 205 | }; 206 | 207 | util.htmlEscape = function(str) { 208 | if (!str) { 209 | return str; 210 | } 211 | return str.replace(/&/g, '&') 212 | .replace(//g, '>'); 214 | }; 215 | 216 | util.argsToArray = function(args) { 217 | var arrayOfArgs = []; 218 | for (var i = 0; i < args.length; i++) { 219 | arrayOfArgs.push(args[i]); 220 | } 221 | return arrayOfArgs; 222 | }; 223 | 224 | util.isUndefined = function(obj) { 225 | return obj === void 0; 226 | }; 227 | 228 | util.arrayContains = function(array, search) { 229 | var i = array.length; 230 | while (i--) { 231 | if (array[i] == search) { 232 | return true; 233 | } 234 | } 235 | return false; 236 | }; 237 | 238 | return util; 239 | }; 240 | 241 | getJasmineRequireObj().Spec = function(j$) { 242 | function Spec(attrs) { 243 | this.expectationFactory = attrs.expectationFactory; 244 | this.resultCallback = attrs.resultCallback || function() {}; 245 | this.id = attrs.id; 246 | this.description = attrs.description || ''; 247 | this.fn = attrs.fn; 248 | this.beforeFns = attrs.beforeFns || function() { return []; }; 249 | this.afterFns = attrs.afterFns || function() { return []; }; 250 | this.onStart = attrs.onStart || function() {}; 251 | this.exceptionFormatter = attrs.exceptionFormatter || function() {}; 252 | this.getSpecName = attrs.getSpecName || function() { return ''; }; 253 | this.expectationResultFactory = attrs.expectationResultFactory || function() { }; 254 | this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; 255 | this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; 256 | 257 | if (!this.fn) { 258 | this.pend(); 259 | } 260 | 261 | this.result = { 262 | id: this.id, 263 | description: this.description, 264 | fullName: this.getFullName(), 265 | failedExpectations: [], 266 | passedExpectations: [] 267 | }; 268 | } 269 | 270 | Spec.prototype.addExpectationResult = function(passed, data) { 271 | var expectationResult = this.expectationResultFactory(data); 272 | if (passed) { 273 | this.result.passedExpectations.push(expectationResult); 274 | } else { 275 | this.result.failedExpectations.push(expectationResult); 276 | } 277 | }; 278 | 279 | Spec.prototype.expect = function(actual) { 280 | return this.expectationFactory(actual, this); 281 | }; 282 | 283 | Spec.prototype.execute = function(onComplete) { 284 | var self = this; 285 | 286 | this.onStart(this); 287 | 288 | if (this.markedPending || this.disabled) { 289 | complete(); 290 | return; 291 | } 292 | 293 | var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns()); 294 | 295 | this.queueRunnerFactory({ 296 | fns: allFns, 297 | onException: onException, 298 | onComplete: complete, 299 | enforceTimeout: function() { return true; } 300 | }); 301 | 302 | function onException(e) { 303 | if (Spec.isPendingSpecException(e)) { 304 | self.pend(); 305 | return; 306 | } 307 | 308 | self.addExpectationResult(false, { 309 | matcherName: '', 310 | passed: false, 311 | expected: '', 312 | actual: '', 313 | error: e 314 | }); 315 | } 316 | 317 | function complete() { 318 | self.result.status = self.status(); 319 | self.resultCallback(self.result); 320 | 321 | if (onComplete) { 322 | onComplete(); 323 | } 324 | } 325 | }; 326 | 327 | Spec.prototype.disable = function() { 328 | this.disabled = true; 329 | }; 330 | 331 | Spec.prototype.pend = function() { 332 | this.markedPending = true; 333 | }; 334 | 335 | Spec.prototype.status = function() { 336 | if (this.disabled) { 337 | return 'disabled'; 338 | } 339 | 340 | if (this.markedPending) { 341 | return 'pending'; 342 | } 343 | 344 | if (this.result.failedExpectations.length > 0) { 345 | return 'failed'; 346 | } else { 347 | return 'passed'; 348 | } 349 | }; 350 | 351 | Spec.prototype.getFullName = function() { 352 | return this.getSpecName(this); 353 | }; 354 | 355 | Spec.pendingSpecExceptionMessage = '=> marked Pending'; 356 | 357 | Spec.isPendingSpecException = function(e) { 358 | return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1); 359 | }; 360 | 361 | return Spec; 362 | }; 363 | 364 | if (typeof window == void 0 && typeof exports == 'object') { 365 | exports.Spec = jasmineRequire.Spec; 366 | } 367 | 368 | getJasmineRequireObj().Env = function(j$) { 369 | function Env(options) { 370 | options = options || {}; 371 | 372 | var self = this; 373 | var global = options.global || j$.getGlobal(); 374 | 375 | var totalSpecsDefined = 0; 376 | 377 | var catchExceptions = true; 378 | 379 | var realSetTimeout = j$.getGlobal().setTimeout; 380 | var realClearTimeout = j$.getGlobal().clearTimeout; 381 | this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global)); 382 | 383 | var runnableLookupTable = {}; 384 | 385 | var spies = []; 386 | 387 | var currentSpec = null; 388 | var currentSuite = null; 389 | 390 | var reporter = new j$.ReportDispatcher([ 391 | 'jasmineStarted', 392 | 'jasmineDone', 393 | 'suiteStarted', 394 | 'suiteDone', 395 | 'specStarted', 396 | 'specDone' 397 | ]); 398 | 399 | this.specFilter = function() { 400 | return true; 401 | }; 402 | 403 | var equalityTesters = []; 404 | 405 | var customEqualityTesters = []; 406 | this.addCustomEqualityTester = function(tester) { 407 | customEqualityTesters.push(tester); 408 | }; 409 | 410 | j$.Expectation.addCoreMatchers(j$.matchers); 411 | 412 | var nextSpecId = 0; 413 | var getNextSpecId = function() { 414 | return 'spec' + nextSpecId++; 415 | }; 416 | 417 | var nextSuiteId = 0; 418 | var getNextSuiteId = function() { 419 | return 'suite' + nextSuiteId++; 420 | }; 421 | 422 | var expectationFactory = function(actual, spec) { 423 | return j$.Expectation.Factory({ 424 | util: j$.matchersUtil, 425 | customEqualityTesters: customEqualityTesters, 426 | actual: actual, 427 | addExpectationResult: addExpectationResult 428 | }); 429 | 430 | function addExpectationResult(passed, result) { 431 | return spec.addExpectationResult(passed, result); 432 | } 433 | }; 434 | 435 | var specStarted = function(spec) { 436 | currentSpec = spec; 437 | reporter.specStarted(spec.result); 438 | }; 439 | 440 | var beforeFns = function(suite) { 441 | return function() { 442 | var befores = []; 443 | while(suite) { 444 | befores = befores.concat(suite.beforeFns); 445 | suite = suite.parentSuite; 446 | } 447 | return befores.reverse(); 448 | }; 449 | }; 450 | 451 | var afterFns = function(suite) { 452 | return function() { 453 | var afters = []; 454 | while(suite) { 455 | afters = afters.concat(suite.afterFns); 456 | suite = suite.parentSuite; 457 | } 458 | return afters; 459 | }; 460 | }; 461 | 462 | var getSpecName = function(spec, suite) { 463 | return suite.getFullName() + ' ' + spec.description; 464 | }; 465 | 466 | // TODO: we may just be able to pass in the fn instead of wrapping here 467 | var buildExpectationResult = j$.buildExpectationResult, 468 | exceptionFormatter = new j$.ExceptionFormatter(), 469 | expectationResultFactory = function(attrs) { 470 | attrs.messageFormatter = exceptionFormatter.message; 471 | attrs.stackFormatter = exceptionFormatter.stack; 472 | 473 | return buildExpectationResult(attrs); 474 | }; 475 | 476 | // TODO: fix this naming, and here's where the value comes in 477 | this.catchExceptions = function(value) { 478 | catchExceptions = !!value; 479 | return catchExceptions; 480 | }; 481 | 482 | this.catchingExceptions = function() { 483 | return catchExceptions; 484 | }; 485 | 486 | var maximumSpecCallbackDepth = 20; 487 | var currentSpecCallbackDepth = 0; 488 | 489 | function clearStack(fn) { 490 | currentSpecCallbackDepth++; 491 | if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) { 492 | currentSpecCallbackDepth = 0; 493 | realSetTimeout(fn, 0); 494 | } else { 495 | fn(); 496 | } 497 | } 498 | 499 | var catchException = function(e) { 500 | return j$.Spec.isPendingSpecException(e) || catchExceptions; 501 | }; 502 | 503 | var queueRunnerFactory = function(options) { 504 | options.catchException = catchException; 505 | options.clearStack = options.clearStack || clearStack; 506 | options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}; 507 | 508 | new j$.QueueRunner(options).execute(); 509 | }; 510 | 511 | var topSuite = new j$.Suite({ 512 | env: this, 513 | id: getNextSuiteId(), 514 | description: 'Jasmine__TopLevel__Suite', 515 | queueRunner: queueRunnerFactory, 516 | resultCallback: function() {} // TODO - hook this up 517 | }); 518 | runnableLookupTable[topSuite.id] = topSuite; 519 | currentSuite = topSuite; 520 | 521 | this.topSuite = function() { 522 | return topSuite; 523 | }; 524 | 525 | this.execute = function(runnablesToRun) { 526 | runnablesToRun = runnablesToRun || [topSuite.id]; 527 | 528 | var allFns = []; 529 | for(var i = 0; i < runnablesToRun.length; i++) { 530 | var runnable = runnableLookupTable[runnablesToRun[i]]; 531 | allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable)); 532 | } 533 | 534 | reporter.jasmineStarted({ 535 | totalSpecsDefined: totalSpecsDefined 536 | }); 537 | 538 | queueRunnerFactory({fns: allFns, onComplete: reporter.jasmineDone}); 539 | }; 540 | 541 | this.addReporter = function(reporterToAdd) { 542 | reporter.addReporter(reporterToAdd); 543 | }; 544 | 545 | this.addMatchers = function(matchersToAdd) { 546 | j$.Expectation.addMatchers(matchersToAdd); 547 | }; 548 | 549 | this.spyOn = function(obj, methodName) { 550 | if (j$.util.isUndefined(obj)) { 551 | throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()'); 552 | } 553 | 554 | if (j$.util.isUndefined(obj[methodName])) { 555 | throw new Error(methodName + '() method does not exist'); 556 | } 557 | 558 | if (obj[methodName] && j$.isSpy(obj[methodName])) { 559 | //TODO?: should this return the current spy? Downside: may cause user confusion about spy state 560 | throw new Error(methodName + ' has already been spied upon'); 561 | } 562 | 563 | var spy = j$.createSpy(methodName, obj[methodName]); 564 | 565 | spies.push({ 566 | spy: spy, 567 | baseObj: obj, 568 | methodName: methodName, 569 | originalValue: obj[methodName] 570 | }); 571 | 572 | obj[methodName] = spy; 573 | 574 | return spy; 575 | }; 576 | 577 | var suiteFactory = function(description) { 578 | var suite = new j$.Suite({ 579 | env: self, 580 | id: getNextSuiteId(), 581 | description: description, 582 | parentSuite: currentSuite, 583 | queueRunner: queueRunnerFactory, 584 | onStart: suiteStarted, 585 | resultCallback: function(attrs) { 586 | reporter.suiteDone(attrs); 587 | } 588 | }); 589 | 590 | runnableLookupTable[suite.id] = suite; 591 | return suite; 592 | }; 593 | 594 | this.describe = function(description, specDefinitions) { 595 | var suite = suiteFactory(description); 596 | 597 | var parentSuite = currentSuite; 598 | parentSuite.addChild(suite); 599 | currentSuite = suite; 600 | 601 | var declarationError = null; 602 | try { 603 | specDefinitions.call(suite); 604 | } catch (e) { 605 | declarationError = e; 606 | } 607 | 608 | if (declarationError) { 609 | this.it('encountered a declaration exception', function() { 610 | throw declarationError; 611 | }); 612 | } 613 | 614 | currentSuite = parentSuite; 615 | 616 | return suite; 617 | }; 618 | 619 | this.xdescribe = function(description, specDefinitions) { 620 | var suite = this.describe(description, specDefinitions); 621 | suite.disable(); 622 | return suite; 623 | }; 624 | 625 | var specFactory = function(description, fn, suite) { 626 | totalSpecsDefined++; 627 | 628 | var spec = new j$.Spec({ 629 | id: getNextSpecId(), 630 | beforeFns: beforeFns(suite), 631 | afterFns: afterFns(suite), 632 | expectationFactory: expectationFactory, 633 | exceptionFormatter: exceptionFormatter, 634 | resultCallback: specResultCallback, 635 | getSpecName: function(spec) { 636 | return getSpecName(spec, suite); 637 | }, 638 | onStart: specStarted, 639 | description: description, 640 | expectationResultFactory: expectationResultFactory, 641 | queueRunnerFactory: queueRunnerFactory, 642 | fn: fn 643 | }); 644 | 645 | runnableLookupTable[spec.id] = spec; 646 | 647 | if (!self.specFilter(spec)) { 648 | spec.disable(); 649 | } 650 | 651 | return spec; 652 | 653 | function removeAllSpies() { 654 | for (var i = 0; i < spies.length; i++) { 655 | var spyEntry = spies[i]; 656 | spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue; 657 | } 658 | spies = []; 659 | } 660 | 661 | function specResultCallback(result) { 662 | removeAllSpies(); 663 | j$.Expectation.resetMatchers(); 664 | customEqualityTesters = []; 665 | currentSpec = null; 666 | reporter.specDone(result); 667 | } 668 | }; 669 | 670 | var suiteStarted = function(suite) { 671 | reporter.suiteStarted(suite.result); 672 | }; 673 | 674 | this.it = function(description, fn) { 675 | var spec = specFactory(description, fn, currentSuite); 676 | currentSuite.addChild(spec); 677 | return spec; 678 | }; 679 | 680 | this.xit = function(description, fn) { 681 | var spec = this.it(description, fn); 682 | spec.pend(); 683 | return spec; 684 | }; 685 | 686 | this.expect = function(actual) { 687 | if (!currentSpec) { 688 | throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out'); 689 | } 690 | 691 | return currentSpec.expect(actual); 692 | }; 693 | 694 | this.beforeEach = function(beforeEachFunction) { 695 | currentSuite.beforeEach(beforeEachFunction); 696 | }; 697 | 698 | this.afterEach = function(afterEachFunction) { 699 | currentSuite.afterEach(afterEachFunction); 700 | }; 701 | 702 | this.pending = function() { 703 | throw j$.Spec.pendingSpecExceptionMessage; 704 | }; 705 | } 706 | 707 | return Env; 708 | }; 709 | 710 | getJasmineRequireObj().JsApiReporter = function() { 711 | 712 | var noopTimer = { 713 | start: function(){}, 714 | elapsed: function(){ return 0; } 715 | }; 716 | 717 | function JsApiReporter(options) { 718 | var timer = options.timer || noopTimer, 719 | status = 'loaded'; 720 | 721 | this.started = false; 722 | this.finished = false; 723 | 724 | this.jasmineStarted = function() { 725 | this.started = true; 726 | status = 'started'; 727 | timer.start(); 728 | }; 729 | 730 | var executionTime; 731 | 732 | this.jasmineDone = function() { 733 | this.finished = true; 734 | executionTime = timer.elapsed(); 735 | status = 'done'; 736 | }; 737 | 738 | this.status = function() { 739 | return status; 740 | }; 741 | 742 | var suites = {}; 743 | 744 | this.suiteStarted = function(result) { 745 | storeSuite(result); 746 | }; 747 | 748 | this.suiteDone = function(result) { 749 | storeSuite(result); 750 | }; 751 | 752 | function storeSuite(result) { 753 | suites[result.id] = result; 754 | } 755 | 756 | this.suites = function() { 757 | return suites; 758 | }; 759 | 760 | var specs = []; 761 | this.specStarted = function(result) { }; 762 | 763 | this.specDone = function(result) { 764 | specs.push(result); 765 | }; 766 | 767 | this.specResults = function(index, length) { 768 | return specs.slice(index, index + length); 769 | }; 770 | 771 | this.specs = function() { 772 | return specs; 773 | }; 774 | 775 | this.executionTime = function() { 776 | return executionTime; 777 | }; 778 | 779 | } 780 | 781 | return JsApiReporter; 782 | }; 783 | 784 | getJasmineRequireObj().Any = function() { 785 | 786 | function Any(expectedObject) { 787 | this.expectedObject = expectedObject; 788 | } 789 | 790 | Any.prototype.jasmineMatches = function(other) { 791 | if (this.expectedObject == String) { 792 | return typeof other == 'string' || other instanceof String; 793 | } 794 | 795 | if (this.expectedObject == Number) { 796 | return typeof other == 'number' || other instanceof Number; 797 | } 798 | 799 | if (this.expectedObject == Function) { 800 | return typeof other == 'function' || other instanceof Function; 801 | } 802 | 803 | if (this.expectedObject == Object) { 804 | return typeof other == 'object'; 805 | } 806 | 807 | if (this.expectedObject == Boolean) { 808 | return typeof other == 'boolean'; 809 | } 810 | 811 | return other instanceof this.expectedObject; 812 | }; 813 | 814 | Any.prototype.jasmineToString = function() { 815 | return ''; 816 | }; 817 | 818 | return Any; 819 | }; 820 | 821 | getJasmineRequireObj().CallTracker = function() { 822 | 823 | function CallTracker() { 824 | var calls = []; 825 | 826 | this.track = function(context) { 827 | calls.push(context); 828 | }; 829 | 830 | this.any = function() { 831 | return !!calls.length; 832 | }; 833 | 834 | this.count = function() { 835 | return calls.length; 836 | }; 837 | 838 | this.argsFor = function(index) { 839 | var call = calls[index]; 840 | return call ? call.args : []; 841 | }; 842 | 843 | this.all = function() { 844 | return calls; 845 | }; 846 | 847 | this.allArgs = function() { 848 | var callArgs = []; 849 | for(var i = 0; i < calls.length; i++){ 850 | callArgs.push(calls[i].args); 851 | } 852 | 853 | return callArgs; 854 | }; 855 | 856 | this.first = function() { 857 | return calls[0]; 858 | }; 859 | 860 | this.mostRecent = function() { 861 | return calls[calls.length - 1]; 862 | }; 863 | 864 | this.reset = function() { 865 | calls = []; 866 | }; 867 | } 868 | 869 | return CallTracker; 870 | }; 871 | 872 | getJasmineRequireObj().Clock = function() { 873 | function Clock(global, delayedFunctionScheduler, mockDate) { 874 | var self = this, 875 | realTimingFunctions = { 876 | setTimeout: global.setTimeout, 877 | clearTimeout: global.clearTimeout, 878 | setInterval: global.setInterval, 879 | clearInterval: global.clearInterval 880 | }, 881 | fakeTimingFunctions = { 882 | setTimeout: setTimeout, 883 | clearTimeout: clearTimeout, 884 | setInterval: setInterval, 885 | clearInterval: clearInterval 886 | }, 887 | installed = false, 888 | timer; 889 | 890 | 891 | self.install = function() { 892 | replace(global, fakeTimingFunctions); 893 | timer = fakeTimingFunctions; 894 | installed = true; 895 | 896 | return self; 897 | }; 898 | 899 | self.uninstall = function() { 900 | delayedFunctionScheduler.reset(); 901 | mockDate.uninstall(); 902 | replace(global, realTimingFunctions); 903 | 904 | timer = realTimingFunctions; 905 | installed = false; 906 | }; 907 | 908 | self.mockDate = function(initialDate) { 909 | mockDate.install(initialDate); 910 | }; 911 | 912 | self.setTimeout = function(fn, delay, params) { 913 | if (legacyIE()) { 914 | if (arguments.length > 2) { 915 | throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill'); 916 | } 917 | return timer.setTimeout(fn, delay); 918 | } 919 | return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); 920 | }; 921 | 922 | self.setInterval = function(fn, delay, params) { 923 | if (legacyIE()) { 924 | if (arguments.length > 2) { 925 | throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill'); 926 | } 927 | return timer.setInterval(fn, delay); 928 | } 929 | return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); 930 | }; 931 | 932 | self.clearTimeout = function(id) { 933 | return Function.prototype.call.apply(timer.clearTimeout, [global, id]); 934 | }; 935 | 936 | self.clearInterval = function(id) { 937 | return Function.prototype.call.apply(timer.clearInterval, [global, id]); 938 | }; 939 | 940 | self.tick = function(millis) { 941 | if (installed) { 942 | mockDate.tick(millis); 943 | delayedFunctionScheduler.tick(millis); 944 | } else { 945 | throw new Error('Mock clock is not installed, use jasmine.clock().install()'); 946 | } 947 | }; 948 | 949 | return self; 950 | 951 | function legacyIE() { 952 | //if these methods are polyfilled, apply will be present 953 | return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; 954 | } 955 | 956 | function replace(dest, source) { 957 | for (var prop in source) { 958 | dest[prop] = source[prop]; 959 | } 960 | } 961 | 962 | function setTimeout(fn, delay) { 963 | return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); 964 | } 965 | 966 | function clearTimeout(id) { 967 | return delayedFunctionScheduler.removeFunctionWithId(id); 968 | } 969 | 970 | function setInterval(fn, interval) { 971 | return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); 972 | } 973 | 974 | function clearInterval(id) { 975 | return delayedFunctionScheduler.removeFunctionWithId(id); 976 | } 977 | 978 | function argSlice(argsObj, n) { 979 | return Array.prototype.slice.call(argsObj, n); 980 | } 981 | } 982 | 983 | return Clock; 984 | }; 985 | 986 | getJasmineRequireObj().DelayedFunctionScheduler = function() { 987 | function DelayedFunctionScheduler() { 988 | var self = this; 989 | var scheduledLookup = []; 990 | var scheduledFunctions = {}; 991 | var currentTime = 0; 992 | var delayedFnCount = 0; 993 | 994 | self.tick = function(millis) { 995 | millis = millis || 0; 996 | var endTime = currentTime + millis; 997 | 998 | runScheduledFunctions(endTime); 999 | currentTime = endTime; 1000 | }; 1001 | 1002 | self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) { 1003 | var f; 1004 | if (typeof(funcToCall) === 'string') { 1005 | /* jshint evil: true */ 1006 | f = function() { return eval(funcToCall); }; 1007 | /* jshint evil: false */ 1008 | } else { 1009 | f = funcToCall; 1010 | } 1011 | 1012 | millis = millis || 0; 1013 | timeoutKey = timeoutKey || ++delayedFnCount; 1014 | runAtMillis = runAtMillis || (currentTime + millis); 1015 | 1016 | var funcToSchedule = { 1017 | runAtMillis: runAtMillis, 1018 | funcToCall: f, 1019 | recurring: recurring, 1020 | params: params, 1021 | timeoutKey: timeoutKey, 1022 | millis: millis 1023 | }; 1024 | 1025 | if (runAtMillis in scheduledFunctions) { 1026 | scheduledFunctions[runAtMillis].push(funcToSchedule); 1027 | } else { 1028 | scheduledFunctions[runAtMillis] = [funcToSchedule]; 1029 | scheduledLookup.push(runAtMillis); 1030 | scheduledLookup.sort(function (a, b) { 1031 | return a - b; 1032 | }); 1033 | } 1034 | 1035 | return timeoutKey; 1036 | }; 1037 | 1038 | self.removeFunctionWithId = function(timeoutKey) { 1039 | for (var runAtMillis in scheduledFunctions) { 1040 | var funcs = scheduledFunctions[runAtMillis]; 1041 | var i = indexOfFirstToPass(funcs, function (func) { 1042 | return func.timeoutKey === timeoutKey; 1043 | }); 1044 | 1045 | if (i > -1) { 1046 | if (funcs.length === 1) { 1047 | delete scheduledFunctions[runAtMillis]; 1048 | deleteFromLookup(runAtMillis); 1049 | } else { 1050 | funcs.splice(i, 1); 1051 | } 1052 | 1053 | // intervals get rescheduled when executed, so there's never more 1054 | // than a single scheduled function with a given timeoutKey 1055 | break; 1056 | } 1057 | } 1058 | }; 1059 | 1060 | self.reset = function() { 1061 | currentTime = 0; 1062 | scheduledLookup = []; 1063 | scheduledFunctions = {}; 1064 | delayedFnCount = 0; 1065 | }; 1066 | 1067 | return self; 1068 | 1069 | function indexOfFirstToPass(array, testFn) { 1070 | var index = -1; 1071 | 1072 | for (var i = 0; i < array.length; ++i) { 1073 | if (testFn(array[i])) { 1074 | index = i; 1075 | break; 1076 | } 1077 | } 1078 | 1079 | return index; 1080 | } 1081 | 1082 | function deleteFromLookup(key) { 1083 | var value = Number(key); 1084 | var i = indexOfFirstToPass(scheduledLookup, function (millis) { 1085 | return millis === value; 1086 | }); 1087 | 1088 | if (i > -1) { 1089 | scheduledLookup.splice(i, 1); 1090 | } 1091 | } 1092 | 1093 | function reschedule(scheduledFn) { 1094 | self.scheduleFunction(scheduledFn.funcToCall, 1095 | scheduledFn.millis, 1096 | scheduledFn.params, 1097 | true, 1098 | scheduledFn.timeoutKey, 1099 | scheduledFn.runAtMillis + scheduledFn.millis); 1100 | } 1101 | 1102 | function runScheduledFunctions(endTime) { 1103 | if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { 1104 | return; 1105 | } 1106 | 1107 | do { 1108 | currentTime = scheduledLookup.shift(); 1109 | 1110 | var funcsToRun = scheduledFunctions[currentTime]; 1111 | delete scheduledFunctions[currentTime]; 1112 | 1113 | for (var i = 0; i < funcsToRun.length; ++i) { 1114 | var funcToRun = funcsToRun[i]; 1115 | funcToRun.funcToCall.apply(null, funcToRun.params || []); 1116 | 1117 | if (funcToRun.recurring) { 1118 | reschedule(funcToRun); 1119 | } 1120 | } 1121 | } while (scheduledLookup.length > 0 && 1122 | // checking first if we're out of time prevents setTimeout(0) 1123 | // scheduled in a funcToRun from forcing an extra iteration 1124 | currentTime !== endTime && 1125 | scheduledLookup[0] <= endTime); 1126 | } 1127 | } 1128 | 1129 | return DelayedFunctionScheduler; 1130 | }; 1131 | 1132 | getJasmineRequireObj().ExceptionFormatter = function() { 1133 | function ExceptionFormatter() { 1134 | this.message = function(error) { 1135 | var message = ''; 1136 | 1137 | if (error.name && error.message) { 1138 | message += error.name + ': ' + error.message; 1139 | } else { 1140 | message += error.toString() + ' thrown'; 1141 | } 1142 | 1143 | if (error.fileName || error.sourceURL) { 1144 | message += ' in ' + (error.fileName || error.sourceURL); 1145 | } 1146 | 1147 | if (error.line || error.lineNumber) { 1148 | message += ' (line ' + (error.line || error.lineNumber) + ')'; 1149 | } 1150 | 1151 | return message; 1152 | }; 1153 | 1154 | this.stack = function(error) { 1155 | return error ? error.stack : null; 1156 | }; 1157 | } 1158 | 1159 | return ExceptionFormatter; 1160 | }; 1161 | 1162 | getJasmineRequireObj().Expectation = function() { 1163 | 1164 | var matchers = {}; 1165 | 1166 | function Expectation(options) { 1167 | this.util = options.util || { buildFailureMessage: function() {} }; 1168 | this.customEqualityTesters = options.customEqualityTesters || []; 1169 | this.actual = options.actual; 1170 | this.addExpectationResult = options.addExpectationResult || function(){}; 1171 | this.isNot = options.isNot; 1172 | 1173 | for (var matcherName in matchers) { 1174 | this[matcherName] = matchers[matcherName]; 1175 | } 1176 | } 1177 | 1178 | Expectation.prototype.wrapCompare = function(name, matcherFactory) { 1179 | return function() { 1180 | var args = Array.prototype.slice.call(arguments, 0), 1181 | expected = args.slice(0), 1182 | message = ''; 1183 | 1184 | args.unshift(this.actual); 1185 | 1186 | var matcher = matcherFactory(this.util, this.customEqualityTesters), 1187 | matcherCompare = matcher.compare; 1188 | 1189 | function defaultNegativeCompare() { 1190 | var result = matcher.compare.apply(null, args); 1191 | result.pass = !result.pass; 1192 | return result; 1193 | } 1194 | 1195 | if (this.isNot) { 1196 | matcherCompare = matcher.negativeCompare || defaultNegativeCompare; 1197 | } 1198 | 1199 | var result = matcherCompare.apply(null, args); 1200 | 1201 | if (!result.pass) { 1202 | if (!result.message) { 1203 | args.unshift(this.isNot); 1204 | args.unshift(name); 1205 | message = this.util.buildFailureMessage.apply(null, args); 1206 | } else { 1207 | if (Object.prototype.toString.apply(result.message) === '[object Function]') { 1208 | message = result.message(); 1209 | } else { 1210 | message = result.message; 1211 | } 1212 | } 1213 | } 1214 | 1215 | if (expected.length == 1) { 1216 | expected = expected[0]; 1217 | } 1218 | 1219 | // TODO: how many of these params are needed? 1220 | this.addExpectationResult( 1221 | result.pass, 1222 | { 1223 | matcherName: name, 1224 | passed: result.pass, 1225 | message: message, 1226 | actual: this.actual, 1227 | expected: expected // TODO: this may need to be arrayified/sliced 1228 | } 1229 | ); 1230 | }; 1231 | }; 1232 | 1233 | Expectation.addCoreMatchers = function(matchers) { 1234 | var prototype = Expectation.prototype; 1235 | for (var matcherName in matchers) { 1236 | var matcher = matchers[matcherName]; 1237 | prototype[matcherName] = prototype.wrapCompare(matcherName, matcher); 1238 | } 1239 | }; 1240 | 1241 | Expectation.addMatchers = function(matchersToAdd) { 1242 | for (var name in matchersToAdd) { 1243 | var matcher = matchersToAdd[name]; 1244 | matchers[name] = Expectation.prototype.wrapCompare(name, matcher); 1245 | } 1246 | }; 1247 | 1248 | Expectation.resetMatchers = function() { 1249 | for (var name in matchers) { 1250 | delete matchers[name]; 1251 | } 1252 | }; 1253 | 1254 | Expectation.Factory = function(options) { 1255 | options = options || {}; 1256 | 1257 | var expect = new Expectation(options); 1258 | 1259 | // TODO: this would be nice as its own Object - NegativeExpectation 1260 | // TODO: copy instead of mutate options 1261 | options.isNot = true; 1262 | expect.not = new Expectation(options); 1263 | 1264 | return expect; 1265 | }; 1266 | 1267 | return Expectation; 1268 | }; 1269 | 1270 | //TODO: expectation result may make more sense as a presentation of an expectation. 1271 | getJasmineRequireObj().buildExpectationResult = function() { 1272 | function buildExpectationResult(options) { 1273 | var messageFormatter = options.messageFormatter || function() {}, 1274 | stackFormatter = options.stackFormatter || function() {}; 1275 | 1276 | return { 1277 | matcherName: options.matcherName, 1278 | expected: options.expected, 1279 | actual: options.actual, 1280 | message: message(), 1281 | stack: stack(), 1282 | passed: options.passed 1283 | }; 1284 | 1285 | function message() { 1286 | if (options.passed) { 1287 | return 'Passed.'; 1288 | } else if (options.message) { 1289 | return options.message; 1290 | } else if (options.error) { 1291 | return messageFormatter(options.error); 1292 | } 1293 | return ''; 1294 | } 1295 | 1296 | function stack() { 1297 | if (options.passed) { 1298 | return ''; 1299 | } 1300 | 1301 | var error = options.error; 1302 | if (!error) { 1303 | try { 1304 | throw new Error(message()); 1305 | } catch (e) { 1306 | error = e; 1307 | } 1308 | } 1309 | return stackFormatter(error); 1310 | } 1311 | } 1312 | 1313 | return buildExpectationResult; 1314 | }; 1315 | 1316 | getJasmineRequireObj().MockDate = function() { 1317 | function MockDate(global) { 1318 | var self = this; 1319 | var currentTime = 0; 1320 | 1321 | if (!global || !global.Date) { 1322 | self.install = function() {}; 1323 | self.tick = function() {}; 1324 | self.uninstall = function() {}; 1325 | return self; 1326 | } 1327 | 1328 | var GlobalDate = global.Date; 1329 | 1330 | self.install = function(mockDate) { 1331 | if (mockDate instanceof GlobalDate) { 1332 | currentTime = mockDate.getTime(); 1333 | } else { 1334 | currentTime = new GlobalDate().getTime(); 1335 | } 1336 | 1337 | global.Date = FakeDate; 1338 | }; 1339 | 1340 | self.tick = function(millis) { 1341 | millis = millis || 0; 1342 | currentTime = currentTime + millis; 1343 | }; 1344 | 1345 | self.uninstall = function() { 1346 | currentTime = 0; 1347 | global.Date = GlobalDate; 1348 | }; 1349 | 1350 | createDateProperties(); 1351 | 1352 | return self; 1353 | 1354 | function FakeDate() { 1355 | if (arguments.length === 0) { 1356 | return new GlobalDate(currentTime); 1357 | } else { 1358 | return new GlobalDate(arguments[0], arguments[1], arguments[2], 1359 | arguments[3], arguments[4], arguments[5], arguments[6]); 1360 | } 1361 | } 1362 | 1363 | function createDateProperties() { 1364 | 1365 | FakeDate.now = function() { 1366 | if (GlobalDate.now) { 1367 | return currentTime; 1368 | } else { 1369 | throw new Error('Browser does not support Date.now()'); 1370 | } 1371 | }; 1372 | 1373 | FakeDate.toSource = GlobalDate.toSource; 1374 | FakeDate.toString = GlobalDate.toString; 1375 | FakeDate.parse = GlobalDate.parse; 1376 | FakeDate.UTC = GlobalDate.UTC; 1377 | } 1378 | } 1379 | 1380 | return MockDate; 1381 | }; 1382 | 1383 | getJasmineRequireObj().ObjectContaining = function(j$) { 1384 | 1385 | function ObjectContaining(sample) { 1386 | this.sample = sample; 1387 | } 1388 | 1389 | ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) { 1390 | if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } 1391 | 1392 | mismatchKeys = mismatchKeys || []; 1393 | mismatchValues = mismatchValues || []; 1394 | 1395 | var hasKey = function(obj, keyName) { 1396 | return obj !== null && !j$.util.isUndefined(obj[keyName]); 1397 | }; 1398 | 1399 | for (var property in this.sample) { 1400 | if (!hasKey(other, property) && hasKey(this.sample, property)) { 1401 | mismatchKeys.push('expected has key \'' + property + '\', but missing from actual.'); 1402 | } 1403 | else if (!j$.matchersUtil.equals(other[property], this.sample[property])) { 1404 | mismatchValues.push('\'' + property + '\' was \'' + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + '\' in actual, but was \'' + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + '\' in expected.'); 1405 | } 1406 | } 1407 | 1408 | return (mismatchKeys.length === 0 && mismatchValues.length === 0); 1409 | }; 1410 | 1411 | ObjectContaining.prototype.jasmineToString = function() { 1412 | return ''; 1413 | }; 1414 | 1415 | return ObjectContaining; 1416 | }; 1417 | 1418 | getJasmineRequireObj().pp = function(j$) { 1419 | 1420 | function PrettyPrinter() { 1421 | this.ppNestLevel_ = 0; 1422 | this.seen = []; 1423 | } 1424 | 1425 | PrettyPrinter.prototype.format = function(value) { 1426 | this.ppNestLevel_++; 1427 | try { 1428 | if (j$.util.isUndefined(value)) { 1429 | this.emitScalar('undefined'); 1430 | } else if (value === null) { 1431 | this.emitScalar('null'); 1432 | } else if (value === 0 && 1/value === -Infinity) { 1433 | this.emitScalar('-0'); 1434 | } else if (value === j$.getGlobal()) { 1435 | this.emitScalar(''); 1436 | } else if (value.jasmineToString) { 1437 | this.emitScalar(value.jasmineToString()); 1438 | } else if (typeof value === 'string') { 1439 | this.emitString(value); 1440 | } else if (j$.isSpy(value)) { 1441 | this.emitScalar('spy on ' + value.and.identity()); 1442 | } else if (value instanceof RegExp) { 1443 | this.emitScalar(value.toString()); 1444 | } else if (typeof value === 'function') { 1445 | this.emitScalar('Function'); 1446 | } else if (typeof value.nodeType === 'number') { 1447 | this.emitScalar('HTMLNode'); 1448 | } else if (value instanceof Date) { 1449 | this.emitScalar('Date(' + value + ')'); 1450 | } else if (j$.util.arrayContains(this.seen, value)) { 1451 | this.emitScalar(''); 1452 | } else if (j$.isArray_(value) || j$.isA_('Object', value)) { 1453 | this.seen.push(value); 1454 | if (j$.isArray_(value)) { 1455 | this.emitArray(value); 1456 | } else { 1457 | this.emitObject(value); 1458 | } 1459 | this.seen.pop(); 1460 | } else { 1461 | this.emitScalar(value.toString()); 1462 | } 1463 | } finally { 1464 | this.ppNestLevel_--; 1465 | } 1466 | }; 1467 | 1468 | PrettyPrinter.prototype.iterateObject = function(obj, fn) { 1469 | for (var property in obj) { 1470 | if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; } 1471 | fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && 1472 | obj.__lookupGetter__(property) !== null) : false); 1473 | } 1474 | }; 1475 | 1476 | PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_; 1477 | PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_; 1478 | PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_; 1479 | PrettyPrinter.prototype.emitString = j$.unimplementedMethod_; 1480 | 1481 | function StringPrettyPrinter() { 1482 | PrettyPrinter.call(this); 1483 | 1484 | this.string = ''; 1485 | } 1486 | 1487 | j$.util.inherit(StringPrettyPrinter, PrettyPrinter); 1488 | 1489 | StringPrettyPrinter.prototype.emitScalar = function(value) { 1490 | this.append(value); 1491 | }; 1492 | 1493 | StringPrettyPrinter.prototype.emitString = function(value) { 1494 | this.append('\'' + value + '\''); 1495 | }; 1496 | 1497 | StringPrettyPrinter.prototype.emitArray = function(array) { 1498 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1499 | this.append('Array'); 1500 | return; 1501 | } 1502 | var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); 1503 | this.append('[ '); 1504 | for (var i = 0; i < length; i++) { 1505 | if (i > 0) { 1506 | this.append(', '); 1507 | } 1508 | this.format(array[i]); 1509 | } 1510 | if(array.length > length){ 1511 | this.append(', ...'); 1512 | } 1513 | this.append(' ]'); 1514 | }; 1515 | 1516 | StringPrettyPrinter.prototype.emitObject = function(obj) { 1517 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1518 | this.append('Object'); 1519 | return; 1520 | } 1521 | 1522 | var self = this; 1523 | this.append('{ '); 1524 | var first = true; 1525 | 1526 | this.iterateObject(obj, function(property, isGetter) { 1527 | if (first) { 1528 | first = false; 1529 | } else { 1530 | self.append(', '); 1531 | } 1532 | 1533 | self.append(property); 1534 | self.append(': '); 1535 | if (isGetter) { 1536 | self.append(''); 1537 | } else { 1538 | self.format(obj[property]); 1539 | } 1540 | }); 1541 | 1542 | this.append(' }'); 1543 | }; 1544 | 1545 | StringPrettyPrinter.prototype.append = function(value) { 1546 | this.string += value; 1547 | }; 1548 | 1549 | return function(value) { 1550 | var stringPrettyPrinter = new StringPrettyPrinter(); 1551 | stringPrettyPrinter.format(value); 1552 | return stringPrettyPrinter.string; 1553 | }; 1554 | }; 1555 | 1556 | getJasmineRequireObj().QueueRunner = function(j$) { 1557 | 1558 | function once(fn) { 1559 | var called = false; 1560 | return function() { 1561 | if (!called) { 1562 | called = true; 1563 | fn(); 1564 | } 1565 | }; 1566 | } 1567 | 1568 | function QueueRunner(attrs) { 1569 | this.fns = attrs.fns || []; 1570 | this.onComplete = attrs.onComplete || function() {}; 1571 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1572 | this.onException = attrs.onException || function() {}; 1573 | this.catchException = attrs.catchException || function() { return true; }; 1574 | this.enforceTimeout = attrs.enforceTimeout || function() { return false; }; 1575 | this.userContext = {}; 1576 | this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout}; 1577 | } 1578 | 1579 | QueueRunner.prototype.execute = function() { 1580 | this.run(this.fns, 0); 1581 | }; 1582 | 1583 | QueueRunner.prototype.run = function(fns, recursiveIndex) { 1584 | var length = fns.length, 1585 | self = this, 1586 | iterativeIndex; 1587 | 1588 | for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { 1589 | var fn = fns[iterativeIndex]; 1590 | if (fn.length > 0) { 1591 | return attemptAsync(fn); 1592 | } else { 1593 | attemptSync(fn); 1594 | } 1595 | } 1596 | 1597 | var runnerDone = iterativeIndex >= length; 1598 | 1599 | if (runnerDone) { 1600 | this.clearStack(this.onComplete); 1601 | } 1602 | 1603 | function attemptSync(fn) { 1604 | try { 1605 | fn.call(self.userContext); 1606 | } catch (e) { 1607 | handleException(e); 1608 | } 1609 | } 1610 | 1611 | function attemptAsync(fn) { 1612 | var clearTimeout = function () { 1613 | Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]); 1614 | }, 1615 | next = once(function () { 1616 | clearTimeout(timeoutId); 1617 | self.run(fns, iterativeIndex + 1); 1618 | }), 1619 | timeoutId; 1620 | 1621 | if (self.enforceTimeout()) { 1622 | timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() { 1623 | self.onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.')); 1624 | next(); 1625 | }, j$.DEFAULT_TIMEOUT_INTERVAL]]); 1626 | } 1627 | 1628 | try { 1629 | fn.call(self.userContext, next); 1630 | } catch (e) { 1631 | handleException(e); 1632 | next(); 1633 | } 1634 | } 1635 | 1636 | function handleException(e) { 1637 | self.onException(e); 1638 | if (!self.catchException(e)) { 1639 | //TODO: set a var when we catch an exception and 1640 | //use a finally block to close the loop in a nice way.. 1641 | throw e; 1642 | } 1643 | } 1644 | }; 1645 | 1646 | return QueueRunner; 1647 | }; 1648 | 1649 | getJasmineRequireObj().ReportDispatcher = function() { 1650 | function ReportDispatcher(methods) { 1651 | 1652 | var dispatchedMethods = methods || []; 1653 | 1654 | for (var i = 0; i < dispatchedMethods.length; i++) { 1655 | var method = dispatchedMethods[i]; 1656 | this[method] = (function(m) { 1657 | return function() { 1658 | dispatch(m, arguments); 1659 | }; 1660 | }(method)); 1661 | } 1662 | 1663 | var reporters = []; 1664 | 1665 | this.addReporter = function(reporter) { 1666 | reporters.push(reporter); 1667 | }; 1668 | 1669 | return this; 1670 | 1671 | function dispatch(method, args) { 1672 | for (var i = 0; i < reporters.length; i++) { 1673 | var reporter = reporters[i]; 1674 | if (reporter[method]) { 1675 | reporter[method].apply(reporter, args); 1676 | } 1677 | } 1678 | } 1679 | } 1680 | 1681 | return ReportDispatcher; 1682 | }; 1683 | 1684 | 1685 | getJasmineRequireObj().SpyStrategy = function() { 1686 | 1687 | function SpyStrategy(options) { 1688 | options = options || {}; 1689 | 1690 | var identity = options.name || 'unknown', 1691 | originalFn = options.fn || function() {}, 1692 | getSpy = options.getSpy || function() {}, 1693 | plan = function() {}; 1694 | 1695 | this.identity = function() { 1696 | return identity; 1697 | }; 1698 | 1699 | this.exec = function() { 1700 | return plan.apply(this, arguments); 1701 | }; 1702 | 1703 | this.callThrough = function() { 1704 | plan = originalFn; 1705 | return getSpy(); 1706 | }; 1707 | 1708 | this.returnValue = function(value) { 1709 | plan = function() { 1710 | return value; 1711 | }; 1712 | return getSpy(); 1713 | }; 1714 | 1715 | this.throwError = function(something) { 1716 | var error = (something instanceof Error) ? something : new Error(something); 1717 | plan = function() { 1718 | throw error; 1719 | }; 1720 | return getSpy(); 1721 | }; 1722 | 1723 | this.callFake = function(fn) { 1724 | plan = fn; 1725 | return getSpy(); 1726 | }; 1727 | 1728 | this.stub = function(fn) { 1729 | plan = function() {}; 1730 | return getSpy(); 1731 | }; 1732 | } 1733 | 1734 | return SpyStrategy; 1735 | }; 1736 | 1737 | getJasmineRequireObj().Suite = function() { 1738 | function Suite(attrs) { 1739 | this.env = attrs.env; 1740 | this.id = attrs.id; 1741 | this.parentSuite = attrs.parentSuite; 1742 | this.description = attrs.description; 1743 | this.onStart = attrs.onStart || function() {}; 1744 | this.resultCallback = attrs.resultCallback || function() {}; 1745 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1746 | 1747 | this.beforeFns = []; 1748 | this.afterFns = []; 1749 | this.queueRunner = attrs.queueRunner || function() {}; 1750 | this.disabled = false; 1751 | 1752 | this.children = []; 1753 | 1754 | this.result = { 1755 | id: this.id, 1756 | status: this.disabled ? 'disabled' : '', 1757 | description: this.description, 1758 | fullName: this.getFullName() 1759 | }; 1760 | } 1761 | 1762 | Suite.prototype.getFullName = function() { 1763 | var fullName = this.description; 1764 | for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { 1765 | if (parentSuite.parentSuite) { 1766 | fullName = parentSuite.description + ' ' + fullName; 1767 | } 1768 | } 1769 | return fullName; 1770 | }; 1771 | 1772 | Suite.prototype.disable = function() { 1773 | this.disabled = true; 1774 | }; 1775 | 1776 | Suite.prototype.beforeEach = function(fn) { 1777 | this.beforeFns.unshift(fn); 1778 | }; 1779 | 1780 | Suite.prototype.afterEach = function(fn) { 1781 | this.afterFns.unshift(fn); 1782 | }; 1783 | 1784 | Suite.prototype.addChild = function(child) { 1785 | this.children.push(child); 1786 | }; 1787 | 1788 | Suite.prototype.execute = function(onComplete) { 1789 | var self = this; 1790 | if (this.disabled) { 1791 | complete(); 1792 | return; 1793 | } 1794 | 1795 | var allFns = []; 1796 | 1797 | for (var i = 0; i < this.children.length; i++) { 1798 | allFns.push(wrapChildAsAsync(this.children[i])); 1799 | } 1800 | 1801 | this.onStart(this); 1802 | 1803 | this.queueRunner({ 1804 | fns: allFns, 1805 | onComplete: complete 1806 | }); 1807 | 1808 | function complete() { 1809 | self.resultCallback(self.result); 1810 | 1811 | if (onComplete) { 1812 | onComplete(); 1813 | } 1814 | } 1815 | 1816 | function wrapChildAsAsync(child) { 1817 | return function(done) { child.execute(done); }; 1818 | } 1819 | }; 1820 | 1821 | return Suite; 1822 | }; 1823 | 1824 | if (typeof window == void 0 && typeof exports == 'object') { 1825 | exports.Suite = jasmineRequire.Suite; 1826 | } 1827 | 1828 | getJasmineRequireObj().Timer = function() { 1829 | var defaultNow = (function(Date) { 1830 | return function() { return new Date().getTime(); }; 1831 | })(Date); 1832 | 1833 | function Timer(options) { 1834 | options = options || {}; 1835 | 1836 | var now = options.now || defaultNow, 1837 | startTime; 1838 | 1839 | this.start = function() { 1840 | startTime = now(); 1841 | }; 1842 | 1843 | this.elapsed = function() { 1844 | return now() - startTime; 1845 | }; 1846 | } 1847 | 1848 | return Timer; 1849 | }; 1850 | 1851 | getJasmineRequireObj().matchersUtil = function(j$) { 1852 | // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter? 1853 | 1854 | return { 1855 | equals: function(a, b, customTesters) { 1856 | customTesters = customTesters || []; 1857 | 1858 | return eq(a, b, [], [], customTesters); 1859 | }, 1860 | 1861 | contains: function(haystack, needle, customTesters) { 1862 | customTesters = customTesters || []; 1863 | 1864 | if (Object.prototype.toString.apply(haystack) === '[object Array]') { 1865 | for (var i = 0; i < haystack.length; i++) { 1866 | if (eq(haystack[i], needle, [], [], customTesters)) { 1867 | return true; 1868 | } 1869 | } 1870 | return false; 1871 | } 1872 | return !!haystack && haystack.indexOf(needle) >= 0; 1873 | }, 1874 | 1875 | buildFailureMessage: function() { 1876 | var args = Array.prototype.slice.call(arguments, 0), 1877 | matcherName = args[0], 1878 | isNot = args[1], 1879 | actual = args[2], 1880 | expected = args.slice(3), 1881 | englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); 1882 | 1883 | var message = 'Expected ' + 1884 | j$.pp(actual) + 1885 | (isNot ? ' not ' : ' ') + 1886 | englishyPredicate; 1887 | 1888 | if (expected.length > 0) { 1889 | for (var i = 0; i < expected.length; i++) { 1890 | if (i > 0) { 1891 | message += ','; 1892 | } 1893 | message += ' ' + j$.pp(expected[i]); 1894 | } 1895 | } 1896 | 1897 | return message + '.'; 1898 | } 1899 | }; 1900 | 1901 | // Equality function lovingly adapted from isEqual in 1902 | // [Underscore](http://underscorejs.org) 1903 | function eq(a, b, aStack, bStack, customTesters) { 1904 | var result = true; 1905 | 1906 | for (var i = 0; i < customTesters.length; i++) { 1907 | var customTesterResult = customTesters[i](a, b); 1908 | if (!j$.util.isUndefined(customTesterResult)) { 1909 | return customTesterResult; 1910 | } 1911 | } 1912 | 1913 | if (a instanceof j$.Any) { 1914 | result = a.jasmineMatches(b); 1915 | if (result) { 1916 | return true; 1917 | } 1918 | } 1919 | 1920 | if (b instanceof j$.Any) { 1921 | result = b.jasmineMatches(a); 1922 | if (result) { 1923 | return true; 1924 | } 1925 | } 1926 | 1927 | if (b instanceof j$.ObjectContaining) { 1928 | result = b.jasmineMatches(a); 1929 | if (result) { 1930 | return true; 1931 | } 1932 | } 1933 | 1934 | if (a instanceof Error && b instanceof Error) { 1935 | return a.message == b.message; 1936 | } 1937 | 1938 | // Identical objects are equal. `0 === -0`, but they aren't identical. 1939 | // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). 1940 | if (a === b) { return a !== 0 || 1 / a == 1 / b; } 1941 | // A strict comparison is necessary because `null == undefined`. 1942 | if (a === null || b === null) { return a === b; } 1943 | var className = Object.prototype.toString.call(a); 1944 | if (className != Object.prototype.toString.call(b)) { return false; } 1945 | switch (className) { 1946 | // Strings, numbers, dates, and booleans are compared by value. 1947 | case '[object String]': 1948 | // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is 1949 | // equivalent to `new String("5")`. 1950 | return a == String(b); 1951 | case '[object Number]': 1952 | // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for 1953 | // other numeric values. 1954 | return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b); 1955 | case '[object Date]': 1956 | case '[object Boolean]': 1957 | // Coerce dates and booleans to numeric primitive values. Dates are compared by their 1958 | // millisecond representations. Note that invalid dates with millisecond representations 1959 | // of `NaN` are not equivalent. 1960 | return +a == +b; 1961 | // RegExps are compared by their source patterns and flags. 1962 | case '[object RegExp]': 1963 | return a.source == b.source && 1964 | a.global == b.global && 1965 | a.multiline == b.multiline && 1966 | a.ignoreCase == b.ignoreCase; 1967 | } 1968 | if (typeof a != 'object' || typeof b != 'object') { return false; } 1969 | // Assume equality for cyclic structures. The algorithm for detecting cyclic 1970 | // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. 1971 | var length = aStack.length; 1972 | while (length--) { 1973 | // Linear search. Performance is inversely proportional to the number of 1974 | // unique nested structures. 1975 | if (aStack[length] == a) { return bStack[length] == b; } 1976 | } 1977 | // Add the first object to the stack of traversed objects. 1978 | aStack.push(a); 1979 | bStack.push(b); 1980 | var size = 0; 1981 | // Recursively compare objects and arrays. 1982 | if (className == '[object Array]') { 1983 | // Compare array lengths to determine if a deep comparison is necessary. 1984 | size = a.length; 1985 | result = size == b.length; 1986 | if (result) { 1987 | // Deep compare the contents, ignoring non-numeric properties. 1988 | while (size--) { 1989 | if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; } 1990 | } 1991 | } 1992 | } else { 1993 | // Objects with different constructors are not equivalent, but `Object`s 1994 | // from different frames are. 1995 | var aCtor = a.constructor, bCtor = b.constructor; 1996 | if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) && 1997 | isFunction(bCtor) && (bCtor instanceof bCtor))) { 1998 | return false; 1999 | } 2000 | // Deep compare objects. 2001 | for (var key in a) { 2002 | if (has(a, key)) { 2003 | // Count the expected number of properties. 2004 | size++; 2005 | // Deep compare each member. 2006 | if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; } 2007 | } 2008 | } 2009 | // Ensure that both objects contain the same number of properties. 2010 | if (result) { 2011 | for (key in b) { 2012 | if (has(b, key) && !(size--)) { break; } 2013 | } 2014 | result = !size; 2015 | } 2016 | } 2017 | // Remove the first object from the stack of traversed objects. 2018 | aStack.pop(); 2019 | bStack.pop(); 2020 | 2021 | return result; 2022 | 2023 | function has(obj, key) { 2024 | return obj.hasOwnProperty(key); 2025 | } 2026 | 2027 | function isFunction(obj) { 2028 | return typeof obj === 'function'; 2029 | } 2030 | } 2031 | }; 2032 | 2033 | getJasmineRequireObj().toBe = function() { 2034 | function toBe() { 2035 | return { 2036 | compare: function(actual, expected) { 2037 | return { 2038 | pass: actual === expected 2039 | }; 2040 | } 2041 | }; 2042 | } 2043 | 2044 | return toBe; 2045 | }; 2046 | 2047 | getJasmineRequireObj().toBeCloseTo = function() { 2048 | 2049 | function toBeCloseTo() { 2050 | return { 2051 | compare: function(actual, expected, precision) { 2052 | if (precision !== 0) { 2053 | precision = precision || 2; 2054 | } 2055 | 2056 | return { 2057 | pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) 2058 | }; 2059 | } 2060 | }; 2061 | } 2062 | 2063 | return toBeCloseTo; 2064 | }; 2065 | 2066 | getJasmineRequireObj().toBeDefined = function() { 2067 | function toBeDefined() { 2068 | return { 2069 | compare: function(actual) { 2070 | return { 2071 | pass: (void 0 !== actual) 2072 | }; 2073 | } 2074 | }; 2075 | } 2076 | 2077 | return toBeDefined; 2078 | }; 2079 | 2080 | getJasmineRequireObj().toBeFalsy = function() { 2081 | function toBeFalsy() { 2082 | return { 2083 | compare: function(actual) { 2084 | return { 2085 | pass: !!!actual 2086 | }; 2087 | } 2088 | }; 2089 | } 2090 | 2091 | return toBeFalsy; 2092 | }; 2093 | 2094 | getJasmineRequireObj().toBeGreaterThan = function() { 2095 | 2096 | function toBeGreaterThan() { 2097 | return { 2098 | compare: function(actual, expected) { 2099 | return { 2100 | pass: actual > expected 2101 | }; 2102 | } 2103 | }; 2104 | } 2105 | 2106 | return toBeGreaterThan; 2107 | }; 2108 | 2109 | 2110 | getJasmineRequireObj().toBeLessThan = function() { 2111 | function toBeLessThan() { 2112 | return { 2113 | 2114 | compare: function(actual, expected) { 2115 | return { 2116 | pass: actual < expected 2117 | }; 2118 | } 2119 | }; 2120 | } 2121 | 2122 | return toBeLessThan; 2123 | }; 2124 | getJasmineRequireObj().toBeNaN = function(j$) { 2125 | 2126 | function toBeNaN() { 2127 | return { 2128 | compare: function(actual) { 2129 | var result = { 2130 | pass: (actual !== actual) 2131 | }; 2132 | 2133 | if (result.pass) { 2134 | result.message = 'Expected actual not to be NaN.'; 2135 | } else { 2136 | result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; }; 2137 | } 2138 | 2139 | return result; 2140 | } 2141 | }; 2142 | } 2143 | 2144 | return toBeNaN; 2145 | }; 2146 | 2147 | getJasmineRequireObj().toBeNull = function() { 2148 | 2149 | function toBeNull() { 2150 | return { 2151 | compare: function(actual) { 2152 | return { 2153 | pass: actual === null 2154 | }; 2155 | } 2156 | }; 2157 | } 2158 | 2159 | return toBeNull; 2160 | }; 2161 | 2162 | getJasmineRequireObj().toBeTruthy = function() { 2163 | 2164 | function toBeTruthy() { 2165 | return { 2166 | compare: function(actual) { 2167 | return { 2168 | pass: !!actual 2169 | }; 2170 | } 2171 | }; 2172 | } 2173 | 2174 | return toBeTruthy; 2175 | }; 2176 | 2177 | getJasmineRequireObj().toBeUndefined = function() { 2178 | 2179 | function toBeUndefined() { 2180 | return { 2181 | compare: function(actual) { 2182 | return { 2183 | pass: void 0 === actual 2184 | }; 2185 | } 2186 | }; 2187 | } 2188 | 2189 | return toBeUndefined; 2190 | }; 2191 | 2192 | getJasmineRequireObj().toContain = function() { 2193 | function toContain(util, customEqualityTesters) { 2194 | customEqualityTesters = customEqualityTesters || []; 2195 | 2196 | return { 2197 | compare: function(actual, expected) { 2198 | 2199 | return { 2200 | pass: util.contains(actual, expected, customEqualityTesters) 2201 | }; 2202 | } 2203 | }; 2204 | } 2205 | 2206 | return toContain; 2207 | }; 2208 | 2209 | getJasmineRequireObj().toEqual = function() { 2210 | 2211 | function toEqual(util, customEqualityTesters) { 2212 | customEqualityTesters = customEqualityTesters || []; 2213 | 2214 | return { 2215 | compare: function(actual, expected) { 2216 | var result = { 2217 | pass: false 2218 | }; 2219 | 2220 | result.pass = util.equals(actual, expected, customEqualityTesters); 2221 | 2222 | return result; 2223 | } 2224 | }; 2225 | } 2226 | 2227 | return toEqual; 2228 | }; 2229 | 2230 | getJasmineRequireObj().toHaveBeenCalled = function(j$) { 2231 | 2232 | function toHaveBeenCalled() { 2233 | return { 2234 | compare: function(actual) { 2235 | var result = {}; 2236 | 2237 | if (!j$.isSpy(actual)) { 2238 | throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); 2239 | } 2240 | 2241 | if (arguments.length > 1) { 2242 | throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); 2243 | } 2244 | 2245 | result.pass = actual.calls.any(); 2246 | 2247 | result.message = result.pass ? 2248 | 'Expected spy ' + actual.and.identity() + ' not to have been called.' : 2249 | 'Expected spy ' + actual.and.identity() + ' to have been called.'; 2250 | 2251 | return result; 2252 | } 2253 | }; 2254 | } 2255 | 2256 | return toHaveBeenCalled; 2257 | }; 2258 | 2259 | getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { 2260 | 2261 | function toHaveBeenCalledWith(util, customEqualityTesters) { 2262 | return { 2263 | compare: function() { 2264 | var args = Array.prototype.slice.call(arguments, 0), 2265 | actual = args[0], 2266 | expectedArgs = args.slice(1), 2267 | result = { pass: false }; 2268 | 2269 | if (!j$.isSpy(actual)) { 2270 | throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); 2271 | } 2272 | 2273 | if (!actual.calls.any()) { 2274 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; }; 2275 | return result; 2276 | } 2277 | 2278 | if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) { 2279 | result.pass = true; 2280 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; }; 2281 | } else { 2282 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; }; 2283 | } 2284 | 2285 | return result; 2286 | } 2287 | }; 2288 | } 2289 | 2290 | return toHaveBeenCalledWith; 2291 | }; 2292 | 2293 | getJasmineRequireObj().toMatch = function() { 2294 | 2295 | function toMatch() { 2296 | return { 2297 | compare: function(actual, expected) { 2298 | var regexp = new RegExp(expected); 2299 | 2300 | return { 2301 | pass: regexp.test(actual) 2302 | }; 2303 | } 2304 | }; 2305 | } 2306 | 2307 | return toMatch; 2308 | }; 2309 | 2310 | getJasmineRequireObj().toThrow = function(j$) { 2311 | 2312 | function toThrow(util) { 2313 | return { 2314 | compare: function(actual, expected) { 2315 | var result = { pass: false }, 2316 | threw = false, 2317 | thrown; 2318 | 2319 | if (typeof actual != 'function') { 2320 | throw new Error('Actual is not a Function'); 2321 | } 2322 | 2323 | try { 2324 | actual(); 2325 | } catch (e) { 2326 | threw = true; 2327 | thrown = e; 2328 | } 2329 | 2330 | if (!threw) { 2331 | result.message = 'Expected function to throw an exception.'; 2332 | return result; 2333 | } 2334 | 2335 | if (arguments.length == 1) { 2336 | result.pass = true; 2337 | result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; }; 2338 | 2339 | return result; 2340 | } 2341 | 2342 | if (util.equals(thrown, expected)) { 2343 | result.pass = true; 2344 | result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; }; 2345 | } else { 2346 | result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; }; 2347 | } 2348 | 2349 | return result; 2350 | } 2351 | }; 2352 | } 2353 | 2354 | return toThrow; 2355 | }; 2356 | 2357 | getJasmineRequireObj().toThrowError = function(j$) { 2358 | function toThrowError (util) { 2359 | return { 2360 | compare: function(actual) { 2361 | var threw = false, 2362 | pass = {pass: true}, 2363 | fail = {pass: false}, 2364 | thrown, 2365 | errorType, 2366 | message, 2367 | regexp, 2368 | name, 2369 | constructorName; 2370 | 2371 | if (typeof actual != 'function') { 2372 | throw new Error('Actual is not a Function'); 2373 | } 2374 | 2375 | extractExpectedParams.apply(null, arguments); 2376 | 2377 | try { 2378 | actual(); 2379 | } catch (e) { 2380 | threw = true; 2381 | thrown = e; 2382 | } 2383 | 2384 | if (!threw) { 2385 | fail.message = 'Expected function to throw an Error.'; 2386 | return fail; 2387 | } 2388 | 2389 | if (!(thrown instanceof Error)) { 2390 | fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; }; 2391 | return fail; 2392 | } 2393 | 2394 | if (arguments.length == 1) { 2395 | pass.message = 'Expected function not to throw an Error, but it threw ' + fnNameFor(thrown) + '.'; 2396 | return pass; 2397 | } 2398 | 2399 | if (errorType) { 2400 | name = fnNameFor(errorType); 2401 | constructorName = fnNameFor(thrown.constructor); 2402 | } 2403 | 2404 | if (errorType && message) { 2405 | if (thrown.constructor == errorType && util.equals(thrown.message, message)) { 2406 | pass.message = function() { return 'Expected function not to throw ' + name + ' with message ' + j$.pp(message) + '.'; }; 2407 | return pass; 2408 | } else { 2409 | fail.message = function() { return 'Expected function to throw ' + name + ' with message ' + j$.pp(message) + 2410 | ', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; }; 2411 | return fail; 2412 | } 2413 | } 2414 | 2415 | if (errorType && regexp) { 2416 | if (thrown.constructor == errorType && regexp.test(thrown.message)) { 2417 | pass.message = function() { return 'Expected function not to throw ' + name + ' with message matching ' + j$.pp(regexp) + '.'; }; 2418 | return pass; 2419 | } else { 2420 | fail.message = function() { return 'Expected function to throw ' + name + ' with message matching ' + j$.pp(regexp) + 2421 | ', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; }; 2422 | return fail; 2423 | } 2424 | } 2425 | 2426 | if (errorType) { 2427 | if (thrown.constructor == errorType) { 2428 | pass.message = 'Expected function not to throw ' + name + '.'; 2429 | return pass; 2430 | } else { 2431 | fail.message = 'Expected function to throw ' + name + ', but it threw ' + constructorName + '.'; 2432 | return fail; 2433 | } 2434 | } 2435 | 2436 | if (message) { 2437 | if (thrown.message == message) { 2438 | pass.message = function() { return 'Expected function not to throw an exception with message ' + j$.pp(message) + '.'; }; 2439 | return pass; 2440 | } else { 2441 | fail.message = function() { return 'Expected function to throw an exception with message ' + j$.pp(message) + 2442 | ', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; }; 2443 | return fail; 2444 | } 2445 | } 2446 | 2447 | if (regexp) { 2448 | if (regexp.test(thrown.message)) { 2449 | pass.message = function() { return 'Expected function not to throw an exception with a message matching ' + j$.pp(regexp) + '.'; }; 2450 | return pass; 2451 | } else { 2452 | fail.message = function() { return 'Expected function to throw an exception with a message matching ' + j$.pp(regexp) + 2453 | ', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; }; 2454 | return fail; 2455 | } 2456 | } 2457 | 2458 | function fnNameFor(func) { 2459 | return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1]; 2460 | } 2461 | 2462 | function extractExpectedParams() { 2463 | if (arguments.length == 1) { 2464 | return; 2465 | } 2466 | 2467 | if (arguments.length == 2) { 2468 | var expected = arguments[1]; 2469 | 2470 | if (expected instanceof RegExp) { 2471 | regexp = expected; 2472 | } else if (typeof expected == 'string') { 2473 | message = expected; 2474 | } else if (checkForAnErrorType(expected)) { 2475 | errorType = expected; 2476 | } 2477 | 2478 | if (!(errorType || message || regexp)) { 2479 | throw new Error('Expected is not an Error, string, or RegExp.'); 2480 | } 2481 | } else { 2482 | if (checkForAnErrorType(arguments[1])) { 2483 | errorType = arguments[1]; 2484 | } else { 2485 | throw new Error('Expected error type is not an Error.'); 2486 | } 2487 | 2488 | if (arguments[2] instanceof RegExp) { 2489 | regexp = arguments[2]; 2490 | } else if (typeof arguments[2] == 'string') { 2491 | message = arguments[2]; 2492 | } else { 2493 | throw new Error('Expected error message is not a string or RegExp.'); 2494 | } 2495 | } 2496 | } 2497 | 2498 | function checkForAnErrorType(type) { 2499 | if (typeof type !== 'function') { 2500 | return false; 2501 | } 2502 | 2503 | var Surrogate = function() {}; 2504 | Surrogate.prototype = type.prototype; 2505 | return (new Surrogate()) instanceof Error; 2506 | } 2507 | } 2508 | }; 2509 | } 2510 | 2511 | return toThrowError; 2512 | }; 2513 | 2514 | getJasmineRequireObj().version = function() { 2515 | return '2.0.1'; 2516 | }; 2517 | -------------------------------------------------------------------------------- /lib/jasmine-2.0.1/jasmine_favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyroyse/gilded-rose-javascript/c8e40edc5b8de713d25c80a9139d091c469fa389/lib/jasmine-2.0.1/jasmine_favicon.png -------------------------------------------------------------------------------- /lib/jasmine-jquery-2.0.5/jasmine-jquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Jasmine-jQuery: a set of jQuery helpers for Jasmine tests. 3 | 4 | Version 2.0.5 5 | 6 | https://github.com/velesin/jasmine-jquery 7 | 8 | Copyright (c) 2010-2014 Wojciech Zawistowski, Travis Jeffery 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | "Software"), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be 19 | included in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 25 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 26 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 27 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | +function (window, jasmine, $) { "use strict"; 31 | 32 | jasmine.spiedEventsKey = function (selector, eventName) { 33 | return [$(selector).selector, eventName].toString() 34 | } 35 | 36 | jasmine.getFixtures = function () { 37 | return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures() 38 | } 39 | 40 | jasmine.getStyleFixtures = function () { 41 | return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures() 42 | } 43 | 44 | jasmine.Fixtures = function () { 45 | this.containerId = 'jasmine-fixtures' 46 | this.fixturesCache_ = {} 47 | this.fixturesPath = 'spec/javascripts/fixtures' 48 | } 49 | 50 | jasmine.Fixtures.prototype.set = function (html) { 51 | this.cleanUp() 52 | return this.createContainer_(html) 53 | } 54 | 55 | jasmine.Fixtures.prototype.appendSet= function (html) { 56 | this.addToContainer_(html) 57 | } 58 | 59 | jasmine.Fixtures.prototype.preload = function () { 60 | this.read.apply(this, arguments) 61 | } 62 | 63 | jasmine.Fixtures.prototype.load = function () { 64 | this.cleanUp() 65 | this.createContainer_(this.read.apply(this, arguments)) 66 | } 67 | 68 | jasmine.Fixtures.prototype.appendLoad = function () { 69 | this.addToContainer_(this.read.apply(this, arguments)) 70 | } 71 | 72 | jasmine.Fixtures.prototype.read = function () { 73 | var htmlChunks = [] 74 | , fixtureUrls = arguments 75 | 76 | for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) { 77 | htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex])) 78 | } 79 | 80 | return htmlChunks.join('') 81 | } 82 | 83 | jasmine.Fixtures.prototype.clearCache = function () { 84 | this.fixturesCache_ = {} 85 | } 86 | 87 | jasmine.Fixtures.prototype.cleanUp = function () { 88 | $('#' + this.containerId).remove() 89 | } 90 | 91 | jasmine.Fixtures.prototype.sandbox = function (attributes) { 92 | var attributesToSet = attributes || {} 93 | return $('
').attr(attributesToSet) 94 | } 95 | 96 | jasmine.Fixtures.prototype.createContainer_ = function (html) { 97 | var container = $('
') 98 | .attr('id', this.containerId) 99 | .html(html) 100 | 101 | $(document.body).append(container) 102 | return container 103 | } 104 | 105 | jasmine.Fixtures.prototype.addToContainer_ = function (html){ 106 | var container = $(document.body).find('#'+this.containerId).append(html) 107 | 108 | if (!container.length) { 109 | this.createContainer_(html) 110 | } 111 | } 112 | 113 | jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) { 114 | if (typeof this.fixturesCache_[url] === 'undefined') { 115 | this.loadFixtureIntoCache_(url) 116 | } 117 | return this.fixturesCache_[url] 118 | } 119 | 120 | jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) { 121 | var self = this 122 | , url = this.makeFixtureUrl_(relativeUrl) 123 | , htmlText = '' 124 | , request = $.ajax({ 125 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded 126 | cache: false, 127 | url: url, 128 | success: function (data, status, $xhr) { 129 | htmlText = $xhr.responseText 130 | } 131 | }).fail(function ($xhr, status, err) { 132 | throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')') 133 | }) 134 | 135 | var scripts = $($.parseHTML(htmlText, true)).find('script[src]') || []; 136 | 137 | scripts.each(function(){ 138 | $.ajax({ 139 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded 140 | cache: false, 141 | dataType: 'script', 142 | url: $(this).attr('src'), 143 | success: function (data, status, $xhr) { 144 | htmlText += '' 145 | }, 146 | error: function ($xhr, status, err) { 147 | throw new Error('Script could not be loaded: ' + scriptSrc + ' (status: ' + status + ', message: ' + err.message + ')') 148 | } 149 | }); 150 | }) 151 | 152 | self.fixturesCache_[relativeUrl] = htmlText; 153 | } 154 | 155 | jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){ 156 | return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl 157 | } 158 | 159 | jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) { 160 | return this[methodName].apply(this, passedArguments) 161 | } 162 | 163 | 164 | jasmine.StyleFixtures = function () { 165 | this.fixturesCache_ = {} 166 | this.fixturesNodes_ = [] 167 | this.fixturesPath = 'spec/javascripts/fixtures' 168 | } 169 | 170 | jasmine.StyleFixtures.prototype.set = function (css) { 171 | this.cleanUp() 172 | this.createStyle_(css) 173 | } 174 | 175 | jasmine.StyleFixtures.prototype.appendSet = function (css) { 176 | this.createStyle_(css) 177 | } 178 | 179 | jasmine.StyleFixtures.prototype.preload = function () { 180 | this.read_.apply(this, arguments) 181 | } 182 | 183 | jasmine.StyleFixtures.prototype.load = function () { 184 | this.cleanUp() 185 | this.createStyle_(this.read_.apply(this, arguments)) 186 | } 187 | 188 | jasmine.StyleFixtures.prototype.appendLoad = function () { 189 | this.createStyle_(this.read_.apply(this, arguments)) 190 | } 191 | 192 | jasmine.StyleFixtures.prototype.cleanUp = function () { 193 | while(this.fixturesNodes_.length) { 194 | this.fixturesNodes_.pop().remove() 195 | } 196 | } 197 | 198 | jasmine.StyleFixtures.prototype.createStyle_ = function (html) { 199 | var styleText = $('
').html(html).text() 200 | , style = $('') 201 | 202 | this.fixturesNodes_.push(style) 203 | $('head').append(style) 204 | } 205 | 206 | jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache 207 | jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read 208 | jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_ 209 | jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_ 210 | jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_ 211 | jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_ 212 | 213 | jasmine.getJSONFixtures = function () { 214 | return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures() 215 | } 216 | 217 | jasmine.JSONFixtures = function () { 218 | this.fixturesCache_ = {} 219 | this.fixturesPath = 'spec/javascripts/fixtures/json' 220 | } 221 | 222 | jasmine.JSONFixtures.prototype.load = function () { 223 | this.read.apply(this, arguments) 224 | return this.fixturesCache_ 225 | } 226 | 227 | jasmine.JSONFixtures.prototype.read = function () { 228 | var fixtureUrls = arguments 229 | 230 | for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) { 231 | this.getFixtureData_(fixtureUrls[urlIndex]) 232 | } 233 | 234 | return this.fixturesCache_ 235 | } 236 | 237 | jasmine.JSONFixtures.prototype.clearCache = function () { 238 | this.fixturesCache_ = {} 239 | } 240 | 241 | jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) { 242 | if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url) 243 | return this.fixturesCache_[url] 244 | } 245 | 246 | jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) { 247 | var self = this 248 | , url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl 249 | 250 | $.ajax({ 251 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded 252 | cache: false, 253 | dataType: 'json', 254 | url: url, 255 | success: function (data) { 256 | self.fixturesCache_[relativeUrl] = data 257 | }, 258 | error: function ($xhr, status, err) { 259 | throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')') 260 | } 261 | }) 262 | } 263 | 264 | jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) { 265 | return this[methodName].apply(this, passedArguments) 266 | } 267 | 268 | jasmine.jQuery = function () {} 269 | 270 | jasmine.jQuery.browserTagCaseIndependentHtml = function (html) { 271 | return $('
').append(html).html() 272 | } 273 | 274 | jasmine.jQuery.elementToString = function (element) { 275 | return $(element).map(function () { return this.outerHTML; }).toArray().join(', ') 276 | } 277 | 278 | var data = { 279 | spiedEvents: {} 280 | , handlers: [] 281 | } 282 | 283 | jasmine.jQuery.events = { 284 | spyOn: function (selector, eventName) { 285 | var handler = function (e) { 286 | data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments) 287 | } 288 | 289 | $(selector).on(eventName, handler) 290 | data.handlers.push(handler) 291 | 292 | return { 293 | selector: selector, 294 | eventName: eventName, 295 | handler: handler, 296 | reset: function (){ 297 | delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] 298 | } 299 | } 300 | }, 301 | 302 | args: function (selector, eventName) { 303 | var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] 304 | 305 | if (!actualArgs) { 306 | throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent." 307 | } 308 | 309 | return actualArgs 310 | }, 311 | 312 | wasTriggered: function (selector, eventName) { 313 | return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]) 314 | }, 315 | 316 | wasTriggeredWith: function (selector, eventName, expectedArgs, util, customEqualityTesters) { 317 | var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1) 318 | 319 | if (Object.prototype.toString.call(expectedArgs) !== '[object Array]') 320 | actualArgs = actualArgs[0] 321 | 322 | return util.equals(expectedArgs, actualArgs, customEqualityTesters) 323 | }, 324 | 325 | wasPrevented: function (selector, eventName) { 326 | var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] 327 | , e = args ? args[0] : undefined 328 | 329 | return e && e.isDefaultPrevented() 330 | }, 331 | 332 | wasStopped: function (selector, eventName) { 333 | var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] 334 | , e = args ? args[0] : undefined 335 | return e && e.isPropagationStopped() 336 | }, 337 | 338 | cleanUp: function () { 339 | data.spiedEvents = {} 340 | data.handlers = [] 341 | } 342 | } 343 | 344 | var hasProperty = function (actualValue, expectedValue) { 345 | if (expectedValue === undefined) 346 | return actualValue !== undefined 347 | 348 | return actualValue === expectedValue 349 | } 350 | 351 | beforeEach(function () { 352 | jasmine.addMatchers({ 353 | toHaveClass: function () { 354 | return { 355 | compare: function (actual, className) { 356 | return { pass: $(actual).hasClass(className) } 357 | } 358 | } 359 | }, 360 | 361 | toHaveCss: function () { 362 | return { 363 | compare: function (actual, css) { 364 | for (var prop in css){ 365 | var value = css[prop] 366 | // see issue #147 on gh 367 | ;if (value === 'auto' && $(actual).get(0).style[prop] === 'auto') continue 368 | if ($(actual).css(prop) !== value) return { pass: false } 369 | } 370 | return { pass: true } 371 | } 372 | } 373 | }, 374 | 375 | toBeVisible: function () { 376 | return { 377 | compare: function (actual) { 378 | return { pass: $(actual).is(':visible') } 379 | } 380 | } 381 | }, 382 | 383 | toBeHidden: function () { 384 | return { 385 | compare: function (actual) { 386 | return { pass: $(actual).is(':hidden') } 387 | } 388 | } 389 | }, 390 | 391 | toBeSelected: function () { 392 | return { 393 | compare: function (actual) { 394 | return { pass: $(actual).is(':selected') } 395 | } 396 | } 397 | }, 398 | 399 | toBeChecked: function () { 400 | return { 401 | compare: function (actual) { 402 | return { pass: $(actual).is(':checked') } 403 | } 404 | } 405 | }, 406 | 407 | toBeEmpty: function () { 408 | return { 409 | compare: function (actual) { 410 | return { pass: $(actual).is(':empty') } 411 | } 412 | } 413 | }, 414 | 415 | toBeInDOM: function () { 416 | return { 417 | compare: function (actual) { 418 | return { pass: $.contains(document.documentElement, $(actual)[0]) } 419 | } 420 | } 421 | }, 422 | 423 | toExist: function () { 424 | return { 425 | compare: function (actual) { 426 | return { pass: $(actual).length } 427 | } 428 | } 429 | }, 430 | 431 | toHaveLength: function () { 432 | return { 433 | compare: function (actual, length) { 434 | return { pass: $(actual).length === length } 435 | } 436 | } 437 | }, 438 | 439 | toHaveAttr: function () { 440 | return { 441 | compare: function (actual, attributeName, expectedAttributeValue) { 442 | return { pass: hasProperty($(actual).attr(attributeName), expectedAttributeValue) } 443 | } 444 | } 445 | }, 446 | 447 | toHaveProp: function () { 448 | return { 449 | compare: function (actual, propertyName, expectedPropertyValue) { 450 | return { pass: hasProperty($(actual).prop(propertyName), expectedPropertyValue) } 451 | } 452 | } 453 | }, 454 | 455 | toHaveId: function () { 456 | return { 457 | compare: function (actual, id) { 458 | return { pass: $(actual).attr('id') == id } 459 | } 460 | } 461 | }, 462 | 463 | toHaveHtml: function () { 464 | return { 465 | compare: function (actual, html) { 466 | return { pass: $(actual).html() == jasmine.jQuery.browserTagCaseIndependentHtml(html) } 467 | } 468 | } 469 | }, 470 | 471 | toContainHtml: function () { 472 | return { 473 | compare: function (actual, html) { 474 | var actualHtml = $(actual).html() 475 | , expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html) 476 | 477 | return { pass: (actualHtml.indexOf(expectedHtml) >= 0) } 478 | } 479 | } 480 | }, 481 | 482 | toHaveText: function () { 483 | return { 484 | compare: function (actual, text) { 485 | var actualText = $(actual).text() 486 | var trimmedText = $.trim(actualText) 487 | 488 | if (text && $.isFunction(text.test)) { 489 | return { pass: text.test(actualText) || text.test(trimmedText) } 490 | } else { 491 | return { pass: (actualText == text || trimmedText == text) } 492 | } 493 | } 494 | } 495 | }, 496 | 497 | toContainText: function () { 498 | return { 499 | compare: function (actual, text) { 500 | var trimmedText = $.trim($(actual).text()) 501 | 502 | if (text && $.isFunction(text.test)) { 503 | return { pass: text.test(trimmedText) } 504 | } else { 505 | return { pass: trimmedText.indexOf(text) != -1 } 506 | } 507 | } 508 | } 509 | }, 510 | 511 | toHaveValue: function () { 512 | return { 513 | compare: function (actual, value) { 514 | return { pass: $(actual).val() === value } 515 | } 516 | } 517 | }, 518 | 519 | toHaveData: function () { 520 | return { 521 | compare: function (actual, key, expectedValue) { 522 | return { pass: hasProperty($(actual).data(key), expectedValue) } 523 | } 524 | } 525 | }, 526 | 527 | toContainElement: function () { 528 | return { 529 | compare: function (actual, selector) { 530 | if (window.debug) debugger 531 | return { pass: $(actual).find(selector).length } 532 | } 533 | } 534 | }, 535 | 536 | toBeMatchedBy: function () { 537 | return { 538 | compare: function (actual, selector) { 539 | return { pass: $(actual).filter(selector).length } 540 | } 541 | } 542 | }, 543 | 544 | toBeDisabled: function () { 545 | return { 546 | compare: function (actual, selector) { 547 | return { pass: $(actual).is(':disabled') } 548 | } 549 | } 550 | }, 551 | 552 | toBeFocused: function (selector) { 553 | return { 554 | compare: function (actual, selector) { 555 | return { pass: $(actual)[0] === $(actual)[0].ownerDocument.activeElement } 556 | } 557 | } 558 | }, 559 | 560 | toHandle: function () { 561 | return { 562 | compare: function (actual, event) { 563 | var events = $._data($(actual).get(0), "events") 564 | 565 | if (!events || !event || typeof event !== "string") { 566 | return { pass: false } 567 | } 568 | 569 | var namespaces = event.split(".") 570 | , eventType = namespaces.shift() 571 | , sortedNamespaces = namespaces.slice(0).sort() 572 | , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") 573 | 574 | if (events[eventType] && namespaces.length) { 575 | for (var i = 0; i < events[eventType].length; i++) { 576 | var namespace = events[eventType][i].namespace 577 | 578 | if (namespaceRegExp.test(namespace)) 579 | return { pass: true } 580 | } 581 | } else { 582 | return { pass: (events[eventType] && events[eventType].length > 0) } 583 | } 584 | 585 | return { pass: false } 586 | } 587 | } 588 | }, 589 | 590 | toHandleWith: function () { 591 | return { 592 | compare: function (actual, eventName, eventHandler) { 593 | var normalizedEventName = eventName.split('.')[0] 594 | , stack = $._data($(actual).get(0), "events")[normalizedEventName] 595 | 596 | for (var i = 0; i < stack.length; i++) { 597 | if (stack[i].handler == eventHandler) return { pass: true } 598 | } 599 | 600 | return { pass: false } 601 | } 602 | } 603 | }, 604 | 605 | toHaveBeenTriggeredOn: function () { 606 | return { 607 | compare: function (actual, selector) { 608 | var result = { pass: jasmine.jQuery.events.wasTriggered(selector, actual) } 609 | 610 | result.message = result.pass ? 611 | "Expected event " + $(actual) + " not to have been triggered on " + selector : 612 | "Expected event " + $(actual) + " to have been triggered on " + selector 613 | 614 | return result; 615 | } 616 | } 617 | }, 618 | 619 | toHaveBeenTriggered: function (){ 620 | return { 621 | compare: function (actual) { 622 | var eventName = actual.eventName 623 | , selector = actual.selector 624 | , result = { pass: jasmine.jQuery.events.wasTriggered(selector, eventName) } 625 | 626 | result.message = result.pass ? 627 | "Expected event " + eventName + " not to have been triggered on " + selector : 628 | "Expected event " + eventName + " to have been triggered on " + selector 629 | 630 | return result 631 | } 632 | } 633 | }, 634 | 635 | toHaveBeenTriggeredOnAndWith: function (j$, customEqualityTesters) { 636 | return { 637 | compare: function (actual, selector, expectedArgs) { 638 | var wasTriggered = jasmine.jQuery.events.wasTriggered(selector, actual) 639 | , result = { pass: wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, actual, expectedArgs, j$, customEqualityTesters) } 640 | 641 | if (wasTriggered) { 642 | var actualArgs = jasmine.jQuery.events.args(selector, actual, expectedArgs)[1] 643 | result.message = result.pass ? 644 | "Expected event " + actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) : 645 | "Expected event " + actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) 646 | 647 | } else { 648 | // todo check on this 649 | result.message = result.pass ? 650 | "Expected event " + actual + " not to have been triggered on " + selector : 651 | "Expected event " + actual + " to have been triggered on " + selector 652 | } 653 | 654 | return result 655 | } 656 | } 657 | }, 658 | 659 | toHaveBeenPreventedOn: function () { 660 | return { 661 | compare: function (actual, selector) { 662 | var result = { pass: jasmine.jQuery.events.wasPrevented(selector, actual) } 663 | 664 | result.message = result.pass ? 665 | "Expected event " + actual + " not to have been prevented on " + selector : 666 | "Expected event " + actual + " to have been prevented on " + selector 667 | 668 | return result 669 | } 670 | } 671 | }, 672 | 673 | toHaveBeenPrevented: function () { 674 | return { 675 | compare: function (actual) { 676 | var eventName = actual.eventName 677 | , selector = actual.selector 678 | , result = { pass: jasmine.jQuery.events.wasPrevented(selector, eventName) } 679 | 680 | result.message = result.pass ? 681 | "Expected event " + eventName + " not to have been prevented on " + selector : 682 | "Expected event " + eventName + " to have been prevented on " + selector 683 | 684 | return result 685 | } 686 | } 687 | }, 688 | 689 | toHaveBeenStoppedOn: function () { 690 | return { 691 | compare: function (actual, selector) { 692 | var result = { pass: jasmine.jQuery.events.wasStopped(selector, actual) } 693 | 694 | result.message = result.pass ? 695 | "Expected event " + actual + " not to have been stopped on " + selector : 696 | "Expected event " + actual + " to have been stopped on " + selector 697 | 698 | return result; 699 | } 700 | } 701 | }, 702 | 703 | toHaveBeenStopped: function () { 704 | return { 705 | compare: function (actual) { 706 | var eventName = actual.eventName 707 | , selector = actual.selector 708 | , result = { pass: jasmine.jQuery.events.wasStopped(selector, eventName) } 709 | 710 | result.message = result.pass ? 711 | "Expected event " + eventName + " not to have been stopped on " + selector : 712 | "Expected event " + eventName + " to have been stopped on " + selector 713 | 714 | return result 715 | } 716 | } 717 | } 718 | }) 719 | 720 | jasmine.getEnv().addCustomEqualityTester(function(a, b) { 721 | if (a && b) { 722 | if (a instanceof $ || jasmine.isDomNode(a)) { 723 | var $a = $(a) 724 | 725 | if (b instanceof $) 726 | return $a.length == b.length && a.is(b) 727 | 728 | return $a.is(b); 729 | } 730 | 731 | if (b instanceof $ || jasmine.isDomNode(b)) { 732 | var $b = $(b) 733 | 734 | if (a instanceof $) 735 | return a.length == $b.length && $b.is(a) 736 | 737 | return $(b).is(a); 738 | } 739 | } 740 | }) 741 | 742 | jasmine.getEnv().addCustomEqualityTester(function (a, b) { 743 | if (a instanceof $ && b instanceof $ && a.size() == b.size()) 744 | return a.is(b) 745 | }) 746 | }) 747 | 748 | afterEach(function () { 749 | jasmine.getFixtures().cleanUp() 750 | jasmine.getStyleFixtures().cleanUp() 751 | jasmine.jQuery.events.cleanUp() 752 | }) 753 | 754 | window.readFixtures = function () { 755 | return jasmine.getFixtures().proxyCallTo_('read', arguments) 756 | } 757 | 758 | window.preloadFixtures = function () { 759 | jasmine.getFixtures().proxyCallTo_('preload', arguments) 760 | } 761 | 762 | window.loadFixtures = function () { 763 | jasmine.getFixtures().proxyCallTo_('load', arguments) 764 | } 765 | 766 | window.appendLoadFixtures = function () { 767 | jasmine.getFixtures().proxyCallTo_('appendLoad', arguments) 768 | } 769 | 770 | window.setFixtures = function (html) { 771 | return jasmine.getFixtures().proxyCallTo_('set', arguments) 772 | } 773 | 774 | window.appendSetFixtures = function () { 775 | jasmine.getFixtures().proxyCallTo_('appendSet', arguments) 776 | } 777 | 778 | window.sandbox = function (attributes) { 779 | return jasmine.getFixtures().sandbox(attributes) 780 | } 781 | 782 | window.spyOnEvent = function (selector, eventName) { 783 | return jasmine.jQuery.events.spyOn(selector, eventName) 784 | } 785 | 786 | window.preloadStyleFixtures = function () { 787 | jasmine.getStyleFixtures().proxyCallTo_('preload', arguments) 788 | } 789 | 790 | window.loadStyleFixtures = function () { 791 | jasmine.getStyleFixtures().proxyCallTo_('load', arguments) 792 | } 793 | 794 | window.appendLoadStyleFixtures = function () { 795 | jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments) 796 | } 797 | 798 | window.setStyleFixtures = function (html) { 799 | jasmine.getStyleFixtures().proxyCallTo_('set', arguments) 800 | } 801 | 802 | window.appendSetStyleFixtures = function (html) { 803 | jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments) 804 | } 805 | 806 | window.loadJSONFixtures = function () { 807 | return jasmine.getJSONFixtures().proxyCallTo_('load', arguments) 808 | } 809 | 810 | window.getJSONFixture = function (url) { 811 | return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url] 812 | } 813 | }(window, window.jasmine, window.jQuery); 814 | -------------------------------------------------------------------------------- /spec/gilded_rose_spec.js: -------------------------------------------------------------------------------- 1 | describe("Gilded Rose", function() { 2 | 3 | it("should do something", function() { 4 | update_quality(); 5 | }); 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /spec/spec_helper.js: -------------------------------------------------------------------------------- 1 | var when = function(description, callback) { 2 | describe('when '.concat(description), callback); 3 | }; 4 | -------------------------------------------------------------------------------- /src/gilded_rose.js: -------------------------------------------------------------------------------- 1 | function Item(name, sell_in, quality) { 2 | this.name = name; 3 | this.sell_in = sell_in; 4 | this.quality = quality; 5 | } 6 | 7 | var items = [] 8 | 9 | items.push(new Item('+5 Dexterity Vest', 10, 20)); 10 | items.push(new Item('Aged Brie', 2, 0)); 11 | items.push(new Item('Elixir of the Mongoose', 5, 7)); 12 | items.push(new Item('Sulfuras, Hand of Ragnaros', 0, 80)); 13 | items.push(new Item('Backstage passes to a TAFKAL80ETC concert', 15, 20)); 14 | items.push(new Item('Conjured Mana Cake', 3, 6)); 15 | 16 | function update_quality() { 17 | for (var i = 0; i < items.length; i++) { 18 | if (items[i].name != 'Aged Brie' && items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { 19 | if (items[i].quality > 0) { 20 | if (items[i].name != 'Sulfuras, Hand of Ragnaros') { 21 | items[i].quality = items[i].quality - 1 22 | } 23 | } 24 | } else { 25 | if (items[i].quality < 50) { 26 | items[i].quality = items[i].quality + 1 27 | if (items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { 28 | if (items[i].sell_in < 11) { 29 | if (items[i].quality < 50) { 30 | items[i].quality = items[i].quality + 1 31 | } 32 | } 33 | if (items[i].sell_in < 6) { 34 | if (items[i].quality < 50) { 35 | items[i].quality = items[i].quality + 1 36 | } 37 | } 38 | } 39 | } 40 | } 41 | if (items[i].name != 'Sulfuras, Hand of Ragnaros') { 42 | items[i].sell_in = items[i].sell_in - 1; 43 | } 44 | if (items[i].sell_in < 0) { 45 | if (items[i].name != 'Aged Brie') { 46 | if (items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { 47 | if (items[i].quality > 0) { 48 | if (items[i].name != 'Sulfuras, Hand of Ragnaros') { 49 | items[i].quality = items[i].quality - 1 50 | } 51 | } 52 | } else { 53 | items[i].quality = items[i].quality - items[i].quality 54 | } 55 | } else { 56 | if (items[i].quality < 50) { 57 | items[i].quality = items[i].quality + 1 58 | } 59 | } 60 | } 61 | } 62 | } 63 | --------------------------------------------------------------------------------