dwf: made Jasmine & Jasmine.Reporters namespaces; the instance of Jasmine is now just jasmine.

This commit is contained in:
pivotal 2008-12-08 13:01:06 -08:00
parent b8a8dc4562
commit 821fb54934
9 changed files with 157 additions and 158 deletions

View File

@ -129,20 +129,37 @@ Suites are executed in the order in which `describe()` calls are made, usually i
You don't need a DOM to run your tests, but you do need a page on which to load & execute your JS. Include the `jasmine.js` file in a script tag as well as the JS file with your specs. You can also use this page for reporting. More on that in a moment. You don't need a DOM to run your tests, but you do need a page on which to load & execute your JS. Include the `jasmine.js` file in a script tag as well as the JS file with your specs. You can also use this page for reporting. More on that in a moment.
// include example.html Here's the example HTML file (in `jasmine/example`):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Example</title>
<script type="text/javascript" src="../lib/jasmine.js"></script>
<script type="text/javascript" src="example.js"></script>
<link type="text/css" rel="stylesheet" href="../lib/jasmine.css"/>
</head>
<body>
<h1>
Running Jasmine Example Specs
</h1>
<div id="results"></div>
<script type="text/javascript">
jasmine.execute();
setTimeout(function () {
document.getElementById('results').innerHTML = 'It\'s alive! :' +
(jasmine.currentRunner.results.passedCount === 1);
}, 250);
</script>
</body>
</html>
### Reports ### Reports
no reporting yet other than Runner.results, which is walkable If a reporter exists on the Jasmine instance (named `jasmine`), it will be called when each spec, suite and the overall runner complete. If you're at the single-spec result level, you'll get a spec description, whether it passed or failed, and what the failure message was. At the suite & runner report level, you'll get the total specs run so far, the passed counts, failed counts, and a description (of the suite or runner).
#### JSON Reporter There is a `Jasmine.Reporters` namespace for you to see how to handle reporting. See the file `json_reporter.js`, which takes the results objects and turns them into JSON strings, for two examples of how to make the results callbacks work for you.
Coming soon.
#### HTML Reporter
Coming soon.
#### In-line HTML Reporter
Coming soon.
### Custom Matchers ### Custom Matchers
@ -157,6 +174,13 @@ A Matcher has a method name, takes an expected value as it's only parameter, has
Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests. Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests.
### Limitations
You can only have one instance of Jasmine (which is a container for a runner) running at any given time. As you can see from `bootstrap.js`, this means you have to wait until a runner is done before defining suites & specs for another runner.
This is a bit sloppy and will be fixed at some point - but it allows for a nicer syntax when defining your specs. For now we expect this to be fine as most of the time having multiple suites is sufficient for isolating application-level code.
Contributing and Tests Contributing and Tests
---------------------- ----------------------
@ -171,17 +195,13 @@ Your contributions are welcome. Please submit tests with your pull request.
* [Davis W. Frank](dwfrank@pivotallabs.com), Pivotal Labs * [Davis W. Frank](dwfrank@pivotallabs.com), Pivotal Labs
* [Rajan Agaskar](rajan@pivotallabs.com), Pivotal Labs * [Rajan Agaskar](rajan@pivotallabs.com), Pivotal Labs
## Acknowledgments
A big shout out to the various JavaScript test framework authors, especially TJ for [JSpec](http://github.com/visionmedia/jspec/tree/master) - we played with it a bit before deciding that we really needed to roll our own.
## TODO List ## TODO List
In no particular order: In no particular order:
* protect the global-ness of some variables & functions
* Suite beforeAll and afterAll functions
* add a description to runs() * add a description to runs()
* suite.beforeAll and suite.afterAll
* JSON reporter
* HTML reporter
* HTML reporter (callback driven)

View File

@ -13,9 +13,10 @@
</h1> </h1>
<div id="results"></div> <div id="results"></div>
<script type="text/javascript"> <script type="text/javascript">
Jasmine.execute(); jasmine.execute();
setTimeout(function () { setTimeout(function () {
document.getElementById('results').innerHTML = 'It\'s alive! :' + (Jasmine.results.passedCount ==1); document.getElementById('results').innerHTML = 'It\'s alive! :' +
(jasmine.currentRunner.results.passedCount === 1);
}, 250); }, 250);
</script> </script>
</body> </body>

View File

@ -89,10 +89,10 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="json_reporter.js" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="json_reporter.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js"> <entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="6" column="36" selection-start="284" selection-end="284" vertical-scroll-proportion="0.11025145"> <state line="36" column="7" selection-start="1033" selection-end="1033" vertical-scroll-proportion="0.6615087">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -101,16 +101,16 @@
<file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="53" column="39" selection-start="1542" selection-end="1542" vertical-scroll-proportion="0.5166163"> <state line="751" column="29" selection-start="22512" selection-end="22512" vertical-scroll-proportion="0.44749755">
<folding /> <folding />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true"> <file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="198" column="17" selection-start="4329" selection-end="4329" vertical-scroll-proportion="0.7901354"> <state line="155" column="4" selection-start="3291" selection-end="3291" vertical-scroll-proportion="-2.7886906">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -119,7 +119,7 @@
<file leaf-file-name="example.html" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="example.html" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/example.html"> <entry file="file://$PROJECT_DIR$/example/example.html">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="4" column="24" selection-start="145" selection-end="145" vertical-scroll-proportion="0.078756474"> <state line="0" column="0" selection-start="0" selection-end="721" vertical-scroll-proportion="0.0">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -430,22 +430,22 @@
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.21091811" order="0" /> <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.21091811" order="0" />
<window_info id="RDoc" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="RDoc" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32841328" order="1" /> <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32841328" order="1" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="1" /> <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.25" order="1" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="14" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="6" /> <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="6" />
<window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" /> <window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="6" />
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="11" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" /> <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="4" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="1" /> <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="1" />
<window_info id="Maven projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" /> <window_info id="Maven projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="5" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="12" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="2" /> <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="2" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" /> <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="0" /> <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="0" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="4" /> <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="4" />
<window_info id="IDEtalk Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="IDEtalk Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="13" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="9" />
<window_info id="Duplicates" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="Duplicates" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="10" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="0" /> <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="0" />
<window_info id="Web" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" /> <window_info id="Web" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="2" />
<window_info id="EJB" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="3" /> <window_info id="EJB" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="3" />
@ -507,6 +507,23 @@
</GetOptions> </GetOptions>
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor">
<state line="10" column="7" selection-start="500" selection-end="500" vertical-scroll-proportion="0.19689119">
<folding />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="751" column="29" selection-start="22512" selection-end="22512" vertical-scroll-proportion="0.44749755">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.css"> <entry file="file://$PROJECT_DIR$/lib/jasmine.css">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="16" column="8" selection-start="315" selection-end="315" vertical-scroll-proportion="0.29400387"> <state line="16" column="8" selection-start="315" selection-end="315" vertical-scroll-proportion="0.29400387">
@ -521,19 +538,16 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.html"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="10" column="7" selection-start="500" selection-end="500" vertical-scroll-proportion="0.19689119"> <state line="155" column="4" selection-start="3291" selection-end="3291" vertical-scroll-proportion="-2.7886906">
<folding /> <folding />
</state> </state>
</provider> </provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/example.html"> <entry file="file://$PROJECT_DIR$/example/example.html">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="4" column="24" selection-start="145" selection-end="145" vertical-scroll-proportion="0.078756474"> <state line="0" column="0" selection-start="0" selection-end="721" vertical-scroll-proportion="0.0">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -543,21 +557,7 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js"> <entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="6" column="36" selection-start="284" selection-end="284" vertical-scroll-proportion="0.11025145"> <state line="36" column="7" selection-start="1033" selection-end="1033" vertical-scroll-proportion="0.6615087">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="39" selection-start="1542" selection-end="1542" vertical-scroll-proportion="0.5166163">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="198" column="17" selection-start="4329" selection-end="4329" vertical-scroll-proportion="0.7901354">
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@ -152,17 +152,35 @@ var queuedFunction = function(func, timeout, spec) {
* Jasmine * Jasmine
******************************************************************************/ ******************************************************************************/
var Jasmine = {}
Jasmine.init = function () {
var that = {
currentSpec: null,
currentSuite: null,
currentRunner: null,
execute: function () {
that.currentRunner.execute();
}
}
return that;
}
var jasmine = Jasmine.init();
/* /*
* Matchers methods; add your own with Matchers.method() * Jasmine.Matchers methods; add your own with Jasmine.Matchers.method() - don't forget to write a test
*
*/ */
Matchers = function (actual, results) { Jasmine.Matchers = function (actual, results) {
this.actual = actual; this.actual = actual;
this.passing_message = 'Passed.' this.passing_message = 'Passed.'
this.results = results || nestedResults(); this.results = results || nestedResults();
} }
Matchers.method('report', function (result, failing_message) { Jasmine.Matchers.method('report', function (result, failing_message) {
this.results.push({ this.results.push({
passed: result, passed: result,
@ -172,12 +190,12 @@ Matchers.method('report', function (result, failing_message) {
return result; return result;
}); });
Matchers.method('should_equal', function (expected) { Jasmine.Matchers.method('should_equal', function (expected) {
return this.report((this.actual === expected), return this.report((this.actual === expected),
'Expected ' + expected + ' but got ' + this.actual + '.'); 'Expected ' + expected + ' but got ' + this.actual + '.');
}); });
Matchers.method('should_not_equal', function (expected) { Jasmine.Matchers.method('should_not_equal', function (expected) {
return this.report((this.actual !== expected), return this.report((this.actual !== expected),
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.'); 'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
}); });
@ -196,7 +214,7 @@ var it = function (description, func) {
results: nestedResults(), results: nestedResults(),
expects_that: function (actual) { expects_that: function (actual) {
return new Matchers(actual, that.results); return new Jasmine.Matchers(actual, that.results);
}, },
waits: function (timeout) { waits: function (timeout) {
@ -209,8 +227,8 @@ var it = function (description, func) {
}, },
finishCallback: function () { finishCallback: function () {
if (Jasmine.reporter) { if (jasmine.reporter) {
Jasmine.reporter.reportSpecResults(that.results); jasmine.reporter.reportSpecResults(that.results);
} }
}, },
@ -243,8 +261,8 @@ var it = function (description, func) {
that.runs = addToQueue; that.runs = addToQueue;
currentSuite.specs.push(that); jasmine.currentSuite.specs.push(that);
currentSpec = that; jasmine.currentSpec = that;
if (func) { if (func) {
func(); func();
@ -255,19 +273,19 @@ var it = function (description, func) {
} }
var runs = function (func) { var runs = function (func) {
currentSpec.runs(func); jasmine.currentSpec.runs(func);
} }
var waits = function (timeout) { var waits = function (timeout) {
currentSpec.waits(timeout); jasmine.currentSpec.waits(timeout);
} }
var beforeEach = function (beforeEach) { var beforeEach = function (beforeEach) {
currentSuite.beforeEach = beforeEach; jasmine.currentSuite.beforeEach = beforeEach;
} }
var afterEach = function (afterEach) { var afterEach = function (afterEach) {
currentSuite.afterEach = afterEach; jasmine.currentSuite.afterEach = afterEach;
} }
var describe = function (description, spec_definitions) { var describe = function (description, spec_definitions) {
@ -276,16 +294,16 @@ var describe = function (description, spec_definitions) {
that.description = description; that.description = description;
that.specs = that.actions; that.specs = that.actions;
currentSuite = that; jasmine.currentSuite = that;
Jasmine.suites.push(that); jasmine.currentRunner.suites.push(that);
spec_definitions(); spec_definitions();
that.results.description = description; that.results.description = description;
that.finishCallback = function () { that.finishCallback = function () {
if (Jasmine.reporter) { if (jasmine.reporter) {
Jasmine.reporter.reportSuiteResults(that.results); jasmine.reporter.reportSuiteResults(that.results);
} }
} }
@ -299,26 +317,24 @@ var Runner = function () {
that.results.description = 'All Jasmine Suites'; that.results.description = 'All Jasmine Suites';
that.finishCallback = function () { that.finishCallback = function () {
if (that.reporter) { if (jasmine.reporter) {
that.reporter.reportRunnerResults(that.results); jasmine.reporter.reportRunnerResults(that.results);
} }
} }
Jasmine = that; jasmine.currentRunner = that;
return that; return that;
} }
var Jasmine = Runner(); jasmine.currentRunner = Runner();
var currentSuite;
var currentSpec;
/* JasmineReporters.reporter /* JasmineReporters.reporter
* Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to
* descendants of this object to do something with the results (see json_reporter.js) * descendants of this object to do something with the results (see json_reporter.js)
*/ */
var JasmineReporters = {}; Jasmine.Reporters = {};
JasmineReporters.reporter = function (callbacks) { Jasmine.Reporters.reporter = function (callbacks) {
var that = { var that = {
callbacks: callbacks || {}, callbacks: callbacks || {},

View File

@ -3,8 +3,8 @@
* Basic reporter that keeps a JSON string of the most recent Spec, Suite or Runner * Basic reporter that keeps a JSON string of the most recent Spec, Suite or Runner
* result. Calling application can then do whatever it wants/needs with the string; * result. Calling application can then do whatever it wants/needs with the string;
*/ */
JasmineReporters.JSON = function () { Jasmine.Reporters.JSON = function () {
var that = JasmineReporters.reporter(); var that = Jasmine.Reporters.reporter();
that.specJSON = ''; that.specJSON = '';
that.suiteJSON = ''; that.suiteJSON = '';
that.runnerJSON = ''; that.runnerJSON = '';
@ -27,7 +27,7 @@ JasmineReporters.JSON = function () {
return that; return that;
} }
var domWriter = function (elementId) { Jasmine.Reporters.domWriter = function (elementId) {
var that = { var that = {
element: document.getElementById(elementId), element: document.getElementById(elementId),
@ -43,10 +43,10 @@ var domWriter = function (elementId) {
return that; return that;
} }
JasmineReporters.JSONtoDOM = function (elementId) { Jasmine.Reporters.JSONtoDOM = function (elementId) {
var that = JasmineReporters.JSON(); var that = Jasmine.Reporters.JSON();
that.domWriter = domWriter(elementId); that.domWriter = Jasmine.Reporters.domWriter(elementId);
var writeRunnerResults = function (results) { var writeRunnerResults = function (results) {
that.domWriter.write(Object.toJSON(results)); that.domWriter.write(Object.toJSON(results));
@ -56,18 +56,3 @@ JasmineReporters.JSONtoDOM = function (elementId) {
return that; return that;
} }
//JasmineReporters.IncrementalJSON = function (elementId) {
// var that = JasmineReporters.reporter(elementId);
//
// that.reportSpecResults = function (results) {
// that.output = Object.toJSON(results);
// if (that.element) {
// that.element.innerHTML += that.output;
// }
// }
//
// return that;
//}

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>

View File

@ -1,3 +0,0 @@
main.file=
platform.active=Ruby
source.encoding=UTF-8

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.ruby.rubyproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
<name>jasmine</name>
<source-roots/>
<test-roots/>
</data>
</configuration>
</project>

69
test/bootstrap.js vendored
View File

@ -42,19 +42,19 @@ var reporter = function () {
}(); }();
var testMatchersComparisons = function () { var testMatchersComparisons = function () {
var expected = new Matchers(true); var expected = new Jasmine.Matchers(true);
reporter.test(expected.should_equal(true), reporter.test(expected.should_equal(true),
'expects_that(true).should_equal(true) returned false'); 'expects_that(true).should_equal(true) returned false');
expected = new Matchers(false); expected = new Jasmine.Matchers(false);
reporter.test(!(expected.should_equal(true)), reporter.test(!(expected.should_equal(true)),
'expects_that(true).should_equal(true) returned true'); 'expects_that(true).should_equal(true) returned true');
expected = new Matchers(true); expected = new Jasmine.Matchers(true);
reporter.test(expected.should_not_equal(false), reporter.test(expected.should_not_equal(false),
'expects_that(true).should_not_equal(false) retruned false'); 'expects_that(true).should_not_equal(false) retruned false');
expected = new Matchers(true); expected = new Jasmine.Matchers(true);
reporter.test(!(expected.should_not_equal(true)), reporter.test(!(expected.should_not_equal(true)),
'expects_that(true).should_not_equal(false) retruned true'); 'expects_that(true).should_not_equal(false) retruned true');
} }
@ -62,7 +62,7 @@ var testMatchersComparisons = function () {
var testMatchersReporting = function () { var testMatchersReporting = function () {
var results = []; var results = [];
var expected = new Matchers(true, results); var expected = new Jasmine.Matchers(true, results);
expected.should_equal(true); expected.should_equal(true);
expected.should_equal(false); expected.should_equal(false);
@ -76,14 +76,14 @@ var testMatchersReporting = function () {
"Second spec did pass"); "Second spec did pass");
results = []; results = [];
expected = new Matchers(false, results); expected = new Jasmine.Matchers(false, results);
expected.should_equal(true); expected.should_equal(true);
reporter.test((results[0].message == 'Expected true but got false.'), reporter.test((results[0].message == 'Expected true but got false.'),
"Failed expectation didn't test the failure message"); "Failed expectation didn't test the failure message");
results = []; results = [];
expected = new Matchers(true, results); expected = new Jasmine.Matchers(true, results);
expected.should_equal(true); expected.should_equal(true);
reporter.test((results[0].message == 'Passed.'), reporter.test((results[0].message == 'Passed.'),
@ -502,7 +502,7 @@ var testRunner = function() {
it('should be a test'); it('should be a test');
}); });
reporter.test((runner.suites.length === 1), reporter.test((runner.suites.length === 1),
"Runner expected one suite"); "Runner expected one suite, got " + runner.suites.length);
runner = Runner(); runner = Runner();
describe('one suite description', function () { describe('one suite description', function () {
@ -535,7 +535,7 @@ var testRunner = function() {
setTimeout(function () { setTimeout(function () {
reporter.test((runner.suites.length === 2), reporter.test((runner.suites.length === 2),
"Runner expected two suites"); "Runner expected two suites, got " + runner.suites.length);
reporter.test((runner.suites[0].specs[0].results.results[0].passed === true), reporter.test((runner.suites[0].specs[0].results.results[0].passed === true),
"Runner should have run specs in first suite"); "Runner should have run specs in first suite");
reporter.test((runner.suites[1].specs[0].results.results[0].passed === false), reporter.test((runner.suites[1].specs[0].results.results[0].passed === false),
@ -649,11 +649,9 @@ var testResults = function () {
} }
var testReporterWithCallbacks = function () { var testReporterWithCallbacks = function () {
var foo = 0; jasmine = Jasmine.init();
var bar = 0;
var baz = 0;
var runner = Runner(); var runner = Runner();
describe('Suite for JSON Reporter with Callbacks', function () { describe('Suite for JSON Reporter with Callbacks', function () {
it('should be a test', function() { it('should be a test', function() {
runs(function () { runs(function () {
@ -675,31 +673,24 @@ var testReporterWithCallbacks = function () {
}); });
var foo = 0;
var bar = 0;
var baz = 0;
var specCallback = function (results) { var specCallback = function (results) { foo++; }
foo++; var suiteCallback = function (results) { bar++; }
} var runnerCallback = function (results) { baz++; }
var suiteCallback = function (results) { jasmine.reporter = Jasmine.Reporters.reporter({
bar++;
}
var runnerCallback = function (results) {
baz++;
}
callbackFunctions = {
specCallback: specCallback, specCallback: specCallback,
suiteCallback: suiteCallback, suiteCallback: suiteCallback,
runnerCallback: runnerCallback runnerCallback: runnerCallback
} });
runner.reporter = JasmineReporters.reporter(callbackFunctions);
runner.execute(); runner.execute();
setTimeout(function() { setTimeout(function() {
reporter.test((foo === 3), reporter.test((foo === 3),
'foo was expected to be 1, was ' + foo); 'foo was expected to be 3, was ' + foo);
reporter.test((bar === 2), reporter.test((bar === 2),
'bar was expected to be 2, was ' + bar); 'bar was expected to be 2, was ' + bar);
reporter.test((baz === 1), reporter.test((baz === 1),
@ -709,7 +700,9 @@ var testReporterWithCallbacks = function () {
} }
var testJSONReporter = function () { var testJSONReporter = function () {
jasmine = Jasmine.init();
var runner = Runner(); var runner = Runner();
describe('Suite for JSON Reporter, NO DOM', function () { describe('Suite for JSON Reporter, NO DOM', function () {
it('should be a test', function() { it('should be a test', function() {
runs(function () { runs(function () {
@ -718,7 +711,7 @@ var testJSONReporter = function () {
}); });
}); });
runner.reporter = JasmineReporters.JSON(); jasmine.reporter = Jasmine.Reporters.JSON();
runner.execute(); runner.execute();
@ -727,17 +720,17 @@ var testJSONReporter = function () {
var expectedSuiteJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}'; var expectedSuiteJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}';
var expectedRunnerJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}'; var expectedRunnerJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}';
specJSON = runner.reporter.specJSON; specJSON = jasmine.reporter.specJSON;
reporter.test((specJSON === expectedSpecJSON), reporter.test((specJSON === expectedSpecJSON),
'JSON Reporter does not have the expected Spec results report.<br /> <b>Expected:</b><br /> ' + expectedSpecJSON + 'JSON Reporter does not have the expected Spec results report.<br /> <b>Expected:</b><br /> ' + expectedSpecJSON +
'<br /><b>Got:</b><br /> ' + specJSON); '<br /><b>Got:</b><br /> ' + specJSON);
suiteJSON = runner.reporter.suiteJSON; suiteJSON = jasmine.reporter.suiteJSON;
reporter.test((suiteJSON === expectedSuiteJSON), reporter.test((suiteJSON === expectedSuiteJSON),
'JSON Reporter does not have the expected Suite results report.<br /> <b>Expected:</b><br /> ' + expectedSuiteJSON + 'JSON Reporter does not have the expected Suite results report.<br /> <b>Expected:</b><br /> ' + expectedSuiteJSON +
'<br /><b>Got:</b><br /> ' + suiteJSON); '<br /><b>Got:</b><br /> ' + suiteJSON);
runnerJSON = runner.reporter.runnerJSON; runnerJSON = jasmine.reporter.runnerJSON;
reporter.test((runnerJSON === expectedRunnerJSON), reporter.test((runnerJSON === expectedRunnerJSON),
'JSON Reporter does not have the expected Runner results report.<br /> <b>Expected:</b><br /> ' + expectedRunnerJSON + 'JSON Reporter does not have the expected Runner results report.<br /> <b>Expected:</b><br /> ' + expectedRunnerJSON +
'<br /><b>Got:</b><br /> ' + runnerJSON); '<br /><b>Got:</b><br /> ' + runnerJSON);
@ -745,7 +738,9 @@ var testJSONReporter = function () {
} }
var testJSONReporterWithDOM = function () { var testJSONReporterWithDOM = function () {
jasmine = Jasmine.init();
var runner = Runner(); var runner = Runner();
describe('Suite for JSON Reporter/DOM', function () { describe('Suite for JSON Reporter/DOM', function () {
it('should be a test', function() { it('should be a test', function() {
runs(function () { runs(function () {
@ -754,7 +749,7 @@ var testJSONReporterWithDOM = function () {
}); });
}); });
runner.reporter = JasmineReporters.JSONtoDOM('json_reporter_results'); jasmine.reporter = Jasmine.Reporters.JSONtoDOM('json_reporter_results');
runner.execute(); runner.execute();
setTimeout(function() { setTimeout(function() {
@ -787,15 +782,15 @@ var runTests = function () {
}, 2000); }, 2000);
setTimeout(function () { setTimeout(function () {
testJSONReporter(); testJSONReporter();
}, 2750); }, 3500);
setTimeout(function () { setTimeout(function () {
testJSONReporterWithDOM(); testJSONReporterWithDOM();
}, 3000); }, 5000);
setTimeout(function() { setTimeout(function() {
$('spinner').hide(); $('spinner').hide();
reporter.summary(); reporter.summary();
}, 4500); }, 6000);
} }