diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ba72ec6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.idea/inspectionProfiles/ \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..bcadfe1a --- /dev/null +++ b/Rakefile @@ -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 + diff --git a/example/example.html b/example/example.html deleted file mode 100644 index 000eb99f..00000000 --- a/example/example.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - Jasmine Example - - - - - -

- Running Jasmine Example Specs -

-
- - - - - diff --git a/example/example.js b/example/example.js deleted file mode 100644 index 4c03804e..00000000 --- a/example/example.js +++ /dev/null @@ -1,7 +0,0 @@ -describe('one suite description', function () { - it('should be a test', function() { - runs(function () { - expect(true).toEqual(true); - }); - }); -}); \ No newline at end of file diff --git a/lib/TrivialReporter.js b/lib/TrivialReporter.js index 14c35ea8..a7bd1144 100644 --- a/lib/TrivialReporter.js +++ b/lib/TrivialReporter.js @@ -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() { + }; + } +} diff --git a/lib/example_suite.html b/lib/example_suite.html new file mode 100644 index 00000000..b59d189a --- /dev/null +++ b/lib/example_suite.html @@ -0,0 +1,50 @@ + + + + Jasmine Test Runner + + + + + + + + + + + + + + + + + diff --git a/lib/example_suite.js b/lib/example_suite.js new file mode 100644 index 00000000..494539e4 --- /dev/null +++ b/lib/example_suite.js @@ -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); + }); + }); +}); \ No newline at end of file diff --git a/lib/jasmine.js b/lib/jasmine.js new file mode 100644 index 00000000..8db90549 --- /dev/null +++ b/lib/jasmine.js @@ -0,0 +1,1409 @@ +/* + * Jasmine internal classes & objects + */ + +/** @namespace */ +var jasmine = {}; + +jasmine.unimplementedMethod_ = function() { + throw new Error("unimplemented method"); +}; + +jasmine.bindOriginal_ = function(base, name) { + var original = base[name]; + return function() { + return original.apply(base, arguments); + }; +}; + +jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); +jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); +jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); +jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); + +jasmine.MessageResult = function(text) { + this.type = 'MessageResult'; + this.text = text; + this.trace = new Error(); // todo: test better +}; + +jasmine.ExpectationResult = function(passed, message, details) { + this.type = 'ExpectationResult'; + this.passed = passed; + this.message = message; + this.details = details; + this.trace = new Error(message); // todo: test better +}; + +jasmine.getEnv = function() { + return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); +}; + +jasmine.isArray_ = function(value) { + return value && + typeof value === 'object' && + typeof value.length === 'number' && + typeof value.splice === 'function' && + !(value.propertyIsEnumerable('length')); +}; + +jasmine.pp = function(value) { + var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); + stringPrettyPrinter.format(value); + return stringPrettyPrinter.string; +}; + +jasmine.isDomNode = function(obj) { + return obj['nodeType'] > 0; +}; + +jasmine.any = function(clazz) { + return new jasmine.Matchers.Any(clazz); +}; + +jasmine.createSpy = function(name) { + var spyObj = function() { + spyObj.wasCalled = true; + spyObj.callCount++; + var args = jasmine.util.argsToArray(arguments); + spyObj.mostRecentCall = { + object: this, + args: args + }; + spyObj.argsForCall.push(args); + return spyObj.plan.apply(this, arguments); + }; + + spyObj.identity = name || 'unknown'; + spyObj.isSpy = true; + + spyObj.plan = function() { + }; + + spyObj.andCallThrough = function() { + spyObj.plan = spyObj.originalValue; + return spyObj; + }; + spyObj.andReturn = function(value) { + spyObj.plan = function() { + return value; + }; + return spyObj; + }; + spyObj.andThrow = function(exceptionMsg) { + spyObj.plan = function() { + throw exceptionMsg; + }; + return spyObj; + }; + spyObj.andCallFake = function(fakeFunc) { + spyObj.plan = fakeFunc; + return spyObj; + }; + spyObj.reset = function() { + spyObj.wasCalled = false; + spyObj.callCount = 0; + spyObj.argsForCall = []; + spyObj.mostRecentCall = {}; + }; + spyObj.reset(); + + return spyObj; +}; + +jasmine.createSpyObj = function(baseName, methodNames) { + var obj = {}; + for (var i = 0; i < methodNames.length; i++) { + obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); + } + return obj; +}; + +jasmine.log = function(message) { + jasmine.getEnv().currentSpec.getResults().log(message); +}; + +var spyOn = function(obj, methodName) { + return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +}; + +var it = function(desc, func) { + return jasmine.getEnv().it(desc, func); +}; + +var xit = function(desc, func) { + return jasmine.getEnv().xit(desc, func); +}; + +var expect = function(actual) { + return jasmine.getEnv().currentSpec.expect(actual); +}; + +var runs = function(func) { + jasmine.getEnv().currentSpec.runs(func); +}; + +var waits = function(timeout) { + jasmine.getEnv().currentSpec.waits(timeout); +}; + +var waitsFor = function(timeout, latchFunction, message) { + jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +}; + +var beforeEach = function(beforeEachFunction) { + jasmine.getEnv().beforeEach(beforeEachFunction); +}; + +var afterEach = function(afterEachFunction) { + jasmine.getEnv().afterEach(afterEachFunction); +}; + +var describe = function(description, specDefinitions) { + return jasmine.getEnv().describe(description, specDefinitions); +}; + +var xdescribe = function(description, specDefinitions) { + return jasmine.getEnv().xdescribe(description, specDefinitions); +}; + +jasmine.XmlHttpRequest = XMLHttpRequest; + +// Provide the XMLHttpRequest class for IE 5.x-6.x: +if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { + try { + return new ActiveXObject("Msxml2.XMLHTTP.6.0"); + } catch(e) { + } + try { + return new ActiveXObject("Msxml2.XMLHTTP.3.0"); + } catch(e) { + } + try { + return new ActiveXObject("Msxml2.XMLHTTP"); + } catch(e) { + } + try { + return new ActiveXObject("Microsoft.XMLHTTP"); + } catch(e) { + } + throw new Error("This browser does not support XMLHttpRequest."); +}; + +jasmine.include = function(url, opt_global) { + if (opt_global) { + document.write(' - - + + @@ -19,7 +19,7 @@ - + diff --git a/spec/bootstrap.js b/spec/bootstrap.js index 6fc42627..342b10e5 100755 --- a/spec/bootstrap.js +++ b/spec/bootstrap.js @@ -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"; diff --git a/spec/runner.html b/spec/runner.html index 0ae2cbf0..fe4bbd87 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -18,11 +18,11 @@ + -