├── .gitignore
├── src
├── version.json
├── WaitsBlock.js
├── Block.js
├── Reporter.js
├── MultiReporter.js
├── Reporters.js
├── WaitsForBlock.js
├── util.js
├── Runner.js
├── NestedResults.js
├── Suite.js
├── Queue.js
├── JsApiReporter.js
├── PrettyPrinter.js
├── mock-timeout.js
├── Spec.js
├── Env.js
└── Matchers.js
├── images
├── go.png
├── fail.png
├── go-16.png
├── fail-16.png
├── pending.png
├── spinner.gif
├── pending-16.png
├── question-bk.png
└── questionbk-16.png
├── examples
├── html
│ ├── spec
│ │ └── example_suite.js
│ └── example_suite.html
└── ruby
│ ├── spec
│ ├── example
│ │ └── example_spec.js
│ ├── jasmine_spec.rb
│ └── jasmine_helper.rb
│ └── Rakefile
├── geminstaller.yml
├── spec
├── jasmine_spec.rb
├── suites
│ ├── UtilSpec.js
│ ├── QueueSpec.js
│ ├── MockClockSpec.js
│ ├── MultiReporterSpec.js
│ ├── ReporterSpec.js
│ ├── EnvSpec.js
│ ├── NestedResultsSpec.js
│ ├── JsApiReporterSpec.js
│ ├── SuiteSpec.js
│ ├── PrettyPrintSpec.js
│ ├── SpecSpec.js
│ ├── ExceptionsSpec.js
│ ├── TrivialReporterSpec.js
│ ├── SpySpec.js
│ └── RunnerSpec.js
├── jasmine_helper.rb
└── runner.html
├── lib
├── consolex.js
├── jasmine.css
└── TrivialReporter.js
├── MIT.LICENSE
├── contrib
└── ruby
│ ├── run.html
│ ├── spec
│ └── jasmine_runner_spec.rb
│ ├── jasmine_spec_builder.rb
│ └── jasmine_runner.rb
├── Rakefile
└── doc
├── symbols
├── src
│ ├── src_WaitsBlock.js.html
│ ├── src_Block.js.html
│ ├── src_Reporter.js.html
│ ├── src_Reporters.js.html
│ ├── src_MultiReporter.js.html
│ └── src_WaitsForBlock.js.html
├── jasmine.MultiReporter.html
└── jasmine.Block.html
├── index.html
└── files.html
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .svn/
3 |
--------------------------------------------------------------------------------
/src/version.json:
--------------------------------------------------------------------------------
1 | {
2 | "major": 0,
3 | "minor": 10,
4 | "build": 0
5 | }
--------------------------------------------------------------------------------
/images/go.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/go.png
--------------------------------------------------------------------------------
/images/fail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/fail.png
--------------------------------------------------------------------------------
/images/go-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/go-16.png
--------------------------------------------------------------------------------
/images/fail-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/fail-16.png
--------------------------------------------------------------------------------
/images/pending.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/pending.png
--------------------------------------------------------------------------------
/images/spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/spinner.gif
--------------------------------------------------------------------------------
/images/pending-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/pending-16.png
--------------------------------------------------------------------------------
/images/question-bk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/question-bk.png
--------------------------------------------------------------------------------
/images/questionbk-16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subtleGradient/jasmine/master/images/questionbk-16.png
--------------------------------------------------------------------------------
/examples/html/spec/example_suite.js:
--------------------------------------------------------------------------------
1 | describe('ExampleSuite', function () {
2 | it('should have a passing test', function() {
3 | expect(true).toEqual(true);
4 | });
5 |
6 | describe('Nested Describe', function () {
7 | it('should also have a passing test', function () {
8 | expect(true).toEqual(true);
9 | });
10 | });
11 | });
--------------------------------------------------------------------------------
/examples/ruby/spec/example/example_spec.js:
--------------------------------------------------------------------------------
1 | describe('ExampleSuite', function () {
2 | it('should have a passing test', function() {
3 | expect(true).toEqual(true);
4 | });
5 |
6 | describe('Nested Describe', function () {
7 | it('should also have a passing test', function () {
8 | expect(true).toEqual(true);
9 | });
10 | });
11 | });
--------------------------------------------------------------------------------
/geminstaller.yml:
--------------------------------------------------------------------------------
1 | ---
2 | gems:
3 | - name: rake
4 | version: 0.8.7
5 | - name: ragaskar-jsdoc_helper
6 | version: 0.0.2.1
7 | - name: json
8 | version: 1.1.9
9 | - name: pivotal-selenium-rc
10 | version: 1.11.20090610
11 | - name: rack
12 | version: 1.0.0
13 | - name: thin
14 | version: 1.2.4
15 | - name: eventmachine
16 | version: 0.12.8
17 | - name: rspec
18 | version: 1.2.9
19 | - name: selenium-client
20 | version: 1.2.17
21 |
--------------------------------------------------------------------------------
/src/WaitsBlock.js:
--------------------------------------------------------------------------------
1 | jasmine.WaitsBlock = function(env, timeout, spec) {
2 | this.timeout = timeout;
3 | jasmine.Block.call(this, env, null, spec);
4 | };
5 |
6 | jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
7 |
8 | jasmine.WaitsBlock.prototype.execute = function (onComplete) {
9 | this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
10 | this.env.setTimeout(function () {
11 | onComplete();
12 | }, this.timeout);
13 | };
14 |
--------------------------------------------------------------------------------
/src/Block.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Blocks are functions with executable code that make up a spec.
3 | *
4 | * @constructor
5 | * @param {jasmine.Env} env
6 | * @param {Function} func
7 | * @param {jasmine.Spec} spec
8 | */
9 | jasmine.Block = function(env, func, spec) {
10 | this.env = env;
11 | this.func = func;
12 | this.spec = spec;
13 | };
14 |
15 | jasmine.Block.prototype.execute = function(onComplete) {
16 | try {
17 | this.func.apply(this.spec);
18 | } catch (e) {
19 | this.spec.fail(e);
20 | }
21 | onComplete();
22 | };
--------------------------------------------------------------------------------
/src/Reporter.js:
--------------------------------------------------------------------------------
1 | /** No-op base class for Jasmine reporters.
2 | *
3 | * @constructor
4 | */
5 | jasmine.Reporter = function() {
6 | };
7 |
8 | //noinspection JSUnusedLocalSymbols
9 | jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
10 | };
11 |
12 | //noinspection JSUnusedLocalSymbols
13 | jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
14 | };
15 |
16 | //noinspection JSUnusedLocalSymbols
17 | jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
18 | };
19 |
20 | //noinspection JSUnusedLocalSymbols
21 | jasmine.Reporter.prototype.reportSpecResults = function(spec) {
22 | };
23 |
24 | //noinspection JSUnusedLocalSymbols
25 | jasmine.Reporter.prototype.log = function(str) {
26 | };
27 |
28 |
--------------------------------------------------------------------------------
/spec/jasmine_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require "selenium_rc"
3 | require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb"))
4 | require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
5 |
6 | jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
7 | JasmineHelper.specs,
8 | JasmineHelper.dir_mappings)
9 |
10 | spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner)
11 |
12 | should_stop = false
13 |
14 | Spec::Runner.configure do |config|
15 | config.after(:suite) do
16 | spec_builder.stop if should_stop
17 | end
18 | end
19 |
20 | spec_builder.start
21 | should_stop = true
22 | spec_builder.declare_suites
23 |
--------------------------------------------------------------------------------
/examples/ruby/spec/jasmine_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require "selenium_rc"
3 | require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb"))
4 | require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
5 |
6 | jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
7 | JasmineHelper.specs,
8 | JasmineHelper.dir_mappings)
9 |
10 | spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner)
11 |
12 | should_stop = false
13 |
14 | Spec::Runner.configure do |config|
15 | config.after(:suite) do
16 | spec_builder.stop if should_stop
17 | end
18 | end
19 |
20 | spec_builder.start
21 | should_stop = true
22 | spec_builder.declare_suites
23 |
--------------------------------------------------------------------------------
/spec/suites/UtilSpec.js:
--------------------------------------------------------------------------------
1 | describe("jasmine.util", function() {
2 | describe("extend", function () {
3 | it("should add properies to a destination object ", function() {
4 | var destination = {baz: 'baz'};
5 | jasmine.util.extend(destination, {
6 | foo: 'foo', bar: 'bar'
7 | });
8 | expect(destination).toEqual({foo: 'foo', bar: 'bar', baz: 'baz'});
9 | });
10 |
11 | it("should replace properies that already exist on a destination object", function() {
12 | var destination = {foo: 'foo'};
13 | jasmine.util.extend(destination, {
14 | foo: 'bar'
15 | });
16 | expect(destination).toEqual({foo: 'bar'});
17 | jasmine.util.extend(destination, {
18 | foo: null
19 | });
20 | expect(destination).toEqual({foo: null});
21 | });
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/examples/ruby/Rakefile:
--------------------------------------------------------------------------------
1 | require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper.rb"))
2 |
3 | namespace :test do
4 | desc "Run continuous integration tests"
5 | require "spec"
6 | require 'spec/rake/spectask'
7 |
8 | Spec::Rake::SpecTask.new(:ci) do |t|
9 | t.spec_opts = ["--color", "--format", "specdoc"]
10 | t.spec_files = ["spec/jasmine_spec.rb"]
11 | end
12 | end
13 |
14 | desc "Run specs via server"
15 | task :jasmine_server do
16 | require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
17 |
18 | puts "your tests are here:"
19 | puts " http://localhost:8888/run.html"
20 |
21 | Jasmine::SimpleServer.start(8888,
22 | lambda { JasmineHelper.specs },
23 | JasmineHelper.dir_mappings)
24 | end
25 |
--------------------------------------------------------------------------------
/spec/suites/QueueSpec.js:
--------------------------------------------------------------------------------
1 | describe("jasmine.Queue", function() {
2 | it("should not call itself recursively, so we don't get stack overflow errors", function() {
3 | var queue = new jasmine.Queue(new jasmine.Env());
4 | queue.add(new jasmine.Block(null, function() {}));
5 | queue.add(new jasmine.Block(null, function() {}));
6 | queue.add(new jasmine.Block(null, function() {}));
7 | queue.add(new jasmine.Block(null, function() {}));
8 |
9 | var nestCount = 0;
10 | var maxNestCount = 0;
11 | var nextCallCount = 0;
12 | queue.next_ = function() {
13 | nestCount++;
14 | if (nestCount > maxNestCount) maxNestCount = nestCount;
15 |
16 | jasmine.Queue.prototype.next_.apply(queue, arguments);
17 | nestCount--;
18 | };
19 |
20 | queue.start();
21 | expect(maxNestCount).toEqual(1);
22 | });
23 | });
--------------------------------------------------------------------------------
/examples/html/example_suite.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 | Jasmine Test Runner
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/MultiReporter.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @constructor
3 | */
4 | jasmine.MultiReporter = function() {
5 | this.subReporters_ = [];
6 | };
7 | jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
8 |
9 | jasmine.MultiReporter.prototype.addReporter = function(reporter) {
10 | this.subReporters_.push(reporter);
11 | };
12 |
13 | (function() {
14 | var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"];
15 | for (var i = 0; i < functionNames.length; i++) {
16 | var functionName = functionNames[i];
17 | jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
18 | return function() {
19 | for (var j = 0; j < this.subReporters_.length; j++) {
20 | var subReporter = this.subReporters_[j];
21 | if (subReporter[functionName]) {
22 | subReporter[functionName].apply(subReporter, arguments);
23 | }
24 | }
25 | };
26 | })(functionName);
27 | }
28 | })();
29 |
--------------------------------------------------------------------------------
/lib/consolex.js:
--------------------------------------------------------------------------------
1 | /** Console X
2 | * http://github.com/deadlyicon/consolex.js
3 | *
4 | * By Jared Grippe
5 | *
6 | * Copyright (c) 2009 Jared Grippe
7 | * Licensed under the MIT license.
8 | *
9 | * consolex avoids ever having to see javascript bugs in browsers that do not implement the entire
10 | * firebug console suit
11 | *
12 | */
13 | (function(window) {
14 | window.console || (window.console = {});
15 |
16 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
17 | "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
18 |
19 | function emptyFunction(){}
20 |
21 | for (var i = 0; i < names.length; ++i){
22 | window.console[names[i]] || (window.console[names[i]] = emptyFunction);
23 | if (typeof window.console[names[i]] !== 'function')
24 | window.console[names[i]] = (function(method) {
25 | return function(){ return Function.prototype.apply.apply(method, [console,arguments]); };
26 | })(window.console[names[i]]);
27 | }
28 | })(this);
--------------------------------------------------------------------------------
/spec/suites/MockClockSpec.js:
--------------------------------------------------------------------------------
1 | describe("MockClock", function () {
2 |
3 | beforeEach(function() {
4 | jasmine.Clock.useMock();
5 | });
6 |
7 | describe("setTimeout", function () {
8 | it("should mock the clock when useMock is in a beforeEach", function() {
9 | var expected = false;
10 | setTimeout(function() {
11 | expected = true;
12 | }, 30000);
13 | expect(expected).toBe(false);
14 | jasmine.Clock.tick(30001);
15 | expect(expected).toBe(true);
16 | });
17 | });
18 |
19 | describe("setInterval", function () {
20 | it("should mock the clock when useMock is in a beforeEach", function() {
21 | var interval = 0;
22 | setInterval(function() {
23 | interval++;
24 | }, 30000);
25 | expect(interval).toEqual(0);
26 | jasmine.Clock.tick(30001);
27 | expect(interval).toEqual(1);
28 | jasmine.Clock.tick(30001);
29 | expect(interval).toEqual(2);
30 | jasmine.Clock.tick(1);
31 | expect(interval).toEqual(2);
32 | });
33 | });
34 | });
35 |
--------------------------------------------------------------------------------
/MIT.LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2008 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.
--------------------------------------------------------------------------------
/examples/ruby/spec/jasmine_helper.rb:
--------------------------------------------------------------------------------
1 | class JasmineHelper
2 | def self.jasmine_lib_dir
3 | File.expand_path(File.join(jasmine_root, 'lib'))
4 | end
5 |
6 | def self.jasmine_root
7 | File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
8 | end
9 |
10 | def self.jasmine
11 | ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] +
12 | ['/lib/json2.js',
13 | '/lib/TrivialReporter.js',
14 | '/lib/consolex.js'
15 | ]
16 | end
17 |
18 | def self.jasmine_src_dir
19 | File.expand_path(File.join(jasmine_root, 'src'))
20 | end
21 |
22 | def self.jasmine_spec_dir
23 | File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec'))
24 | end
25 |
26 | def self.raw_spec_files
27 | Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js"))
28 | end
29 |
30 | def self.specs
31 | raw_spec_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")}
32 | end
33 |
34 | def self.dir_mappings
35 | {
36 | "/src" => jasmine_src_dir,
37 | "/spec" => jasmine_spec_dir,
38 | "/lib" => jasmine_lib_dir
39 | }
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/spec/jasmine_helper.rb:
--------------------------------------------------------------------------------
1 | class JasmineHelper
2 | def self.jasmine_lib_dir
3 | File.expand_path(File.join(jasmine_root, 'lib'))
4 | end
5 |
6 | def self.jasmine
7 | ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] +
8 | ['/lib/json2.js',
9 | '/lib/TrivialReporter.js']
10 | end
11 |
12 | def self.jasmine_root
13 | File.expand_path(File.join(File.dirname(__FILE__), '..'))
14 | end
15 |
16 |
17 | def self.jasmine_src_dir
18 | File.expand_path(File.join(jasmine_root, 'src'))
19 | end
20 |
21 | def self.jasmine_lib_dir
22 | File.expand_path(File.join(jasmine_root, 'lib'))
23 | end
24 |
25 | def self.jasmine_spec_dir
26 | File.expand_path(File.join(jasmine_root, 'spec'))
27 | end
28 |
29 | def self.raw_spec_files
30 | Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js"))
31 | end
32 |
33 | def self.specs
34 | Jasmine.cachebust(raw_spec_files).collect {|f| f.sub(jasmine_spec_dir, "/spec")}
35 | end
36 |
37 | def self.dir_mappings
38 | {
39 | "/src" => jasmine_src_dir,
40 | "/spec" => jasmine_spec_dir,
41 | "/lib" => jasmine_lib_dir
42 | }
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/src/Reporters.js:
--------------------------------------------------------------------------------
1 | /** JasmineReporters.reporter
2 | * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to
3 | * descendants of this object to do something with the results (see json_reporter.js)
4 | *
5 | * @deprecated
6 | */
7 | jasmine.Reporters = {};
8 |
9 | /**
10 | * @deprecated
11 | * @param callbacks
12 | */
13 | jasmine.Reporters.reporter = function(callbacks) {
14 | /**
15 | * @deprecated
16 | * @param callbacks
17 | */
18 | var that = {
19 | callbacks: callbacks || {},
20 |
21 | doCallback: function(callback, results) {
22 | if (callback) {
23 | callback(results);
24 | }
25 | },
26 |
27 | reportRunnerResults: function(runner) {
28 | that.doCallback(that.callbacks.runnerCallback, runner);
29 | },
30 | reportSuiteResults: function(suite) {
31 | that.doCallback(that.callbacks.suiteCallback, suite);
32 | },
33 | reportSpecResults: function(spec) {
34 | that.doCallback(that.callbacks.specCallback, spec);
35 | },
36 | log: function (str) {
37 | if (console && console.log) console.log(str);
38 | }
39 | };
40 |
41 | return that;
42 | };
43 |
44 |
--------------------------------------------------------------------------------
/spec/suites/MultiReporterSpec.js:
--------------------------------------------------------------------------------
1 | describe("jasmine.MultiReporter", function() {
2 | var multiReporter, fakeReporter1, fakeReporter2;
3 |
4 | beforeEach(function() {
5 | multiReporter = new jasmine.MultiReporter();
6 | fakeReporter1 = jasmine.createSpyObj("fakeReporter1", ["reportSpecResults"]);
7 | fakeReporter2 = jasmine.createSpyObj("fakeReporter2", ["reportSpecResults", "reportRunnerStarting"]);
8 | multiReporter.addReporter(fakeReporter1);
9 | multiReporter.addReporter(fakeReporter2);
10 | });
11 |
12 | it("should support all the method calls that jasmine.Reporter supports", function() {
13 | multiReporter.reportRunnerStarting();
14 | multiReporter.reportRunnerResults();
15 | multiReporter.reportSuiteResults();
16 | multiReporter.reportSpecResults();
17 | multiReporter.log();
18 | });
19 |
20 | it("should delegate to any and all subreporters", function() {
21 | multiReporter.reportSpecResults('blah', 'foo');
22 | expect(fakeReporter1.reportSpecResults).wasCalledWith('blah', 'foo');
23 | expect(fakeReporter2.reportSpecResults).wasCalledWith('blah', 'foo');
24 | });
25 |
26 | it("should quietly skip delegating to any subreporters which lack the given method", function() {
27 | multiReporter.reportRunnerStarting('blah', 'foo');
28 | expect(fakeReporter2.reportRunnerStarting).wasCalledWith('blah', 'foo');
29 | });
30 | });
--------------------------------------------------------------------------------
/src/WaitsForBlock.js:
--------------------------------------------------------------------------------
1 | jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
2 | this.timeout = timeout;
3 | this.latchFunction = latchFunction;
4 | this.message = message;
5 | this.totalTimeSpentWaitingForLatch = 0;
6 | jasmine.Block.call(this, env, null, spec);
7 | };
8 |
9 | jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
10 |
11 | jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
12 |
13 | jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
14 | var self = this;
15 | self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
16 | var latchFunctionResult;
17 | try {
18 | latchFunctionResult = self.latchFunction.apply(self.spec);
19 | } catch (e) {
20 | self.spec.fail(e);
21 | onComplete();
22 | return;
23 | }
24 |
25 | if (latchFunctionResult) {
26 | onComplete();
27 | } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
28 | var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
29 | self.spec.fail({
30 | name: 'timeout',
31 | message: message
32 | });
33 | self.spec._next();
34 | } else {
35 | self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
36 | self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
37 | }
38 | };
--------------------------------------------------------------------------------
/lib/jasmine.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
3 | }
4 |
5 |
6 | body .run_spec {
7 | float:right;
8 | }
9 |
10 | .runner.running {
11 | background-color: yellow;
12 | }
13 |
14 |
15 |
16 | .runner {
17 | border: 1px solid gray;
18 | margin: 5px;
19 | padding-left: 1em;
20 | padding-right: 1em;
21 | }
22 |
23 |
24 |
25 | .suite {
26 | border: 1px outset gray;
27 | margin: 5px;
28 | padding-left: 1em;
29 | }
30 |
31 | .suite.passed {
32 | background-color: #cfc;
33 | }
34 |
35 | .suite.failed {
36 | background-color: #fdd;
37 | }
38 |
39 | .spec {
40 | margin: 5px;
41 | clear: both;
42 | }
43 |
44 | .passed {
45 | background-color: #cfc;
46 | }
47 |
48 | .failed {
49 | background-color: #fdd;
50 | }
51 |
52 | .skipped {
53 | color: #777;
54 | background-color: #eee;
55 | }
56 |
57 | /*.resultMessage {*/
58 | /*white-space: pre;*/
59 | /*}*/
60 |
61 | .resultMessage span.result {
62 | display: block;
63 | line-height: 2em;
64 | color: black;
65 | }
66 |
67 | .resultMessage .mismatch {
68 | color: black;
69 | }
70 |
71 | .stackTrace {
72 | white-space: pre;
73 | font-size: .8em;
74 | margin-left: 10px;
75 | height: 5em;
76 | overflow: auto;
77 | border: 1px inset red;
78 | padding: 1em;
79 | background: #eef;
80 | }
81 |
82 |
83 | #jasmine_content {
84 | position:fixed;
85 | left: 100%;
86 | }
87 |
--------------------------------------------------------------------------------
/contrib/ruby/run.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Jasmine suite
6 | <% css_files.each do |css_file| %>
7 |
8 | <% end %>
9 |
10 | <% jasmine_files.each do |jasmine_file| %>
11 |
12 | <% end %>
13 |
14 | <% spec_helpers.each do |spec_helper| %>
15 |
16 | <% end %>
17 |
18 |
38 |
39 | <% spec_files.each do |spec_file| %>
40 |
41 | <% end %>
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/util.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @namespace
3 | */
4 | jasmine.util = {};
5 |
6 | /**
7 | * Declare that a child class inherit it's prototype from the parent class.
8 | *
9 | * @private
10 | * @param {Function} childClass
11 | * @param {Function} parentClass
12 | */
13 | jasmine.util.inherit = function(childClass, parentClass) {
14 | /**
15 | * @private
16 | */
17 | var subclass = function() {
18 | };
19 | subclass.prototype = parentClass.prototype;
20 | childClass.prototype = new subclass;
21 | };
22 |
23 | jasmine.util.formatException = function(e) {
24 | var lineNumber;
25 | if (e.line) {
26 | lineNumber = e.line;
27 | }
28 | else if (e.lineNumber) {
29 | lineNumber = e.lineNumber;
30 | }
31 |
32 | var file;
33 |
34 | if (e.sourceURL) {
35 | file = e.sourceURL;
36 | }
37 | else if (e.fileName) {
38 | file = e.fileName;
39 | }
40 |
41 | var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
42 |
43 | if (file && lineNumber) {
44 | message += ' in ' + file + ' (line ' + lineNumber + ')';
45 | }
46 |
47 | return message;
48 | };
49 |
50 | jasmine.util.htmlEscape = function(str) {
51 | if (!str) return str;
52 | return str.replace(/&/g, '&')
53 | .replace(//g, '>');
55 | };
56 |
57 | jasmine.util.argsToArray = function(args) {
58 | var arrayOfArgs = [];
59 | for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
60 | return arrayOfArgs;
61 | };
62 |
63 | jasmine.util.extend = function(destination, source) {
64 | for (var property in source) destination[property] = source[property];
65 | return destination;
66 | };
67 |
68 |
--------------------------------------------------------------------------------
/spec/suites/ReporterSpec.js:
--------------------------------------------------------------------------------
1 | describe('jasmine.Reporter', function() {
2 | var env;
3 |
4 |
5 | beforeEach(function() {
6 | env = new jasmine.Env();
7 | env.updateInterval = 0;
8 | });
9 |
10 | it('should get called from the test runner', function() {
11 | env.describe('Suite for JSON Reporter with Callbacks', function () {
12 | env.it('should be a test', function() {
13 | this.runs(function () {
14 | this.expect(true).toEqual(true);
15 | });
16 | });
17 | env.it('should be a failing test', function() {
18 | this.runs(function () {
19 | this.expect(false).toEqual(true);
20 | });
21 | });
22 | });
23 | env.describe('Suite for JSON Reporter with Callbacks 2', function () {
24 | env.it('should be a test', function() {
25 | this.runs(function () {
26 | this.expect(true).toEqual(true);
27 | });
28 | });
29 |
30 | });
31 |
32 | var foo = 0;
33 | var bar = 0;
34 | var baz = 0;
35 |
36 | var specCallback = function (results) {
37 | foo++;
38 | };
39 | var suiteCallback = function (results) {
40 | bar++;
41 | };
42 | var runnerCallback = function (results) {
43 | baz++;
44 | };
45 |
46 | env.reporter = jasmine.Reporters.reporter({
47 | specCallback: specCallback,
48 | suiteCallback: suiteCallback,
49 | runnerCallback: runnerCallback
50 | });
51 |
52 | var runner = env.currentRunner();
53 | runner.execute();
54 |
55 | expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo);
56 | expect(bar).toEqual(2); // 'bar was expected to be 2, was ' + bar);
57 | expect(baz).toEqual(1); // 'baz was expected to be 1, was ' + baz);
58 | });
59 |
60 | });
--------------------------------------------------------------------------------
/src/Runner.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Runner
3 | *
4 | * @constructor
5 | * @param {jasmine.Env} env
6 | */
7 | jasmine.Runner = function(env) {
8 | var self = this;
9 | self.env = env;
10 | self.queue = new jasmine.Queue(env);
11 | self.before_ = [];
12 | self.after_ = [];
13 | self.suites_ = [];
14 | };
15 |
16 | jasmine.Runner.prototype.execute = function() {
17 | var self = this;
18 | if (self.env.reporter.reportRunnerStarting) {
19 | self.env.reporter.reportRunnerStarting(this);
20 | }
21 | self.queue.start(function () {
22 | self.finishCallback();
23 | });
24 | };
25 |
26 | jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
27 | beforeEachFunction.typeName = 'beforeEach';
28 | this.before_.push(beforeEachFunction);
29 | };
30 |
31 | jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
32 | afterEachFunction.typeName = 'afterEach';
33 | this.after_.push(afterEachFunction);
34 | };
35 |
36 |
37 | jasmine.Runner.prototype.finishCallback = function() {
38 | this.env.reporter.reportRunnerResults(this);
39 | };
40 |
41 | jasmine.Runner.prototype.addSuite = function(suite) {
42 | this.suites_.push(suite);
43 | };
44 |
45 | jasmine.Runner.prototype.add = function(block) {
46 | if (block instanceof jasmine.Suite) {
47 | this.addSuite(block);
48 | }
49 | this.queue.add(block);
50 | };
51 |
52 | jasmine.Runner.prototype.specs = function () {
53 | var suites = this.suites();
54 | var specs = [];
55 | for (var i = 0; i < suites.length; i++) {
56 | specs = specs.concat(suites[i].specs());
57 | }
58 | return specs;
59 | };
60 |
61 |
62 | jasmine.Runner.prototype.suites = function() {
63 | return this.suites_;
64 | };
65 |
66 | jasmine.Runner.prototype.results = function() {
67 | return this.queue.results();
68 | };
--------------------------------------------------------------------------------
/spec/suites/EnvSpec.js:
--------------------------------------------------------------------------------
1 | describe("jasmine.Env", function() {
2 | var env;
3 | beforeEach(function() {
4 | env = new jasmine.Env();
5 | env.updateInterval = 0;
6 | });
7 |
8 | describe('ids', function () {
9 |
10 | it('nextSpecId should return consecutive integers, starting at 0', function () {
11 | expect(env.nextSpecId()).toEqual(0);
12 | expect(env.nextSpecId()).toEqual(1);
13 | expect(env.nextSpecId()).toEqual(2);
14 | });
15 |
16 | });
17 | describe("reporting", function() {
18 | var fakeReporter;
19 |
20 | beforeEach(function() {
21 | fakeReporter = jasmine.createSpyObj("fakeReporter", ["log"]);
22 | });
23 |
24 | describe('version', function () {
25 | var oldVersion;
26 |
27 | beforeEach(function () {
28 | oldVersion = jasmine.version_;
29 | });
30 |
31 | afterEach(function () {
32 | jasmine.version_ = oldVersion;
33 | });
34 |
35 | it('should raise an error if version is not set', function () {
36 | jasmine.version_ = null;
37 | var exception;
38 | try {
39 | env.version();
40 | }
41 | catch (e) {
42 | exception = e;
43 | }
44 | expect(exception.message).toEqual('Version not set');
45 |
46 | });
47 |
48 | it("version should return the current version as an int", function() {
49 | jasmine.version_ = {
50 | "major": 1,
51 | "minor": 9,
52 | "build": 7,
53 | "revision": 8
54 | };
55 | expect(env.version()).toEqual({
56 | "major": 1,
57 | "minor": 9,
58 | "build": 7,
59 | "revision": 8
60 | });
61 |
62 | });
63 | });
64 |
65 | it("should allow reporters to be registered", function() {
66 | env.addReporter(fakeReporter);
67 | env.reporter.log("message");
68 | expect(fakeReporter.log).wasCalledWith("message");
69 | });
70 | });
71 | });
--------------------------------------------------------------------------------
/src/NestedResults.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
3 | *
4 | * @constructor
5 | */
6 | jasmine.NestedResults = function() {
7 | /**
8 | * The total count of results
9 | */
10 | this.totalCount = 0;
11 | /**
12 | * Number of passed results
13 | */
14 | this.passedCount = 0;
15 | /**
16 | * Number of failed results
17 | */
18 | this.failedCount = 0;
19 | /**
20 | * Was this suite/spec skipped?
21 | */
22 | this.skipped = false;
23 | /**
24 | * @ignore
25 | */
26 | this.items_ = [];
27 | };
28 |
29 | /**
30 | * Roll up the result counts.
31 | *
32 | * @param result
33 | */
34 | jasmine.NestedResults.prototype.rollupCounts = function(result) {
35 | this.totalCount += result.totalCount;
36 | this.passedCount += result.passedCount;
37 | this.failedCount += result.failedCount;
38 | };
39 |
40 | /**
41 | * Tracks a result's message.
42 | * @param message
43 | */
44 | jasmine.NestedResults.prototype.log = function(message) {
45 | this.items_.push(new jasmine.MessageResult(message));
46 | };
47 |
48 | /**
49 | * Getter for the results: message & results.
50 | */
51 | jasmine.NestedResults.prototype.getItems = function() {
52 | return this.items_;
53 | };
54 |
55 | /**
56 | * Adds a result, tracking counts (total, passed, & failed)
57 | * @param {jasmine.ExpectationResult|jasmine.NestedResults} result
58 | */
59 | jasmine.NestedResults.prototype.addResult = function(result) {
60 | if (result.type != 'MessageResult') {
61 | if (result.items_) {
62 | this.rollupCounts(result);
63 | } else {
64 | this.totalCount++;
65 | if (result.passed()) {
66 | this.passedCount++;
67 | } else {
68 | this.failedCount++;
69 | }
70 | }
71 | }
72 | this.items_.push(result);
73 | };
74 |
75 | /**
76 | * @returns {Boolean} True if everything below passed
77 | */
78 | jasmine.NestedResults.prototype.passed = function() {
79 | return this.passedCount === this.totalCount;
80 | };
81 |
--------------------------------------------------------------------------------
/src/Suite.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Internal representation of a Jasmine suite.
3 | *
4 | * @constructor
5 | * @param {jasmine.Env} env
6 | * @param {String} description
7 | * @param {Function} specDefinitions
8 | * @param {jasmine.Suite} parentSuite
9 | */
10 | jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
11 | var self = this;
12 | self.id = env.nextSuiteId ? env.nextSuiteId() : null;
13 | self.description = description;
14 | self.queue = new jasmine.Queue(env);
15 | self.parentSuite = parentSuite;
16 | self.env = env;
17 | self.before_ = [];
18 | self.after_ = [];
19 | self.specs_ = [];
20 | };
21 |
22 | jasmine.Suite.prototype.getFullName = function() {
23 | var fullName = this.description;
24 | for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
25 | fullName = parentSuite.description + ' ' + fullName;
26 | }
27 | return fullName;
28 | };
29 |
30 | jasmine.Suite.prototype.finish = function(onComplete) {
31 | this.env.reporter.reportSuiteResults(this);
32 | this.finished = true;
33 | if (typeof(onComplete) == 'function') {
34 | onComplete();
35 | }
36 | };
37 |
38 | jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
39 | beforeEachFunction.typeName = 'beforeEach';
40 | this.before_.push(beforeEachFunction);
41 | };
42 |
43 | jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
44 | afterEachFunction.typeName = 'afterEach';
45 | this.after_.push(afterEachFunction);
46 | };
47 |
48 | jasmine.Suite.prototype.results = function() {
49 | return this.queue.results();
50 | };
51 |
52 | jasmine.Suite.prototype.add = function(block) {
53 | if (block instanceof jasmine.Suite) {
54 | this.env.currentRunner().addSuite(block);
55 | } else {
56 | this.specs_.push(block);
57 | }
58 | this.queue.add(block);
59 | };
60 |
61 | jasmine.Suite.prototype.specs = function() {
62 | return this.specs_;
63 | };
64 |
65 | jasmine.Suite.prototype.execute = function(onComplete) {
66 | var self = this;
67 | this.queue.start(function () {
68 | self.finish(onComplete);
69 | });
70 | };
--------------------------------------------------------------------------------
/spec/suites/NestedResultsSpec.js:
--------------------------------------------------------------------------------
1 | describe('jasmine.NestedResults', function() {
2 | it('#addResult increments counters', function() {
3 | // Leaf case
4 | var results = new jasmine.NestedResults();
5 |
6 | results.addResult(new jasmine.ExpectationResult({
7 | matcherName: "foo", passed: true, message: 'Passed.', actual: 'bar', expected: 'bar'}
8 | ));
9 |
10 | expect(results.getItems().length).toEqual(1);
11 | expect(results.totalCount).toEqual(1);
12 | expect(results.passedCount).toEqual(1);
13 | expect(results.failedCount).toEqual(0);
14 |
15 | results.addResult(new jasmine.ExpectationResult({
16 | matcherName: "baz", passed: false, message: 'FAIL.', actual: "corge", expected: "quux"
17 | }));
18 |
19 | expect(results.getItems().length).toEqual(2);
20 | expect(results.totalCount).toEqual(2);
21 | expect(results.passedCount).toEqual(1);
22 | expect(results.failedCount).toEqual(1);
23 | });
24 |
25 | it('should roll up counts for nested results', function() {
26 | // Branch case
27 | var leafResultsOne = new jasmine.NestedResults();
28 | leafResultsOne.addResult(new jasmine.ExpectationResult({
29 | matcherName: "toSomething", passed: true, message: 'message', actual: '', expected:''
30 | }));
31 |
32 | leafResultsOne.addResult(new jasmine.ExpectationResult({
33 | matcherName: "toSomethingElse", passed: false, message: 'message', actual: 'a', expected: 'b'
34 | }));
35 |
36 | var leafResultsTwo = new jasmine.NestedResults();
37 | leafResultsTwo.addResult(new jasmine.ExpectationResult({
38 | matcherName: "toSomething", passed: true, message: 'message', actual: '', expected: ''
39 | }));
40 | leafResultsTwo.addResult(new jasmine.ExpectationResult({
41 | matcherName: "toSomethineElse", passed: false, message: 'message', actual: 'c', expected: 'd'
42 | }));
43 |
44 | var branchResults = new jasmine.NestedResults();
45 | branchResults.addResult(leafResultsOne);
46 | branchResults.addResult(leafResultsTwo);
47 |
48 | expect(branchResults.getItems().length).toEqual(2);
49 | expect(branchResults.totalCount).toEqual(4);
50 | expect(branchResults.passedCount).toEqual(2);
51 | expect(branchResults.failedCount).toEqual(2);
52 | });
53 |
54 | });
55 |
--------------------------------------------------------------------------------
/contrib/ruby/spec/jasmine_runner_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec'
2 | require 'open-uri'
3 | require 'thin'
4 |
5 | require File.dirname(__FILE__) + '/../jasmine_runner'
6 |
7 | describe Jasmine::SimpleServer do
8 | before do
9 | @port = Jasmine::find_unused_port
10 | end
11 |
12 | after do
13 | Jasmine::kill_process_group(@jasmine_server_pid) if @jasmine_server_pid
14 | end
15 |
16 | it "should start and print script tags" do
17 | @jasmine_server_pid = fork do
18 | Process.setpgrp
19 | Jasmine::SimpleServer.start(@port, ["file1", "file2"], {})
20 | exit! 0
21 | end
22 |
23 | Jasmine::wait_for_listener(@port)
24 |
25 | run_html = open("http://localhost:#{@port}/").read
26 | run_html.should =~ /
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |