Merge branch 'pivotal'

This commit is contained in:
Davis W. Frank 2009-06-28 13:26:45 -07:00
commit 7e956f77f5
16 changed files with 1509 additions and 255 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea/
.idea/inspectionProfiles/

14
Rakefile Normal file
View File

@ -0,0 +1,14 @@
desc 'Builds lib/jasmine from source'
task :build do
# these files must be better
sources = ["src/base.js", "src/util.js", "src/Env.js"]
sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)}
jasmine = File.new('lib/jasmine.js', 'w')
sources.each do |source_filename|
jasmine.puts(File.read(source_filename))
end
end

View File

@ -1,25 +0,0 @@
<!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.getEnv().execute();
setTimeout(function () {
document.getElementById('results').innerHTML = 'It\'s alive! :' +
(jasmine.getEnv().currentRunner.getResults().passedCount === 1);
}, 250);
</script>
</body>
</html>

View File

@ -1,7 +0,0 @@
describe('one suite description', function () {
it('should be a test', function() {
runs(function () {
expect(true).toEqual(true);
});
});
});

View File

@ -59,3 +59,13 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
jasmine.TrivialReporter.prototype.log = function() {
console.log.apply(console, arguments);
};
//protect against console.log incidents
if (!("console" in window) || !("firebug" in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0, len = names.length; i < len; ++i) {
window.console[names[i]] = function() {
};
}
}

50
lib/example_suite.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
</head>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="jasmine.js"></script>
<script type="text/javascript" src="TrivialReporter.js"></script>
<script type="text/javascript">
jasmine.include('example_suite.js', true);
</script>
<style type="text/css">
.spec {
margin: 5px;
}
.passed {
background-color: lightgreen;
}
.failed {
background-color: pink;
}
.resultMessage {
white-space: pre;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
}
</style>
<body>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
jasmineEnv.reporter = new jasmine.TrivialReporter();
jasmineEnv.execute();
</script>
</body>
</html>

11
lib/example_suite.js Normal file
View File

@ -0,0 +1,11 @@
describe('ExampleSuite', function () {
it('should have a passing test', function() {
expect(true).toEqual(true);
});
describe('Nested Describe', function () {
it('should also have a passing test', function () {
expect(true).toEqual(true);
});
});
});

1409
lib/jasmine.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,35 +0,0 @@
/*
* jasmine.Reporters.JSON --
* 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;
*/
jasmine.Reporters.JSON = function () {
var toJSON = function(object){
return JSON.stringify(object);
};
var that = jasmine.Reporters.reporter();
that.specJSON = '';
that.suiteJSON = '';
that.runnerJSON = '';
var saveSpecResults = function (spec) {
that.specJSON = toJSON(spec.getResults());
};
that.reportSpecResults = saveSpecResults;
var saveSuiteResults = function (suite) {
that.suiteJSON = toJSON(suite.getResults());
};
that.reportSuiteResults = saveSuiteResults;
var saveRunnerResults = function (runner) {
that.runnerJSON = toJSON(runner.getResults());
};
that.reportRunnerResults = saveRunnerResults;
this.log = function (str) {
console.log(str);
};
that.toJSON = toJSON;
return that;
};

View File

@ -5,8 +5,8 @@
<title>Jasmine Tests</title>
<script type="text/javascript" src="lib/json2.js"></script>
<script type="text/javascript" src="lib/mock-timeout.js"></script>
<script type="text/javascript" src="../lib/jsUnitMockTimeout.js"></script>
<script type="text/javascript" src="../src/base.js"></script>
<script type="text/javascript" src="../src/util.js"></script>
<script type="text/javascript" src="../src/Env.js"></script>
@ -19,7 +19,7 @@
<script type="text/javascript" src="../src/Runner.js"></script>
<script type="text/javascript" src="../src/Spec.js"></script>
<script type="text/javascript" src="../src/Suite.js"></script>
<script type="text/javascript" src="../lib/json_reporter.js"></script>
<script type="text/javascript" src="../src/mock-timeout.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>

59
spec/bootstrap.js vendored
View File

@ -54,6 +54,7 @@ Reporter.prototype.summary = function () {
var reporter = new Reporter();
function runSuite(filename) {
console.log(filename);
var suite = jasmine.include(filename);
suite.execute();
emitSuiteResults(filename, suite);
@ -128,59 +129,17 @@ var testRunnerFinishCallback = function () {
"Runner finish callback was not called");
};
var testHandlesBlankSpecs = function () {
var env = newJasmineEnv();
env.describe('Suite for handles blank specs', function () {
env.it('should be a test with a blank runs block', function() {
this.runs(function () {
});
});
env.it('should be a blank (empty function) test', function() {
});
});
var runner = env.currentRunner;
runner.execute();
reporter.test((runner.suites[0].results.getItems().length === 2),
'Should have found 2 spec results, got ' + runner.suites[0].results.getItems().length);
reporter.test((runner.suites[0].results.passedCount === 2),
'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
};
var testResultsAliasing = function () {
var env = newJasmineEnv();
env.describe('Suite for result aliasing test', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
};
var runTests = function () {
document.getElementById('spinner').style.display = "";
runSuite('PrettyPrintTest.js');
runSuite('MatchersTest.js');
runSuite('SpecRunningTest.js');
runSuite('NestedResultsTest.js');
runSuite('ReporterTest.js');
runSuite('RunnerTest.js');
runSuite('JsonReporterTest.js');
runSuite('SpyTest.js');
runSuite('ExceptionsTest.js');
// testResultsAliasing(); // this appears to do nothing.
// handle blank specs will work later.
// testHandlesBlankSpecs();
runSuite('suites/PrettyPrintTest.js');
runSuite('suites/MatchersTest.js');
runSuite('suites/SpecRunningTest.js');
runSuite('suites/NestedResultsTest.js');
runSuite('suites/ReporterTest.js');
runSuite('suites/RunnerTest.js');
runSuite('suites/SpyTest.js');
runSuite('suites/ExceptionsTest.js');
reporter.summary();
document.getElementById('spinner').style.display = "none";

View File

@ -18,11 +18,11 @@
<script type="text/javascript" src="../src/Runner.js"></script>
<script type="text/javascript" src="../src/Spec.js"></script>
<script type="text/javascript" src="../src/Suite.js"></script>
<script type="text/javascript" src="../src/mock-timeout.js"></script>
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
<script type="text/javascript" src="../lib/json_reporter.js"></script>
<script type="text/javascript" src="lib/mock-timeout.js"></script>
<script type="text/javascript">
jasmine.include('suites/ExceptionsTest.js', true);

View File

@ -1,53 +0,0 @@
describe("jasmine.Reporters.JSON", function () {
var env;
var expectedSpecJSON;
var expectedSuiteJSON;
var expectedRunnerJSON;
beforeEach(function() {
env = new jasmine.Env();
env.describe('Suite for JSON Reporter, NO DOM', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
env.reporter = jasmine.Reporters.JSON();
var runner = env.currentRunner;
runner.execute();
expectedSpecJSON = {
"totalCount":1,"passedCount":1,"failedCount":0,"skipped":false,
"items_":[{"type": 'ExpectationResult', "passed":true,"message":"Passed.", trace: jasmine.any(Object), details: jasmine.any(Object)}],
"description":"should be a test"
};
expectedSuiteJSON = {
"totalCount":1,"passedCount":1,"failedCount":0,"skipped":false, items_:[]
};
expectedRunnerJSON = {
"totalCount":1,"passedCount":1,"failedCount":0,"skipped":false, items_:[]
};
});
it("should report spec results as json", function() {
var specJSON = env.reporter.specJSON;
expect(JSON.parse(specJSON)).toEqual(expectedSpecJSON);
});
it("should report test results as json", function() {
var suiteJSON = env.reporter.suiteJSON;
expect(JSON.parse(suiteJSON)).toEqual(expectedSuiteJSON);
});
it("should report test results as json", function() {
var runnerJSON = env.reporter.runnerJSON;
expect(JSON.parse(runnerJSON)).toEqual(expectedRunnerJSON);
});
});

View File

@ -1,81 +0,0 @@
// Mock setTimeout, clearTimeout
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
var Clock = {
timeoutsMade: 0,
scheduledFunctions: {},
nowMillis: 0,
reset: function() {
this.scheduledFunctions = {};
this.nowMillis = 0;
this.timeoutsMade = 0;
},
tick: function(millis) {
var oldMillis = this.nowMillis;
var newMillis = oldMillis + millis;
this.runFunctionsWithinRange(oldMillis, newMillis);
this.nowMillis = newMillis;
},
runFunctionsWithinRange: function(oldMillis, nowMillis) {
var scheduledFunc;
var funcsToRun = [];
for (var timeoutKey in this.scheduledFunctions) {
scheduledFunc = this.scheduledFunctions[timeoutKey];
if (scheduledFunc != undefined &&
scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = undefined;
}
}
if (funcsToRun.length > 0) {
funcsToRun.sort(function(a, b) {
return a.runAtMillis - b.runAtMillis;
});
for (var i = 0; i < funcsToRun.length; ++i) {
try {
this.nowMillis = funcsToRun[i].runAtMillis;
funcsToRun[i].funcToCall();
if (funcsToRun[i].recurring) {
Clock.scheduleFunction(funcsToRun[i].timeoutKey,
funcsToRun[i].funcToCall,
funcsToRun[i].millis,
true);
}
} catch(e) {
}
}
this.runFunctionsWithinRange(oldMillis, nowMillis);
}
},
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
Clock.scheduledFunctions[timeoutKey] = {
runAtMillis: Clock.nowMillis + millis,
funcToCall: funcToCall,
recurring: recurring,
timeoutKey: timeoutKey,
millis: millis
};
}
};
function setTimeout(funcToCall, millis) {
Clock.timeoutsMade = Clock.timeoutsMade + 1;
Clock.scheduleFunction(Clock.timeoutsMade, funcToCall, millis, false);
return Clock.timeoutsMade;
}
function setInterval(funcToCall, millis) {
Clock.timeoutsMade = Clock.timeoutsMade + 1;
Clock.scheduleFunction(Clock.timeoutsMade, funcToCall, millis, true);
return Clock.timeoutsMade;
}
function clearTimeout(timeoutKey) {
Clock.scheduledFunctions[timeoutKey] = undefined;
}
function clearInterval(timeoutKey) {
Clock.scheduledFunctions[timeoutKey] = undefined;
}