From 849a4efda88fdb908c02529a2211d1d21be81f83 Mon Sep 17 00:00:00 2001 From: Nate Clark Date: Wed, 16 Dec 2009 17:27:06 -0800 Subject: [PATCH 01/29] adds support to run Jasmine suites on CI using Sauce Labs --- Rakefile | 33 ++++++++----- contrib/ruby/jasmine_runner.rb | 77 +++++++++++++++++++++++------- examples/ruby/Rakefile | 19 ++++++-- examples/ruby/spec/jasmine_spec.rb | 17 +++++-- examples/ruby/spec/saucelabs.yml | 24 ++++++++++ geminstaller.yml | 3 ++ spec/jasmine_spec.rb | 17 +++++-- spec/saucelabs.yml | 24 ++++++++++ 8 files changed, 171 insertions(+), 43 deletions(-) create mode 100644 examples/ruby/spec/saucelabs.yml create mode 100644 spec/saucelabs.yml diff --git a/Rakefile b/Rakefile index 4ce8838..2bb0f6e 100644 --- a/Rakefile +++ b/Rakefile @@ -59,7 +59,7 @@ namespace :jasmine do task :build => :lint do puts 'Building Jasmine from source' require 'json' - + sources = jasmine_sources version = version_hash @@ -119,17 +119,26 @@ jasmine.version_= { end namespace :test do - desc "Run continuous integration tests" - task :ci => 'jasmine:build' do - require "spec" - require 'spec/rake/spectask' - Spec::Rake::SpecTask.new(:lambda_ci) do |t| - t.spec_opts = ["--color", "--format", "specdoc"] - t.spec_files = ["spec/jasmine_spec.rb"] - end - Rake::Task[:lambda_ci].invoke - end + desc "Run continuous integration tests using a local Selenium runner" + task :ci => :'ci:local' + namespace :ci do + task :local => 'jasmine:build' do + require "spec" + require 'spec/rake/spectask' + Spec::Rake::SpecTask.new(:lambda_ci) do |t| + t.spec_opts = ["--color", "--format", "specdoc"] + t.spec_files = ["spec/jasmine_spec.rb"] + end + Rake::Task[:lambda_ci].invoke + end + + desc "Run continuous integration tests using Sauce Labs 'Selenium in the Cloud'" + task :saucelabs => 'jasmine:build' do + ENV['SAUCELABS'] = 'true' + Rake::Task['jasmine:test:ci:local'].invoke + end + end end -end \ No newline at end of file +end diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 5a6b1ef..2388396 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -228,46 +228,53 @@ module Jasmine @browser = options[:browser] ? options[:browser].delete(:browser) : 'firefox' @selenium_pid = nil @jasmine_server_pid = nil + @selenium_host = 'localhost' + @jasmine_server_port = Jasmine::find_unused_port + @selenium_server_port = Jasmine::find_unused_port end def start - start_servers - @client = Jasmine::SimpleClient.new("localhost", @selenium_server_port, "*#{@browser}", "http://localhost:#{@jasmine_server_port}/") + start_jasmine_server + start_selenium_server + @client = Jasmine::SimpleClient.new(@selenium_host, @selenium_server_port, "*#{@browser}", "http://localhost:#{@jasmine_server_port}/") @client.connect end def stop @client.disconnect - stop_servers + stop_selenium_server + stop_jasmine_server end - def start_servers - @jasmine_server_port = Jasmine::find_unused_port - @selenium_server_port = Jasmine::find_unused_port - - @selenium_pid = fork do - Process.setpgrp - exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1" - end - puts "selenium started. pid is #{@selenium_pid}" - + def start_jasmine_server @jasmine_server_pid = fork do Process.setpgrp Jasmine::SimpleServer.start(@jasmine_server_port, @spec_files, @dir_mappings, @options) exit! 0 end puts "jasmine server started. pid is #{@jasmine_server_pid}" - - Jasmine::wait_for_listener(@selenium_server_port, "selenium server") Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server") end - def stop_servers - puts "shutting down the servers..." - Jasmine::kill_process_group(@selenium_pid) if @selenium_pid + def start_selenium_server + @selenium_pid = fork do + Process.setpgrp + exec "java -jar #{@selenium_jar_path} -port #{@selenium_server_port} > /dev/null 2>&1" + end + puts "selenium started. pid is #{@selenium_pid}" + Jasmine::wait_for_listener(@selenium_server_port, "selenium server") + end + + def stop_jasmine_server + puts "shutting down Jasmine server..." Jasmine::kill_process_group(@jasmine_server_pid) if @jasmine_server_pid end + def stop_selenium_server + puts "shutting down Selenium server..." + Jasmine::kill_process_group(@selenium_pid) if @selenium_pid + end + def run begin start @@ -284,6 +291,40 @@ module Jasmine end end + class SauceLabsRunner < Runner + def initialize(spec_files, dir_mappings, options={}) + @spec_files = spec_files + @dir_mappings = dir_mappings + @options = options + + @browser = options[:browser] ? options[:browser].delete(:browser) : 'firefox' + @jasmine_server_pid = nil + @jasmine_server_port = Jasmine::find_unused_port + @saucelabs_config = SeleniumConfig.new(options[:saucelabs_config], options[:saucelabs_config_file], @jasmine_server_port) + end + + def start_selenium_server + @sauce_tunnel = SauceTunnel.new(@saucelabs_config) + end + + def start + start_jasmine_server + start_selenium_server + @client = Jasmine::SimpleClient.new(@saucelabs_config['selenium_server_address'], + 4444, + @saucelabs_config['selenium_browser_key'], + "http://#{@saucelabs_config['application_address']}") + @client.connect + end + + def stop + @client.disconnect + @sauce_tunnel.shutdown + stop_jasmine_server + end + + end + def self.files(f) result = f result = result.call if result.respond_to?(:call) diff --git a/examples/ruby/Rakefile b/examples/ruby/Rakefile index 9cf3592..4196c32 100644 --- a/examples/ruby/Rakefile +++ b/examples/ruby/Rakefile @@ -2,12 +2,21 @@ require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper. namespace :test do desc "Run continuous integration tests" - require "spec" - require 'spec/rake/spectask' + task :ci => :'ci:local' + namespace :ci do + require "spec" + require 'spec/rake/spectask' - Spec::Rake::SpecTask.new(:ci) do |t| - t.spec_opts = ["--color", "--format", "specdoc"] - t.spec_files = ["spec/jasmine_spec.rb"] + Spec::Rake::SpecTask.new(:local) do |t| + t.spec_opts = ["--color", "--format", "specdoc"] + t.spec_files = ["spec/jasmine_spec.rb"] + end + + desc "Run continuous integration tests using Sauce Labs 'Selenium in the Cloud'" + task :saucelabs do + ENV['SAUCELABS'] = 'true' + Rake::Task['test:ci:local'].invoke + end end end diff --git a/examples/ruby/spec/jasmine_spec.rb b/examples/ruby/spec/jasmine_spec.rb index ce15f00..1b37d8b 100644 --- a/examples/ruby/spec/jasmine_spec.rb +++ b/examples/ruby/spec/jasmine_spec.rb @@ -1,11 +1,20 @@ require 'rubygems' -require "selenium_rc" require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb")) require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) -jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, - JasmineHelper.specs, - JasmineHelper.dir_mappings) +jasmine_runner = if ENV['SAUCELABS'] == 'true' + require 'sauce_tunnel' + require 'selenium_config' + Jasmine::SauceLabsRunner.new(JasmineHelper.specs, + JasmineHelper.dir_mappings, + :saucelabs_config => 'saucelabs', + :saucelabs_config_file => File.expand_path(File.join(File.dirname(__FILE__), "saucelabs.yml"))) +else + require "selenium_rc" + Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, + JasmineHelper.specs, + JasmineHelper.dir_mappings) +end spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner) diff --git a/examples/ruby/spec/saucelabs.yml b/examples/ruby/spec/saucelabs.yml new file mode 100644 index 0000000..8a46d1c --- /dev/null +++ b/examples/ruby/spec/saucelabs.yml @@ -0,0 +1,24 @@ +local: + application_framework: :selenium +# +# Possible Sauce Labs configurations as of 2009/11/19 +# From: http://saucelabs.com/products/docs/sauce-ondemand/browsers +# os: "Windows 2003" +# browser: "iexplore" +# browser-version: "6.", "7.", "8." +# browser: "firefox" +# browser-version: "2.", "3.0", "3.5" +# browser: "safari" +# browser-version: "3.", "4." +# browser: "opera" +# browser-version: "9." +# browser: "googlechrome" +# browser-version: "" +# os: "Linux" +# browser: "firefox" +# browser-version: "3." +saucelabs: + application_framework: :external + selenium_server_address: "saucelabs.com" + selenium_browser_key: '{"username": "--YOUR-SAUCELABS-USERNAME--", "access-key": "--YOUR-SAUCELABS-ACCESS-KEY--", "os": "Linux", "browser": "firefox", "browser-version": "3."}' + application_port: "80" diff --git a/geminstaller.yml b/geminstaller.yml index 860e086..780400c 100644 --- a/geminstaller.yml +++ b/geminstaller.yml @@ -18,3 +18,6 @@ gems: version: 1.2.9 - name: selenium-client version: 1.2.17 +- name: saucelabs-adapter + version: 0.3.2 + install_options: --source=http://gems.pivotallabs.com diff --git a/spec/jasmine_spec.rb b/spec/jasmine_spec.rb index ce15f00..1b37d8b 100644 --- a/spec/jasmine_spec.rb +++ b/spec/jasmine_spec.rb @@ -1,11 +1,20 @@ require 'rubygems' -require "selenium_rc" require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb")) require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) -jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, - JasmineHelper.specs, - JasmineHelper.dir_mappings) +jasmine_runner = if ENV['SAUCELABS'] == 'true' + require 'sauce_tunnel' + require 'selenium_config' + Jasmine::SauceLabsRunner.new(JasmineHelper.specs, + JasmineHelper.dir_mappings, + :saucelabs_config => 'saucelabs', + :saucelabs_config_file => File.expand_path(File.join(File.dirname(__FILE__), "saucelabs.yml"))) +else + require "selenium_rc" + Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, + JasmineHelper.specs, + JasmineHelper.dir_mappings) +end spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner) diff --git a/spec/saucelabs.yml b/spec/saucelabs.yml new file mode 100644 index 0000000..8a46d1c --- /dev/null +++ b/spec/saucelabs.yml @@ -0,0 +1,24 @@ +local: + application_framework: :selenium +# +# Possible Sauce Labs configurations as of 2009/11/19 +# From: http://saucelabs.com/products/docs/sauce-ondemand/browsers +# os: "Windows 2003" +# browser: "iexplore" +# browser-version: "6.", "7.", "8." +# browser: "firefox" +# browser-version: "2.", "3.0", "3.5" +# browser: "safari" +# browser-version: "3.", "4." +# browser: "opera" +# browser-version: "9." +# browser: "googlechrome" +# browser-version: "" +# os: "Linux" +# browser: "firefox" +# browser-version: "3." +saucelabs: + application_framework: :external + selenium_server_address: "saucelabs.com" + selenium_browser_key: '{"username": "--YOUR-SAUCELABS-USERNAME--", "access-key": "--YOUR-SAUCELABS-ACCESS-KEY--", "os": "Linux", "browser": "firefox", "browser-version": "3."}' + application_port: "80" From d90852336f6c41d598b83a2a3ef322f342b722f2 Mon Sep 17 00:00:00 2001 From: "Nathan Wilmes & Davis W. Frank" Date: Mon, 21 Dec 2009 11:45:49 -0800 Subject: [PATCH 02/29] Added wasNotCalledWith matcher, used argsForCall a bit less --- lib/jasmine-0.10.0.js | 24 ++++++++++++++++++++---- spec/suites/SpySpec.js | 6 +++--- src/Matchers.js | 18 +++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index f7f621b..d5abe6a 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -1201,12 +1201,28 @@ jasmine.Matchers.prototype.wasCalledWith = function() { } this.message = function() { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + if (this.actual.callCount == 0) { + return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; + } else { + return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + } }; return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); }; +jasmine.Matchers.prototype.wasNotCalledWith = function() { + if (!jasmine.isSpy(this.actual)) { + throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); + } + + this.message = function() { + return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; + }; + + return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +}; + /** * Matcher that checks that the expected item is an element in the actual Array. * @@ -1437,14 +1453,14 @@ jasmine.PrettyPrinter.prototype.format = function(value) { this.emitString(value); } else if (jasmine.isSpy(value)) { this.emitScalar("spy on " + value.identity); + } else if (value instanceof RegExp) { + this.emitScalar(value.toString()); } else if (typeof value === 'function') { this.emitScalar('Function'); } else if (typeof value.nodeType === 'number') { this.emitScalar('HTMLNode'); } else if (value instanceof Date) { this.emitScalar('Date(' + value + ')'); - } else if (value instanceof RegExp) { - this.emitScalar(value.toString()); } else if (value.__Jasmine_been_here_before__) { this.emitScalar(''); } else if (jasmine.isArray_(value) || typeof value == 'object') { @@ -2241,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1259251766 + "revision": 1261424713 }; diff --git a/spec/suites/SpySpec.js b/spec/suites/SpySpec.js index 1e782fb..37dd04f 100644 --- a/spec/suites/SpySpec.js +++ b/spec/suites/SpySpec.js @@ -33,8 +33,8 @@ describe('Spies', function () { TestClass.someFunction('foo'); TestClass.someFunction('bar'); - expect(TestClass.someFunction.argsForCall[0]).toEqual(['foo']); - expect(TestClass.someFunction.argsForCall[1]).toEqual(['bar']); + expect(TestClass.someFunction.calls[0].args).toEqual(['foo']); + expect(TestClass.someFunction.calls[1].args).toEqual(['bar']); expect(TestClass.someFunction.mostRecentCall.args).toEqual(['bar']); }); @@ -184,4 +184,4 @@ describe('Spies', function () { expect(spyObj.method2.identity).toEqual('BaseName.method2'); }); -}); \ No newline at end of file +}); diff --git a/src/Matchers.js b/src/Matchers.js index 79f5d53..fd88829 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -198,12 +198,28 @@ jasmine.Matchers.prototype.wasCalledWith = function() { } this.message = function() { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + if (this.actual.callCount == 0) { + return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; + } else { + return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + } }; return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); }; +jasmine.Matchers.prototype.wasNotCalledWith = function() { + if (!jasmine.isSpy(this.actual)) { + throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); + } + + this.message = function() { + return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; + }; + + return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +}; + /** * Matcher that checks that the expected item is an element in the actual Array. * From dd5e97bf140d8c1c2e37165c81008e06dd6a031f Mon Sep 17 00:00:00 2001 From: "Fabio M. Costa" Date: Wed, 23 Dec 2009 08:46:50 -0200 Subject: [PATCH 03/29] with this fix jasmine runs on ie6 (cherry picked from commit 33a3b769e2b28aab01c1d6ee216c55e12539f417) --- src/base.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/base.js b/src/base.js index 8850f28..391412f 100755 --- a/src/base.js +++ b/src/base.js @@ -501,10 +501,8 @@ var xdescribe = function(description, specDefinitions) { }; -jasmine.XmlHttpRequest = XMLHttpRequest; - // Provide the XMLHttpRequest class for IE 5.x-6.x: -if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { +jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) { @@ -522,7 +520,7 @@ if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { } catch(e) { } throw new Error("This browser does not support XMLHttpRequest."); -}; +} : XMLHttpRequest; /** * Adds suite files to an HTML document so that they are executed, thus adding them to the current From ba8c16acd73b9b533aa05cd63ed33e0941316c7b Mon Sep 17 00:00:00 2001 From: ragaskar Date: Wed, 23 Dec 2009 07:38:18 -0800 Subject: [PATCH 04/29] Rebuild jasmine, add rest-client to geminstaller (req'd by saucelabs-adapter --- geminstaller.yml | 2 ++ lib/jasmine-0.10.0.js | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/geminstaller.yml b/geminstaller.yml index 780400c..a89fb78 100644 --- a/geminstaller.yml +++ b/geminstaller.yml @@ -18,6 +18,8 @@ gems: version: 1.2.9 - name: selenium-client version: 1.2.17 +- name: rest-client + version: 1.0.3 - name: saucelabs-adapter version: 0.3.2 install_options: --source=http://gems.pivotallabs.com diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index d5abe6a..bfb4494 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -501,10 +501,8 @@ var xdescribe = function(description, specDefinitions) { }; -jasmine.XmlHttpRequest = XMLHttpRequest; - // Provide the XMLHttpRequest class for IE 5.x-6.x: -if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { +jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) { @@ -522,7 +520,7 @@ if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { } catch(e) { } throw new Error("This browser does not support XMLHttpRequest."); -}; +} : XMLHttpRequest; /** * Adds suite files to an HTML document so that they are executed, thus adding them to the current @@ -2257,5 +2255,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1261424713 + "revision": 1261582590 }; From 21998dcb9d39848f963f9f9dcfc29e29edb7c89d Mon Sep 17 00:00:00 2001 From: ragaskar Date: Wed, 23 Dec 2009 21:29:34 -0800 Subject: [PATCH 05/29] Update Jasmine geminstaller to use gemcutter gems --- doc/files.html | 2 +- doc/index.html | 2 +- doc/symbols/_global_.html | 2 +- doc/symbols/jasmine.Block.html | 2 +- doc/symbols/jasmine.Clock.html | 2 +- doc/symbols/jasmine.Env.html | 36 +- doc/symbols/jasmine.JsApiReporter.html | 2 +- doc/symbols/jasmine.Matchers.html | 1395 ++++++++++++------- doc/symbols/jasmine.MultiReporter.html | 2 +- doc/symbols/jasmine.NestedResults.html | 2 +- doc/symbols/jasmine.Reporter.html | 2 +- doc/symbols/jasmine.Runner.html | 2 +- doc/symbols/jasmine.Spec.html | 2 +- doc/symbols/jasmine.Spy.html | 2 +- doc/symbols/jasmine.Suite.html | 2 +- doc/symbols/jasmine.html | 88 +- doc/symbols/jasmine.util.html | 2 +- doc/symbols/src/lib_TrivialReporter.js.html | 54 +- doc/symbols/src/src_Env.js.html | 401 +++--- doc/symbols/src/src_JsApiReporter.js.html | 45 +- doc/symbols/src/src_Matchers.js.html | 618 ++++---- doc/symbols/src/src_PrettyPrinter.js.html | 222 +-- doc/symbols/src/src_Spec.js.html | 380 +++-- doc/symbols/src/src_base.js.html | 1032 +++++++------- doc/symbols/src/src_mock-timeout.js.html | 8 +- examples/ruby/spec/jasmine_spec.rb | 2 +- geminstaller.yml | 4 +- lib/jasmine-0.10.0.js | 2 +- spec/jasmine_spec.rb | 2 +- 29 files changed, 2316 insertions(+), 2001 deletions(-) diff --git a/doc/files.html b/doc/files.html index bce9c40..dfdecfe 100644 --- a/doc/files.html +++ b/doc/files.html @@ -454,7 +454,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 2f8b49a..fa86084 100644 --- a/doc/index.html +++ b/doc/index.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 2b25eed..57f29d3 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -912,7 +912,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:29 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index f50be43..a04e2c9 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -411,7 +411,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:29 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Clock.html b/doc/symbols/jasmine.Clock.html index dbe6f6a..fd7c165 100644 --- a/doc/symbols/jasmine.Clock.html +++ b/doc/symbols/jasmine.Clock.html @@ -672,7 +672,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:29 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index ac69aa9..40efbdd 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -382,6 +382,15 @@ ul.inheritsList + +   + + +
+ + +   @@ -910,6 +919,31 @@ ul.inheritsList +
+ + +
+ + + matchersClass() + +
+
+ + + +
+ + + + + + + + + + +
@@ -1129,7 +1163,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:29 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 38ea39f..ca02c07 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -816,7 +816,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index 6aa15b3..4ec8408 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -268,184 +268,6 @@ ul.inheritsList - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- toBe -
-
toBe: compares the actual to the expected using ===
-
  - -
Matcher that compares the acutal to undefined.
-
  -
- toBeFalsy -
-
Matcher that boolean nots the actual.
-
  -
- toBeNull -
-
Matcher that compares the actual to null.
-
  - -
Matcher that boolean not-nots the actual.
-
  - -
Matcher that compares the acutal to undefined.
-
  -
- toContain -
-
Matcher that checks that the expected item is an element in the actual Array.
-
  -
- toEqual -
-
toEqual: compares the actual to the expected using common sense equality.
-
  -
- toMatch -
-
Matcher that compares the actual to the expected using a regular expression.
-
  -
- toNotBe -
-
toNotBe: compares the actual to the expected using !==
-
  - -
Matcher that checks that the expected item is NOT an element in the actual Array.
-
  - -
toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
-
  - -
Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
-
  -
- toThrow -
-
Matcher that checks that the expected exception was thrown by the actual.
-
  -
- wasCalled -
-
Matcher that checks to see if the acutal, a Jasmine spy, was called.
-
  - -
Matcher that checks to see if the acutal, a Jasmine spy, was not called.
-
- - - - @@ -473,7 +295,16 @@ ul.inheritsList <static>   -
jasmine.Matchers.matcherFn_(matcherName, options) +
jasmine.Matchers.matcherFn_(matcherName, matcherFunction) +
+
+ + + + +   + +
message(expected)
@@ -497,6 +328,186 @@ ul.inheritsList + +   + +
toBe(expected) +
+
toBe: compares the actual to the expected using ===
+ + + + +   + + +
Matcher that compares the actual to jasmine.undefined.
+ + + + +   + + +
Matcher that boolean nots the actual.
+ + + + +   + +
toBeGreaterThan(expected) +
+
+ + + + +   + +
toBeLessThan(expected) +
+
+ + + + +   + + +
Matcher that compares the actual to null.
+ + + + +   + + +
Matcher that boolean not-nots the actual.
+ + + + +   + + +
Matcher that compares the actual to jasmine.undefined.
+ + + + +   + +
toContain(item) +
+
Matcher that checks that the expected item is an element in the actual Array.
+ + + + +   + +
toEqual(expected) +
+
toEqual: compares the actual to the expected using common sense equality.
+ + + + +   + +
toMatch(reg_exp) +
+
Matcher that compares the actual to the expected using a regular expression.
+ + + + +   + +
toNotBe(expected) +
+
toNotBe: compares the actual to the expected using !==
+ + + + +   + +
toNotContain(item) +
+
Matcher that checks that the expected item is NOT an element in the actual Array.
+ + + + +   + +
toNotEqual(expected) +
+
toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
+ + + + +   + +
toNotMatch(reg_exp) +
+
Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
+ + + + +   + +
toThrow(expectedException) +
+
Matcher that checks that the expected exception was thrown by the actual.
+ + + + +   + + +
Matcher that checks to see if the actual, a Jasmine spy, was called.
+ + + + +   + + +
Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
+ + + + +   + + +
Matcher that checks to see if the actual, a Jasmine spy, was not called.
+ + + + +   + + +
+ + + @@ -561,364 +572,6 @@ ul.inheritsList -
- Field Detail -
- - -
- - - toBe - -
-
- toBe: compares the actual to the expected using === - - -
- - - - - - - - -
- - -
- - - toBeDefined - -
-
- Matcher that compares the acutal to undefined. - - -
- - - - - - - - -
- - -
- - - toBeFalsy - -
-
- Matcher that boolean nots the actual. - - -
- - - - - - - - -
- - -
- - - toBeNull - -
-
- Matcher that compares the actual to null. - - -
- - - - - - - - -
- - -
- - - toBeTruthy - -
-
- Matcher that boolean not-nots the actual. - - -
- - - - - - - - -
- - -
- - - toBeUndefined - -
-
- Matcher that compares the acutal to undefined. - - -
- - - - - - - - -
- - -
- - - toContain - -
-
- Matcher that checks that the expected item is an element in the actual Array. - - -
- - - - - - - - -
- - -
- - - toEqual - -
-
- toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. - - -
- - - - - - - - -
- - -
- - - toMatch - -
-
- Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -a pattern or a String. - - -
- - - - - - - - -
- - -
- - - toNotBe - -
-
- toNotBe: compares the actual to the expected using !== - - -
- - - - - - - - -
- - -
- - - toNotContain - -
-
- Matcher that checks that the expected item is NOT an element in the actual Array. - - -
- - - - - - - - -
- - -
- - - toNotEqual - -
-
- toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual - - -
- - - - - - - - -
- - -
- - - toNotMatch - -
-
- Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch - - -
- - - - - - - - -
- - -
- - - toThrow - -
-
- Matcher that checks that the expected exception was thrown by the actual. - - -
- - - - - - - - -
- - -
- - - wasCalled - -
-
- Matcher that checks to see if the acutal, a Jasmine spy, was called. - - -
- - - - - - - - -
- - -
- - - wasNotCalled - -
-
- Matcher that checks to see if the acutal, a Jasmine spy, was not called. - - -
- - - - - - - - - - - @@ -966,7 +619,7 @@ a pattern or a String.
<static> - jasmine.Matchers.matcherFn_(matcherName, options) + jasmine.Matchers.matcherFn_(matcherName, matcherFunction)
@@ -988,7 +641,43 @@ a pattern or a String.
- options + matcherFunction + +
+
+ + + + + + + + + + +
+ + +
+ + + message(expected) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ expected
@@ -1086,6 +775,632 @@ a pattern or a String. +
+ + +
+ + + toBe(expected) + +
+
+ toBe: compares the actual to the expected using === + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toBeDefined() + +
+
+ Matcher that compares the actual to jasmine.undefined. + + +
+ + + + + + + + + + + +
+ + +
+ + + toBeFalsy() + +
+
+ Matcher that boolean nots the actual. + + +
+ + + + + + + + + + + +
+ + +
+ + + toBeGreaterThan(expected) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toBeLessThan(expected) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toBeNull() + +
+
+ Matcher that compares the actual to null. + + +
+ + + + + + + + + + + +
+ + +
+ + + toBeTruthy() + +
+
+ Matcher that boolean not-nots the actual. + + +
+ + + + + + + + + + + +
+ + +
+ + + toBeUndefined() + +
+
+ Matcher that compares the actual to jasmine.undefined. + + +
+ + + + + + + + + + + +
+ + +
+ + + toContain(item) + +
+
+ Matcher that checks that the expected item is an element in the actual Array. + + +
+ + + + +
+
Parameters:
+ +
+ {Object} item + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toEqual(expected) + +
+
+ toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toMatch(reg_exp) + +
+
+ Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +a pattern or a String. + + +
+ + + + +
+
Parameters:
+ +
+ reg_exp + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotBe(expected) + +
+
+ toNotBe: compares the actual to the expected using !== + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotContain(item) + +
+
+ Matcher that checks that the expected item is NOT an element in the actual Array. + + +
+ + + + +
+
Parameters:
+ +
+ {Object} item + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotEqual(expected) + +
+
+ toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotMatch(reg_exp) + +
+
+ Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch + + +
+ + + + +
+
Parameters:
+ +
+ reg_exp + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toThrow(expectedException) + +
+
+ Matcher that checks that the expected exception was thrown by the actual. + + +
+ + + + +
+
Parameters:
+ +
+ {String} expectedException + +
+
+ +
+ + + + + + + + +
+ + +
+ + + wasCalled() + +
+
+ Matcher that checks to see if the actual, a Jasmine spy, was called. + + +
+ + + + + + + + + + + +
+ + +
+ + + wasCalledWith() + +
+
+ Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. + + +
+ + + +

+					
+					
+					
+						
+						
+						
+						
+						
+						
+						
+
+					
+ + +
+ + + wasNotCalled() + +
+
+ Matcher that checks to see if the actual, a Jasmine spy, was not called. + + +
+ + + + + + + + + + + +
+ + +
+ + + wasNotCalledWith() + +
+
+ + + +
+ + + + + + + + + + + @@ -1100,7 +1415,7 @@ a pattern or a String.
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index b2ead53..8583a03 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -388,7 +388,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 69283a6..395225e 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index d035c63..3646e49 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -568,7 +568,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index c726687..c3ac98a 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index bc5e538..3c6473c 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -1253,7 +1253,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index a7f98a6..0cb83ac 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -849,7 +849,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index 898ace0..d5f40c6 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -699,7 +699,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 14b52e6..835bd0f 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -405,6 +405,15 @@ Jasmine environment.
+ + <static>   + +
jasmine.isSpy(putativeSpy) +
+
Determines whether an object is a spy.
+ + + <static>   @@ -486,15 +495,6 @@ Jasmine environment.
- - <static>   - -
jasmine.XmlHttpRequest() -
-
- - - @@ -909,6 +909,49 @@ Jasmine environment. +
+
Returns:
+ +
{Boolean}
+ +
+ + + + +
+ + +
<static> + + {Boolean} + jasmine.isSpy(putativeSpy) + +
+
+ Determines whether an object is a spy. + + +
+ + + + +
+
Parameters:
+ +
+ {jasmine.Spy|Object} putativeSpy + +
+
+ +
+ + + + +
Returns:
@@ -1282,31 +1325,6 @@ Jasmine environment. -
- - -
<static> - - - jasmine.XmlHttpRequest() - -
-
- - - -
- - - - - - - - - - - @@ -1321,7 +1339,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:29 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 905d878..bb10c02 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -529,7 +529,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Tue Nov 10 2009 17:31:30 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST)
diff --git a/doc/symbols/src/lib_TrivialReporter.js.html b/doc/symbols/src/lib_TrivialReporter.js.html index df0b881..9eac326 100644 --- a/doc/symbols/src/lib_TrivialReporter.js.html +++ b/doc/symbols/src/lib_TrivialReporter.js.html @@ -96,31 +96,29 @@ 89 for (var i = 0; i < resultItems.length; i++) { 90 var result = resultItems[i]; 91 if (result.passed && !result.passed()) { - 92 var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'}); - 93 resultMessageDiv.innerHTML = result.message; // todo: lame; mend - 94 specDiv.appendChild(resultMessageDiv); - 95 specDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); - 96 } - 97 } - 98 this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv); - 99 }; -100 -101 jasmine.TrivialReporter.prototype.log = function() { -102 console.log.apply(console, arguments); -103 }; -104 -105 jasmine.TrivialReporter.prototype.getLocation = function() { -106 return this.document.location; -107 }; -108 -109 jasmine.TrivialReporter.prototype.specFilter = function(spec) { -110 var paramMap = {}; -111 var params = this.getLocation().search.substring(1).split('&'); -112 for (var i = 0; i < params.length; i++) { -113 var p = params[i].split('='); -114 paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); -115 } -116 -117 if (!paramMap["spec"]) return true; -118 return spec.getFullName().indexOf(paramMap["spec"]) == 0; -119 }; \ No newline at end of file + 92 specDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); + 93 specDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); + 94 } + 95 } + 96 this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv); + 97 }; + 98 + 99 jasmine.TrivialReporter.prototype.log = function() { +100 console.log.apply(console, arguments); +101 }; +102 +103 jasmine.TrivialReporter.prototype.getLocation = function() { +104 return this.document.location; +105 }; +106 +107 jasmine.TrivialReporter.prototype.specFilter = function(spec) { +108 var paramMap = {}; +109 var params = this.getLocation().search.substring(1).split('&'); +110 for (var i = 0; i < params.length; i++) { +111 var p = params[i].split('='); +112 paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); +113 } +114 +115 if (!paramMap["spec"]) return true; +116 return spec.getFullName().indexOf(paramMap["spec"]) == 0; +117 }; \ No newline at end of file diff --git a/doc/symbols/src/src_Env.js.html b/doc/symbols/src/src_Env.js.html index e004986..7b46e68 100644 --- a/doc/symbols/src/src_Env.js.html +++ b/doc/symbols/src/src_Env.js.html @@ -17,7 +17,7 @@ 10 11 this.reporter = new jasmine.MultiReporter(); 12 - 13 this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL + 13 this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL; 14 this.lastUpdate = 0; 15 this.specFilter = function() { 16 return true; @@ -26,207 +26,218 @@ 19 this.nextSpecId_ = 0; 20 this.nextSuiteId_ = 0; 21 this.equalityTesters_ = []; - 22 }; - 23 - 24 - 25 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; - 26 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; - 27 jasmine.Env.prototype.setInterval = jasmine.setInterval; - 28 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; - 29 - 30 /** - 31 * @returns an object containing jasmine version build info, if set. - 32 */ - 33 jasmine.Env.prototype.version = function () { - 34 if (jasmine.version_) { - 35 return jasmine.version_; - 36 } else { - 37 throw new Error('Version not set'); - 38 } - 39 }; + 22 + 23 // wrap matchers + 24 this.matchersClass = function() { + 25 jasmine.Matchers.apply(this, arguments); + 26 }; + 27 jasmine.util.inherit(this.matchersClass, jasmine.Matchers); + 28 + 29 for (var methodName in jasmine.Matchers.prototype) { + 30 var orig = jasmine.Matchers.prototype[methodName]; + 31 this.matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); + 32 } + 33 }; + 34 + 35 + 36 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; + 37 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; + 38 jasmine.Env.prototype.setInterval = jasmine.setInterval; + 39 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; 40 41 /** - 42 * @returns a sequential integer starting at 0 + 42 * @returns an object containing jasmine version build info, if set. 43 */ - 44 jasmine.Env.prototype.nextSpecId = function () { - 45 return this.nextSpecId_++; - 46 }; - 47 - 48 /** - 49 * @returns a sequential integer starting at 0 - 50 */ - 51 jasmine.Env.prototype.nextSuiteId = function () { - 52 return this.nextSuiteId_++; - 53 }; - 54 - 55 /** - 56 * Register a reporter to receive status updates from Jasmine. - 57 * @param {jasmine.Reporter} reporter An object which will receive status updates. - 58 */ - 59 jasmine.Env.prototype.addReporter = function(reporter) { - 60 this.reporter.addReporter(reporter); - 61 }; - 62 - 63 jasmine.Env.prototype.execute = function() { - 64 this.currentRunner_.execute(); - 65 }; - 66 - 67 jasmine.Env.prototype.describe = function(description, specDefinitions) { - 68 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); - 69 - 70 var parentSuite = this.currentSuite; - 71 if (parentSuite) { - 72 parentSuite.add(suite); - 73 } else { - 74 this.currentRunner_.add(suite); - 75 } - 76 - 77 this.currentSuite = suite; - 78 - 79 specDefinitions.call(suite); + 44 jasmine.Env.prototype.version = function () { + 45 if (jasmine.version_) { + 46 return jasmine.version_; + 47 } else { + 48 throw new Error('Version not set'); + 49 } + 50 }; + 51 + 52 /** + 53 * @returns a sequential integer starting at 0 + 54 */ + 55 jasmine.Env.prototype.nextSpecId = function () { + 56 return this.nextSpecId_++; + 57 }; + 58 + 59 /** + 60 * @returns a sequential integer starting at 0 + 61 */ + 62 jasmine.Env.prototype.nextSuiteId = function () { + 63 return this.nextSuiteId_++; + 64 }; + 65 + 66 /** + 67 * Register a reporter to receive status updates from Jasmine. + 68 * @param {jasmine.Reporter} reporter An object which will receive status updates. + 69 */ + 70 jasmine.Env.prototype.addReporter = function(reporter) { + 71 this.reporter.addReporter(reporter); + 72 }; + 73 + 74 jasmine.Env.prototype.execute = function() { + 75 this.currentRunner_.execute(); + 76 }; + 77 + 78 jasmine.Env.prototype.describe = function(description, specDefinitions) { + 79 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); 80 - 81 this.currentSuite = parentSuite; - 82 - 83 return suite; - 84 }; - 85 - 86 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { - 87 if (this.currentSuite) { - 88 this.currentSuite.beforeEach(beforeEachFunction); - 89 } else { - 90 this.currentRunner_.beforeEach(beforeEachFunction); - 91 } - 92 }; + 81 var parentSuite = this.currentSuite; + 82 if (parentSuite) { + 83 parentSuite.add(suite); + 84 } else { + 85 this.currentRunner_.add(suite); + 86 } + 87 + 88 this.currentSuite = suite; + 89 + 90 specDefinitions.call(suite); + 91 + 92 this.currentSuite = parentSuite; 93 - 94 jasmine.Env.prototype.currentRunner = function () { - 95 return this.currentRunner_; - 96 }; - 97 - 98 jasmine.Env.prototype.afterEach = function(afterEachFunction) { - 99 if (this.currentSuite) { -100 this.currentSuite.afterEach(afterEachFunction); -101 } else { -102 this.currentRunner_.afterEach(afterEachFunction); -103 } + 94 return suite; + 95 }; + 96 + 97 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { + 98 if (this.currentSuite) { + 99 this.currentSuite.beforeEach(beforeEachFunction); +100 } else { +101 this.currentRunner_.beforeEach(beforeEachFunction); +102 } +103 }; 104 -105 }; -106 -107 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { -108 return { -109 execute: function() { -110 } -111 }; -112 }; -113 -114 jasmine.Env.prototype.it = function(description, func) { -115 var spec = new jasmine.Spec(this, this.currentSuite, description); -116 this.currentSuite.add(spec); -117 this.currentSpec = spec; -118 -119 if (func) { -120 spec.runs(func); -121 } -122 -123 return spec; -124 }; -125 -126 jasmine.Env.prototype.xit = function(desc, func) { -127 return { -128 id: this.nextSpecId(), -129 runs: function() { -130 } -131 }; -132 }; +105 jasmine.Env.prototype.currentRunner = function () { +106 return this.currentRunner_; +107 }; +108 +109 jasmine.Env.prototype.afterEach = function(afterEachFunction) { +110 if (this.currentSuite) { +111 this.currentSuite.afterEach(afterEachFunction); +112 } else { +113 this.currentRunner_.afterEach(afterEachFunction); +114 } +115 +116 }; +117 +118 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +119 return { +120 execute: function() { +121 } +122 }; +123 }; +124 +125 jasmine.Env.prototype.it = function(description, func) { +126 var spec = new jasmine.Spec(this, this.currentSuite, description); +127 this.currentSuite.add(spec); +128 this.currentSpec = spec; +129 +130 if (func) { +131 spec.runs(func); +132 } 133 -134 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { -135 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { -136 return true; -137 } -138 -139 a.__Jasmine_been_here_before__ = b; -140 b.__Jasmine_been_here_before__ = a; -141 -142 var hasKey = function(obj, keyName) { -143 return obj != null && obj[keyName] !== undefined; -144 }; -145 -146 for (var property in b) { -147 if (!hasKey(a, property) && hasKey(b, property)) { -148 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); -149 } -150 } -151 for (property in a) { -152 if (!hasKey(b, property) && hasKey(a, property)) { -153 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); -154 } -155 } -156 for (property in b) { -157 if (property == '__Jasmine_been_here_before__') continue; -158 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { -159 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); +134 return spec; +135 }; +136 +137 jasmine.Env.prototype.xit = function(desc, func) { +138 return { +139 id: this.nextSpecId(), +140 runs: function() { +141 } +142 }; +143 }; +144 +145 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { +146 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { +147 return true; +148 } +149 +150 a.__Jasmine_been_here_before__ = b; +151 b.__Jasmine_been_here_before__ = a; +152 +153 var hasKey = function(obj, keyName) { +154 return obj != null && obj[keyName] !== jasmine.undefined; +155 }; +156 +157 for (var property in b) { +158 if (!hasKey(a, property) && hasKey(b, property)) { +159 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); 160 } 161 } -162 -163 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { -164 mismatchValues.push("arrays were not the same length"); -165 } -166 -167 delete a.__Jasmine_been_here_before__; -168 delete b.__Jasmine_been_here_before__; -169 return (mismatchKeys.length == 0 && mismatchValues.length == 0); -170 }; -171 -172 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { -173 mismatchKeys = mismatchKeys || []; -174 mismatchValues = mismatchValues || []; -175 -176 if (a === b) return true; +162 for (property in a) { +163 if (!hasKey(b, property) && hasKey(a, property)) { +164 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); +165 } +166 } +167 for (property in b) { +168 if (property == '__Jasmine_been_here_before__') continue; +169 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { +170 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); +171 } +172 } +173 +174 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { +175 mismatchValues.push("arrays were not the same length"); +176 } 177 -178 if (a === undefined || a === null || b === undefined || b === null) { -179 return (a == undefined && b == undefined); -180 } -181 -182 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -183 return a === b; -184 } -185 -186 if (a instanceof Date && b instanceof Date) { -187 return a.getTime() == b.getTime(); -188 } -189 -190 if (a instanceof jasmine.Matchers.Any) { -191 return a.matches(b); -192 } -193 -194 if (b instanceof jasmine.Matchers.Any) { -195 return b.matches(a); -196 } -197 -198 if (typeof a === "object" && typeof b === "object") { -199 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -200 } -201 -202 for (var i = 0; i < this.equalityTesters_.length; i++) { -203 var equalityTester = this.equalityTesters_[i]; -204 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -205 if (result !== undefined) return result; -206 } -207 -208 //Straight check -209 return (a === b); -210 }; -211 -212 jasmine.Env.prototype.contains_ = function(haystack, needle) { -213 if (jasmine.isArray_(haystack)) { -214 for (var i = 0; i < haystack.length; i++) { -215 if (this.equals_(haystack[i], needle)) return true; -216 } -217 return false; -218 } -219 return haystack.indexOf(needle) >= 0; -220 }; -221 -222 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -223 this.equalityTesters_.push(equalityTester); -224 }; -225 \ No newline at end of file +178 delete a.__Jasmine_been_here_before__; +179 delete b.__Jasmine_been_here_before__; +180 return (mismatchKeys.length == 0 && mismatchValues.length == 0); +181 }; +182 +183 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +184 mismatchKeys = mismatchKeys || []; +185 mismatchValues = mismatchValues || []; +186 +187 if (a === b) return true; +188 +189 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { +190 return (a == jasmine.undefined && b == jasmine.undefined); +191 } +192 +193 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +194 return a === b; +195 } +196 +197 if (a instanceof Date && b instanceof Date) { +198 return a.getTime() == b.getTime(); +199 } +200 +201 if (a instanceof jasmine.Matchers.Any) { +202 return a.matches(b); +203 } +204 +205 if (b instanceof jasmine.Matchers.Any) { +206 return b.matches(a); +207 } +208 +209 if (typeof a === "object" && typeof b === "object") { +210 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +211 } +212 +213 for (var i = 0; i < this.equalityTesters_.length; i++) { +214 var equalityTester = this.equalityTesters_[i]; +215 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); +216 if (result !== jasmine.undefined) return result; +217 } +218 +219 //Straight check +220 return (a === b); +221 }; +222 +223 jasmine.Env.prototype.contains_ = function(haystack, needle) { +224 if (jasmine.isArray_(haystack)) { +225 for (var i = 0; i < haystack.length; i++) { +226 if (this.equals_(haystack[i], needle)) return true; +227 } +228 return false; +229 } +230 return haystack.indexOf(needle) >= 0; +231 }; +232 +233 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +234 this.equalityTesters_.push(equalityTester); +235 }; +236 \ No newline at end of file diff --git a/doc/symbols/src/src_JsApiReporter.js.html b/doc/symbols/src/src_JsApiReporter.js.html index fa4bd53..8097661 100644 --- a/doc/symbols/src/src_JsApiReporter.js.html +++ b/doc/symbols/src/src_JsApiReporter.js.html @@ -86,25 +86,26 @@ 79 80 jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ 81 var summaryMessages = []; - 82 for (var messageIndex in result.messages) { - 83 var resultMessage = result.messages[messageIndex]; - 84 summaryMessages.push({ - 85 text: resultMessage.text, - 86 passed: resultMessage.passed ? resultMessage.passed() : true, - 87 type: resultMessage.type, - 88 message: resultMessage.message, - 89 trace: { - 90 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : undefined - 91 } - 92 }); - 93 }; - 94 - 95 var summaryResult = { - 96 result : result.result, - 97 messages : summaryMessages - 98 }; - 99 -100 return summaryResult; -101 }; -102 -103 \ No newline at end of file + 82 var messagesLength = result.messages.length + 83 for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) { + 84 var resultMessage = result.messages[messageIndex]; + 85 summaryMessages.push({ + 86 text: resultMessage.text, + 87 passed: resultMessage.passed ? resultMessage.passed() : true, + 88 type: resultMessage.type, + 89 message: resultMessage.message, + 90 trace: { + 91 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined + 92 } + 93 }); + 94 }; + 95 + 96 var summaryResult = { + 97 result : result.result, + 98 messages : summaryMessages + 99 }; +100 +101 return summaryResult; +102 }; +103 +104 \ No newline at end of file diff --git a/doc/symbols/src/src_Matchers.js.html b/doc/symbols/src/src_Matchers.js.html index 17275cf..0000319 100644 --- a/doc/symbols/src/src_Matchers.js.html +++ b/doc/symbols/src/src_Matchers.js.html @@ -31,57 +31,57 @@ 24 return result; 25 }; 26 - 27 jasmine.Matchers.matcherFn_ = function(matcherName, options) { - 28 return function () { - 29 jasmine.util.extend(this, options); - 30 var matcherArgs = jasmine.util.argsToArray(arguments); - 31 var args = [this.actual].concat(matcherArgs); - 32 var result = options.test.apply(this, args); - 33 var message; - 34 if (!result) { - 35 message = options.message.apply(this, args); - 36 } - 37 var expectationResult = new jasmine.ExpectationResult({ - 38 matcherName: matcherName, - 39 passed: result, - 40 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], - 41 actual: this.actual, - 42 message: message - 43 }); - 44 this.spec.addMatcherResult(expectationResult); - 45 return result; - 46 }; - 47 }; - 48 - 49 - 50 - 51 - 52 /** - 53 * toBe: compares the actual to the expected using === - 54 * @param expected - 55 */ - 56 - 57 jasmine.Matchers.prototype.toBe = jasmine.Matchers.matcherFn_('toBe', { - 58 test: function (actual, expected) { - 59 return actual === expected; - 60 }, - 61 message: function(actual, expected) { - 62 return "Expected " + jasmine.pp(actual) + " to be " + jasmine.pp(expected); - 63 } - 64 }); - 65 - 66 /** - 67 * toNotBe: compares the actual to the expected using !== - 68 * @param expected - 69 */ - 70 jasmine.Matchers.prototype.toNotBe = jasmine.Matchers.matcherFn_('toNotBe', { - 71 test: function (actual, expected) { - 72 return actual !== expected; - 73 }, - 74 message: function(actual, expected) { - 75 return "Expected " + jasmine.pp(actual) + " to not be " + jasmine.pp(expected); - 76 } - 77 }); + 27 jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { + 28 return function() { + 29 var matcherArgs = jasmine.util.argsToArray(arguments); + 30 var result = matcherFunction.apply(this, arguments); + 31 var message; + 32 if (!result) { + 33 if (this.message) { + 34 message = this.message.apply(this, arguments); + 35 } else { + 36 var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); + 37 message = "Expected " + jasmine.pp(this.actual) + " " + englishyPredicate; + 38 if (matcherArgs.length > 0) { + 39 for (var i = 0; i < matcherArgs.length; i++) { + 40 if (i > 0) message += ","; + 41 message += " " + jasmine.pp(matcherArgs[i]); + 42 } + 43 } + 44 message += "."; + 45 } + 46 } + 47 var expectationResult = new jasmine.ExpectationResult({ + 48 matcherName: matcherName, + 49 passed: result, + 50 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], + 51 actual: this.actual, + 52 message: message + 53 }); + 54 this.spec.addMatcherResult(expectationResult); + 55 return result; + 56 }; + 57 }; + 58 + 59 + 60 + 61 + 62 /** + 63 * toBe: compares the actual to the expected using === + 64 * @param expected + 65 */ + 66 + 67 jasmine.Matchers.prototype.toBe = function(expected) { + 68 return this.actual === expected; + 69 }; + 70 + 71 /** + 72 * toNotBe: compares the actual to the expected using !== + 73 * @param expected + 74 */ + 75 jasmine.Matchers.prototype.toNotBe = function(expected) { + 76 return this.actual !== expected; + 77 }; 78 79 /** 80 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. @@ -89,311 +89,233 @@ 82 * @param expected 83 */ 84 - 85 jasmine.Matchers.prototype.toEqual = jasmine.Matchers.matcherFn_('toEqual', { - 86 test: function (actual, expected) { - 87 return this.env.equals_(actual, expected); - 88 }, - 89 message: function(actual, expected) { - 90 return "Expected " + jasmine.pp(actual) + " to equal " + jasmine.pp(expected); - 91 } - 92 }); - 93 - 94 /** - 95 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual - 96 * @param expected - 97 */ - 98 jasmine.Matchers.prototype.toNotEqual = jasmine.Matchers.matcherFn_('toNotEqual', { - 99 test: function (actual, expected) { -100 return !this.env.equals_(actual, expected); -101 }, -102 message: function(actual, expected) { -103 return "Expected " + jasmine.pp(actual) + " to not equal " + jasmine.pp(expected); -104 } -105 }); + 85 jasmine.Matchers.prototype.toEqual = function(expected) { + 86 return this.env.equals_(this.actual, expected); + 87 }; + 88 + 89 /** + 90 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual + 91 * @param expected + 92 */ + 93 jasmine.Matchers.prototype.toNotEqual = function(expected) { + 94 return !this.env.equals_(this.actual, expected); + 95 }; + 96 + 97 /** + 98 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes + 99 * a pattern or a String. +100 * +101 * @param reg_exp +102 */ +103 jasmine.Matchers.prototype.toMatch = function(expected) { +104 return new RegExp(expected).test(this.actual); +105 }; 106 107 /** -108 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -109 * a pattern or a String. -110 * -111 * @param reg_exp -112 */ -113 jasmine.Matchers.prototype.toMatch = jasmine.Matchers.matcherFn_('toMatch', { -114 test: function(actual, expected) { -115 return new RegExp(expected).test(actual); -116 }, -117 message: function(actual, expected) { -118 return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString(); -119 } -120 }); +108 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +109 * @param reg_exp +110 */ +111 jasmine.Matchers.prototype.toNotMatch = function(expected) { +112 return !(new RegExp(expected).test(this.actual)); +113 }; +114 +115 /** +116 * Matcher that compares the actual to jasmine.undefined. +117 */ +118 jasmine.Matchers.prototype.toBeDefined = function() { +119 return (this.actual !== jasmine.undefined); +120 }; 121 122 /** -123 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -124 * @param reg_exp -125 */ -126 -127 jasmine.Matchers.prototype.toNotMatch = jasmine.Matchers.matcherFn_('toNotMatch', { -128 test: function(actual, expected) { -129 return !(new RegExp(expected).test(actual)); -130 }, -131 message: function(actual, expected) { -132 return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString(); -133 } -134 }); +123 * Matcher that compares the actual to jasmine.undefined. +124 */ +125 jasmine.Matchers.prototype.toBeUndefined = function() { +126 return (this.actual === jasmine.undefined); +127 }; +128 +129 /** +130 * Matcher that compares the actual to null. +131 */ +132 jasmine.Matchers.prototype.toBeNull = function() { +133 return (this.actual === null); +134 }; 135 136 /** -137 * Matcher that compares the acutal to undefined. +137 * Matcher that boolean not-nots the actual. 138 */ -139 -140 jasmine.Matchers.prototype.toBeDefined = jasmine.Matchers.matcherFn_('toBeDefined', { -141 test: function(actual) { -142 return (actual !== undefined); -143 }, -144 message: function() { -145 return 'Expected actual to not be undefined.'; -146 } -147 }); -148 -149 /** -150 * Matcher that compares the acutal to undefined. -151 */ -152 -153 jasmine.Matchers.prototype.toBeUndefined = jasmine.Matchers.matcherFn_('toBeUndefined', { -154 test: function(actual) { -155 return (actual === undefined); -156 }, -157 message: function(actual) { -158 return 'Expected ' + jasmine.pp(actual) + ' to be undefined.'; -159 } -160 }); -161 -162 /** -163 * Matcher that compares the actual to null. -164 * -165 */ -166 jasmine.Matchers.prototype.toBeNull = jasmine.Matchers.matcherFn_('toBeNull', { -167 test: function(actual) { -168 return (actual === null); -169 }, -170 message: function(actual) { -171 return 'Expected ' + jasmine.pp(actual) + ' to be null.'; -172 } -173 }); -174 -175 /** -176 * Matcher that boolean not-nots the actual. -177 */ -178 jasmine.Matchers.prototype.toBeTruthy = jasmine.Matchers.matcherFn_('toBeTruthy', { -179 test: function(actual) { -180 return !!actual; -181 }, -182 message: function() { -183 return 'Expected actual to be truthy'; -184 } -185 }); -186 -187 -188 /** -189 * Matcher that boolean nots the actual. -190 */ -191 jasmine.Matchers.prototype.toBeFalsy = jasmine.Matchers.matcherFn_('toBeFalsy', { -192 test: function(actual) { -193 return !actual; -194 }, -195 message: function(actual) { -196 return 'Expected ' + jasmine.pp(actual) + ' to be falsy'; -197 } -198 }); +139 jasmine.Matchers.prototype.toBeTruthy = function() { +140 return !!this.actual; +141 }; +142 +143 +144 /** +145 * Matcher that boolean nots the actual. +146 */ +147 jasmine.Matchers.prototype.toBeFalsy = function() { +148 return !this.actual; +149 }; +150 +151 /** +152 * Matcher that checks to see if the actual, a Jasmine spy, was called. +153 */ +154 jasmine.Matchers.prototype.wasCalled = function() { +155 if (arguments.length > 0) { +156 throw new Error('wasCalled does not take arguments, use wasCalledWith'); +157 } +158 +159 if (!jasmine.isSpy(this.actual)) { +160 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +161 } +162 +163 this.message = function() { +164 return "Expected spy " + this.actual.identity + " to have been called."; +165 }; +166 +167 return this.actual.wasCalled; +168 }; +169 +170 /** +171 * Matcher that checks to see if the actual, a Jasmine spy, was not called. +172 */ +173 jasmine.Matchers.prototype.wasNotCalled = function() { +174 if (arguments.length > 0) { +175 throw new Error('wasNotCalled does not take arguments'); +176 } +177 +178 if (!jasmine.isSpy(this.actual)) { +179 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +180 } +181 +182 this.message = function() { +183 return "Expected spy " + this.actual.identity + " to not have been called."; +184 }; +185 +186 return !this.actual.wasCalled; +187 }; +188 +189 /** +190 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. +191 * +192 * @example +193 * +194 */ +195 jasmine.Matchers.prototype.wasCalledWith = function() { +196 if (!jasmine.isSpy(this.actual)) { +197 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +198 } 199 -200 /** -201 * Matcher that checks to see if the acutal, a Jasmine spy, was called. -202 */ -203 -204 jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.matcherFn_('wasCalled', { -205 getActual_: function() { -206 var args = jasmine.util.argsToArray(arguments); -207 if (args.length > 1) { -208 throw(new Error('wasCalled does not take arguments, use wasCalledWith')); -209 } -210 return args.splice(0, 1)[0]; -211 }, -212 test: function() { -213 var actual = this.getActual_.apply(this, arguments); -214 if (!actual || !actual.isSpy) { -215 return false; -216 } -217 return actual.wasCalled; -218 }, -219 message: function() { -220 var actual = this.getActual_.apply(this, arguments); -221 if (!actual || !actual.isSpy) { -222 return 'Actual is not a spy.'; -223 } -224 return "Expected spy " + actual.identity + " to have been called."; -225 } -226 }); -227 -228 /** -229 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. -230 */ -231 jasmine.Matchers.prototype.wasNotCalled = jasmine.Matchers.matcherFn_('wasNotCalled', { -232 getActual_: function() { -233 var args = jasmine.util.argsToArray(arguments); -234 return args.splice(0, 1)[0]; -235 }, -236 test: function() { -237 var actual = this.getActual_.apply(this, arguments); -238 if (!actual || !actual.isSpy) { -239 return false; -240 } -241 return !actual.wasCalled; -242 }, -243 message: function() { -244 var actual = this.getActual_.apply(this, arguments); -245 if (!actual || !actual.isSpy) { -246 return 'Actual is not a spy.'; -247 } -248 return "Expected spy " + actual.identity + " to not have been called."; -249 } -250 }); -251 -252 jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.matcherFn_('wasCalledWith', { -253 test: function() { -254 var args = jasmine.util.argsToArray(arguments); -255 var actual = args.splice(0, 1)[0]; -256 if (!actual || !actual.isSpy) { -257 return false; -258 } -259 return this.env.contains_(actual.argsForCall, args); -260 }, -261 message: function() { -262 var args = jasmine.util.argsToArray(arguments); -263 var actual = args.splice(0, 1)[0]; -264 var message; -265 if (!actual || !actual.isSpy) { -266 message = 'Actual is not a spy'; -267 } else { -268 message = "Expected spy to have been called with " + jasmine.pp(args) + " but was called with " + actual.argsForCall; -269 } -270 return message; -271 } -272 }); +200 this.message = function() { +201 if (this.actual.callCount == 0) { +202 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; +203 } else { +204 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); +205 } +206 }; +207 +208 return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +209 }; +210 +211 jasmine.Matchers.prototype.wasNotCalledWith = function() { +212 if (!jasmine.isSpy(this.actual)) { +213 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +214 } +215 +216 this.message = function() { +217 return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; +218 }; +219 +220 return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +221 }; +222 +223 /** +224 * Matcher that checks that the expected item is an element in the actual Array. +225 * +226 * @param {Object} item +227 */ +228 jasmine.Matchers.prototype.toContain = function(expected) { +229 return this.env.contains_(this.actual, expected); +230 }; +231 +232 /** +233 * Matcher that checks that the expected item is NOT an element in the actual Array. +234 * +235 * @param {Object} item +236 */ +237 jasmine.Matchers.prototype.toNotContain = function(expected) { +238 return !this.env.contains_(this.actual, expected); +239 }; +240 +241 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +242 return this.actual < expected; +243 }; +244 +245 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +246 return this.actual > expected; +247 }; +248 +249 /** +250 * Matcher that checks that the expected exception was thrown by the actual. +251 * +252 * @param {String} expectedException +253 */ +254 jasmine.Matchers.prototype.toThrow = function(expected) { +255 function getException_(actual, expected) { +256 var exception; +257 if (typeof actual != 'function') { +258 throw new Error('Actual is not a function'); +259 } +260 try { +261 actual(); +262 } catch (e) { +263 exception = e; +264 } +265 return exception; +266 } +267 +268 var result = false; +269 var exception = getException_(this.actual, expected); +270 if (exception) { +271 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +272 } 273 -274 /** -275 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. -276 * -277 * @example -278 * -279 */ -280 -281 /** -282 * Matcher that checks that the expected item is an element in the actual Array. -283 * -284 * @param {Object} item -285 */ -286 -287 jasmine.Matchers.prototype.toContain = jasmine.Matchers.matcherFn_('toContain', { -288 test: function(actual, expected) { -289 return this.env.contains_(actual, expected); -290 }, -291 message: function(actual, expected) { -292 return 'Expected ' + jasmine.pp(actual) + ' to contain ' + jasmine.pp(expected); +274 this.message = function(expected) { +275 var exception = getException_(this.actual, expected); +276 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { +277 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); +278 } else { +279 return "Expected function to throw an exception."; +280 } +281 }; +282 +283 return result; +284 }; +285 +286 jasmine.Matchers.Any = function(expectedClass) { +287 this.expectedClass = expectedClass; +288 }; +289 +290 jasmine.Matchers.Any.prototype.matches = function(other) { +291 if (this.expectedClass == String) { +292 return typeof other == 'string' || other instanceof String; 293 } -294 }); -295 -296 /** -297 * Matcher that checks that the expected item is NOT an element in the actual Array. -298 * -299 * @param {Object} item -300 */ -301 jasmine.Matchers.prototype.toNotContain = jasmine.Matchers.matcherFn_('toNotContain', { -302 test: function(actual, expected) { -303 return !this.env.contains_(actual, expected); -304 }, -305 message: function(actual, expected) { -306 return 'Expected ' + jasmine.pp(actual) + ' to not contain ' + jasmine.pp(expected); -307 } -308 }); +294 +295 if (this.expectedClass == Number) { +296 return typeof other == 'number' || other instanceof Number; +297 } +298 +299 if (this.expectedClass == Function) { +300 return typeof other == 'function' || other instanceof Function; +301 } +302 +303 if (this.expectedClass == Object) { +304 return typeof other == 'object'; +305 } +306 +307 return other instanceof this.expectedClass; +308 }; 309 -310 jasmine.Matchers.prototype.toBeLessThan = jasmine.Matchers.matcherFn_('toBeLessThan', { -311 test: function(actual, expected) { -312 return actual < expected; -313 }, -314 message: function(actual, expected) { -315 return 'Expected ' + jasmine.pp(actual) + ' to be less than ' + jasmine.pp(expected); -316 } -317 }); -318 -319 jasmine.Matchers.prototype.toBeGreaterThan = jasmine.Matchers.matcherFn_('toBeGreaterThan', { -320 test: function(actual, expected) { -321 return actual > expected; -322 }, -323 message: function(actual, expected) { -324 return 'Expected ' + jasmine.pp(actual) + ' to be greater than ' + jasmine.pp(expected); -325 } -326 }); -327 -328 /** -329 * Matcher that checks that the expected exception was thrown by the actual. -330 * -331 * @param {String} expectedException -332 */ -333 jasmine.Matchers.prototype.toThrow = jasmine.Matchers.matcherFn_('toThrow', { -334 getException_: function(actual, expected) { -335 var exception; -336 if (typeof actual != 'function') { -337 throw new Error('Actual is not a function'); -338 } -339 try { -340 actual(); -341 } catch (e) { -342 exception = e; -343 } -344 return exception; -345 }, -346 test: function(actual, expected) { -347 var result = false; -348 var exception = this.getException_(actual, expected); -349 if (exception) { -350 result = (expected === undefined || this.env.equals_(exception.message || exception, expected.message || expected)); -351 } -352 return result; -353 }, -354 message: function(actual, expected) { -355 var exception = this.getException_(actual, expected); -356 if (exception && (expected === undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -357 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); -358 } else { -359 return "Expected function to throw an exception."; -360 } -361 } -362 }); -363 -364 jasmine.Matchers.Any = function(expectedClass) { -365 this.expectedClass = expectedClass; -366 }; -367 -368 jasmine.Matchers.Any.prototype.matches = function(other) { -369 if (this.expectedClass == String) { -370 return typeof other == 'string' || other instanceof String; -371 } -372 -373 if (this.expectedClass == Number) { -374 return typeof other == 'number' || other instanceof Number; -375 } -376 -377 if (this.expectedClass == Function) { -378 return typeof other == 'function' || other instanceof Function; -379 } -380 -381 if (this.expectedClass == Object) { -382 return typeof other == 'object'; -383 } -384 -385 return other instanceof this.expectedClass; -386 }; -387 -388 jasmine.Matchers.Any.prototype.toString = function() { -389 return '<jasmine.any(' + this.expectedClass + ')>'; -390 }; -391 -392 \ No newline at end of file +310 jasmine.Matchers.Any.prototype.toString = function() { +311 return '<jasmine.any(' + this.expectedClass + ')>'; +312 }; +313 +314 \ No newline at end of file diff --git a/doc/symbols/src/src_PrettyPrinter.js.html b/doc/symbols/src/src_PrettyPrinter.js.html index 0508164..6b112d0 100644 --- a/doc/symbols/src/src_PrettyPrinter.js.html +++ b/doc/symbols/src/src_PrettyPrinter.js.html @@ -16,113 +16,115 @@ 9 * Formats a value in a nice, human-readable string. 10 * 11 * @param value - 12 * @returns {String} - 13 */ - 14 jasmine.PrettyPrinter.prototype.format = function(value) { - 15 if (this.ppNestLevel_ > 40) { - 16 // return '(jasmine.pp nested too deeply!)'; - 17 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); - 18 } - 19 - 20 this.ppNestLevel_++; - 21 try { - 22 if (value === undefined) { - 23 this.emitScalar('undefined'); - 24 } else if (value === null) { - 25 this.emitScalar('null'); - 26 } else if (value.navigator && value.frames && value.setTimeout) { - 27 this.emitScalar('<window>'); - 28 } else if (value instanceof jasmine.Matchers.Any) { - 29 this.emitScalar(value.toString()); - 30 } else if (typeof value === 'string') { - 31 this.emitString(value); - 32 } else if (typeof value === 'function') { - 33 this.emitScalar('Function'); - 34 } else if (typeof value.nodeType === 'number') { - 35 this.emitScalar('HTMLNode'); - 36 } else if (value instanceof Date) { - 37 this.emitScalar('Date(' + value + ')'); - 38 } else if (value.__Jasmine_been_here_before__) { - 39 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); - 40 } else if (jasmine.isArray_(value) || typeof value == 'object') { - 41 value.__Jasmine_been_here_before__ = true; - 42 if (jasmine.isArray_(value)) { - 43 this.emitArray(value); - 44 } else { - 45 this.emitObject(value); - 46 } - 47 delete value.__Jasmine_been_here_before__; - 48 } else { - 49 this.emitScalar(value.toString()); - 50 } - 51 } finally { - 52 this.ppNestLevel_--; - 53 } - 54 }; - 55 - 56 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { - 57 for (var property in obj) { - 58 if (property == '__Jasmine_been_here_before__') continue; - 59 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); - 60 } - 61 }; - 62 - 63 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; - 64 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; - 65 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; - 66 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; - 67 - 68 jasmine.StringPrettyPrinter = function() { - 69 jasmine.PrettyPrinter.call(this); - 70 - 71 this.string = ''; - 72 }; - 73 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); - 74 - 75 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { - 76 this.append(value); - 77 }; - 78 - 79 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { - 80 this.append("'" + value + "'"); - 81 }; - 82 - 83 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { - 84 this.append('[ '); - 85 for (var i = 0; i < array.length; i++) { - 86 if (i > 0) { - 87 this.append(', '); - 88 } - 89 this.format(array[i]); - 90 } - 91 this.append(' ]'); - 92 }; - 93 - 94 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { - 95 var self = this; - 96 this.append('{ '); - 97 var first = true; - 98 - 99 this.iterateObject(obj, function(property, isGetter) { -100 if (first) { -101 first = false; -102 } else { -103 self.append(', '); -104 } -105 -106 self.append(property); -107 self.append(' : '); -108 if (isGetter) { -109 self.append('<getter>'); -110 } else { -111 self.format(obj[property]); -112 } -113 }); -114 -115 this.append(' }'); -116 }; -117 -118 jasmine.StringPrettyPrinter.prototype.append = function(value) { -119 this.string += value; -120 }; -121 \ No newline at end of file + 12 */ + 13 jasmine.PrettyPrinter.prototype.format = function(value) { + 14 if (this.ppNestLevel_ > 40) { + 15 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); + 16 } + 17 + 18 this.ppNestLevel_++; + 19 try { + 20 if (value === jasmine.undefined) { + 21 this.emitScalar('undefined'); + 22 } else if (value === null) { + 23 this.emitScalar('null'); + 24 } else if (value.navigator && value.frames && value.setTimeout) { + 25 this.emitScalar('<window>'); + 26 } else if (value instanceof jasmine.Matchers.Any) { + 27 this.emitScalar(value.toString()); + 28 } else if (typeof value === 'string') { + 29 this.emitString(value); + 30 } else if (jasmine.isSpy(value)) { + 31 this.emitScalar("spy on " + value.identity); + 32 } else if (value instanceof RegExp) { + 33 this.emitScalar(value.toString()); + 34 } else if (typeof value === 'function') { + 35 this.emitScalar('Function'); + 36 } else if (typeof value.nodeType === 'number') { + 37 this.emitScalar('HTMLNode'); + 38 } else if (value instanceof Date) { + 39 this.emitScalar('Date(' + value + ')'); + 40 } else if (value.__Jasmine_been_here_before__) { + 41 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); + 42 } else if (jasmine.isArray_(value) || typeof value == 'object') { + 43 value.__Jasmine_been_here_before__ = true; + 44 if (jasmine.isArray_(value)) { + 45 this.emitArray(value); + 46 } else { + 47 this.emitObject(value); + 48 } + 49 delete value.__Jasmine_been_here_before__; + 50 } else { + 51 this.emitScalar(value.toString()); + 52 } + 53 } finally { + 54 this.ppNestLevel_--; + 55 } + 56 }; + 57 + 58 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { + 59 for (var property in obj) { + 60 if (property == '__Jasmine_been_here_before__') continue; + 61 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); + 62 } + 63 }; + 64 + 65 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; + 66 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; + 67 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; + 68 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; + 69 + 70 jasmine.StringPrettyPrinter = function() { + 71 jasmine.PrettyPrinter.call(this); + 72 + 73 this.string = ''; + 74 }; + 75 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); + 76 + 77 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { + 78 this.append(value); + 79 }; + 80 + 81 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { + 82 this.append("'" + value + "'"); + 83 }; + 84 + 85 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { + 86 this.append('[ '); + 87 for (var i = 0; i < array.length; i++) { + 88 if (i > 0) { + 89 this.append(', '); + 90 } + 91 this.format(array[i]); + 92 } + 93 this.append(' ]'); + 94 }; + 95 + 96 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { + 97 var self = this; + 98 this.append('{ '); + 99 var first = true; +100 +101 this.iterateObject(obj, function(property, isGetter) { +102 if (first) { +103 first = false; +104 } else { +105 self.append(', '); +106 } +107 +108 self.append(property); +109 self.append(' : '); +110 if (isGetter) { +111 self.append('<getter>'); +112 } else { +113 self.format(obj[property]); +114 } +115 }); +116 +117 this.append(' }'); +118 }; +119 +120 jasmine.StringPrettyPrinter.prototype.append = function(value) { +121 this.string += value; +122 }; +123 \ No newline at end of file diff --git a/doc/symbols/src/src_Spec.js.html b/doc/symbols/src/src_Spec.js.html index b550cf3..2523022 100644 --- a/doc/symbols/src/src_Spec.js.html +++ b/doc/symbols/src/src_Spec.js.html @@ -17,199 +17,197 @@ 10 if (!env) { 11 throw new Error('jasmine.Env() required'); 12 } - 13 ; - 14 if (!suite) { - 15 throw new Error('jasmine.Suite() required'); - 16 } - 17 ; - 18 var spec = this; - 19 spec.id = env.nextSpecId ? env.nextSpecId() : null; - 20 spec.env = env; - 21 spec.suite = suite; - 22 spec.description = description; - 23 spec.queue = new jasmine.Queue(env); - 24 - 25 spec.afterCallbacks = []; - 26 spec.spies_ = []; - 27 - 28 spec.results_ = new jasmine.NestedResults(); - 29 spec.results_.description = description; - 30 spec.matchersClass = null; - 31 }; - 32 - 33 jasmine.Spec.prototype.getFullName = function() { - 34 return this.suite.getFullName() + ' ' + this.description + '.'; - 35 }; - 36 - 37 - 38 jasmine.Spec.prototype.results = function() { - 39 return this.results_; - 40 }; - 41 - 42 jasmine.Spec.prototype.log = function(message) { - 43 return this.results_.log(message); - 44 }; - 45 - 46 /** @deprecated */ - 47 jasmine.Spec.prototype.getResults = function() { - 48 return this.results_; - 49 }; - 50 - 51 jasmine.Spec.prototype.runs = function (func) { - 52 var block = new jasmine.Block(this.env, func, this); - 53 this.addToQueue(block); - 54 return this; - 55 }; - 56 - 57 jasmine.Spec.prototype.addToQueue = function (block) { - 58 if (this.queue.isRunning()) { - 59 this.queue.insertNext(block); - 60 } else { - 61 this.queue.add(block); - 62 } - 63 }; - 64 - 65 jasmine.Spec.prototype.addMatcherResult = function(result) { - 66 this.results_.addResult(result); - 67 }; - 68 - 69 jasmine.Spec.prototype.expect = function(actual) { - 70 return new (this.getMatchersClass_())(this.env, actual, this); - 71 }; - 72 - 73 jasmine.Spec.prototype.waits = function(timeout) { - 74 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); - 75 this.addToQueue(waitsFunc); - 76 return this; - 77 }; - 78 - 79 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { - 80 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); - 81 this.addToQueue(waitsForFunc); - 82 return this; - 83 }; - 84 - 85 jasmine.Spec.prototype.fail = function (e) { - 86 var expectationResult = new jasmine.ExpectationResult({ - 87 passed: false, - 88 message: e ? jasmine.util.formatException(e) : 'Exception' - 89 }); - 90 this.results_.addResult(expectationResult); - 91 }; - 92 - 93 jasmine.Spec.prototype.getMatchersClass_ = function() { - 94 return this.matchersClass || jasmine.Matchers; - 95 }; - 96 - 97 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { - 98 var parent = this.getMatchersClass_(); - 99 var newMatchersClass = function() { -100 parent.apply(this, arguments); -101 }; -102 jasmine.util.inherit(newMatchersClass, parent); -103 for (var method in matchersPrototype) { -104 newMatchersClass.prototype[method] = matchersPrototype[method]; -105 } -106 this.matchersClass = newMatchersClass; -107 }; -108 -109 jasmine.Spec.prototype.finishCallback = function() { -110 this.env.reporter.reportSpecResults(this); -111 }; -112 -113 jasmine.Spec.prototype.finish = function(onComplete) { -114 this.removeAllSpies(); -115 this.finishCallback(); -116 if (onComplete) { -117 onComplete(); -118 } -119 }; + 13 if (!suite) { + 14 throw new Error('jasmine.Suite() required'); + 15 } + 16 var spec = this; + 17 spec.id = env.nextSpecId ? env.nextSpecId() : null; + 18 spec.env = env; + 19 spec.suite = suite; + 20 spec.description = description; + 21 spec.queue = new jasmine.Queue(env); + 22 + 23 spec.afterCallbacks = []; + 24 spec.spies_ = []; + 25 + 26 spec.results_ = new jasmine.NestedResults(); + 27 spec.results_.description = description; + 28 spec.matchersClass = null; + 29 }; + 30 + 31 jasmine.Spec.prototype.getFullName = function() { + 32 return this.suite.getFullName() + ' ' + this.description + '.'; + 33 }; + 34 + 35 + 36 jasmine.Spec.prototype.results = function() { + 37 return this.results_; + 38 }; + 39 + 40 jasmine.Spec.prototype.log = function(message) { + 41 return this.results_.log(message); + 42 }; + 43 + 44 /** @deprecated */ + 45 jasmine.Spec.prototype.getResults = function() { + 46 return this.results_; + 47 }; + 48 + 49 jasmine.Spec.prototype.runs = function (func) { + 50 var block = new jasmine.Block(this.env, func, this); + 51 this.addToQueue(block); + 52 return this; + 53 }; + 54 + 55 jasmine.Spec.prototype.addToQueue = function (block) { + 56 if (this.queue.isRunning()) { + 57 this.queue.insertNext(block); + 58 } else { + 59 this.queue.add(block); + 60 } + 61 }; + 62 + 63 jasmine.Spec.prototype.addMatcherResult = function(result) { + 64 this.results_.addResult(result); + 65 }; + 66 + 67 jasmine.Spec.prototype.expect = function(actual) { + 68 return new (this.getMatchersClass_())(this.env, actual, this); + 69 }; + 70 + 71 jasmine.Spec.prototype.waits = function(timeout) { + 72 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); + 73 this.addToQueue(waitsFunc); + 74 return this; + 75 }; + 76 + 77 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { + 78 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); + 79 this.addToQueue(waitsForFunc); + 80 return this; + 81 }; + 82 + 83 jasmine.Spec.prototype.fail = function (e) { + 84 var expectationResult = new jasmine.ExpectationResult({ + 85 passed: false, + 86 message: e ? jasmine.util.formatException(e) : 'Exception' + 87 }); + 88 this.results_.addResult(expectationResult); + 89 }; + 90 + 91 jasmine.Spec.prototype.getMatchersClass_ = function() { + 92 return this.matchersClass || this.env.matchersClass; + 93 }; + 94 + 95 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { + 96 var parent = this.getMatchersClass_(); + 97 var newMatchersClass = function() { + 98 parent.apply(this, arguments); + 99 }; +100 jasmine.util.inherit(newMatchersClass, parent); +101 for (var method in matchersPrototype) { +102 newMatchersClass.prototype[method] = matchersPrototype[method]; +103 } +104 this.matchersClass = newMatchersClass; +105 }; +106 +107 jasmine.Spec.prototype.finishCallback = function() { +108 this.env.reporter.reportSpecResults(this); +109 }; +110 +111 jasmine.Spec.prototype.finish = function(onComplete) { +112 this.removeAllSpies(); +113 this.finishCallback(); +114 if (onComplete) { +115 onComplete(); +116 } +117 }; +118 +119 jasmine.Spec.prototype.after = function(doAfter, test) { 120 -121 jasmine.Spec.prototype.after = function(doAfter, test) { -122 -123 if (this.queue.isRunning()) { -124 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -125 } else { -126 this.afterCallbacks.unshift(doAfter); -127 } -128 }; -129 -130 jasmine.Spec.prototype.execute = function(onComplete) { -131 var spec = this; -132 if (!spec.env.specFilter(spec)) { -133 spec.results_.skipped = true; -134 spec.finish(onComplete); -135 return; -136 } -137 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +121 if (this.queue.isRunning()) { +122 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +123 } else { +124 this.afterCallbacks.unshift(doAfter); +125 } +126 }; +127 +128 jasmine.Spec.prototype.execute = function(onComplete) { +129 var spec = this; +130 if (!spec.env.specFilter(spec)) { +131 spec.results_.skipped = true; +132 spec.finish(onComplete); +133 return; +134 } +135 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +136 +137 spec.env.currentSpec = spec; 138 -139 spec.env.currentSpec = spec; +139 spec.addBeforesAndAftersToQueue(); 140 -141 spec.addBeforesAndAftersToQueue(); -142 -143 spec.queue.start(function () { -144 spec.finish(onComplete); -145 }); -146 }; -147 -148 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -149 var runner = this.env.currentRunner(); -150 for (var suite = this.suite; suite; suite = suite.parentSuite) { -151 for (var i = 0; i < suite.before_.length; i++) { -152 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -153 } -154 } -155 for (var i = 0; i < runner.before_.length; i++) { -156 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -157 } -158 for (i = 0; i < this.afterCallbacks.length; i++) { -159 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -160 } -161 for (suite = this.suite; suite; suite = suite.parentSuite) { -162 for (var i = 0; i < suite.after_.length; i++) { -163 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -164 } -165 } -166 for (var i = 0; i < runner.after_.length; i++) { -167 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -168 } -169 }; -170 -171 jasmine.Spec.prototype.explodes = function() { -172 throw 'explodes function should not have been called'; -173 }; -174 -175 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -176 if (obj == undefined) { -177 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -178 } -179 -180 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -181 throw methodName + '() method does not exist'; -182 } -183 -184 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -185 throw new Error(methodName + ' has already been spied upon'); -186 } +141 spec.queue.start(function () { +142 spec.finish(onComplete); +143 }); +144 }; +145 +146 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +147 var runner = this.env.currentRunner(); +148 for (var suite = this.suite; suite; suite = suite.parentSuite) { +149 for (var i = 0; i < suite.before_.length; i++) { +150 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +151 } +152 } +153 for (var i = 0; i < runner.before_.length; i++) { +154 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +155 } +156 for (i = 0; i < this.afterCallbacks.length; i++) { +157 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +158 } +159 for (suite = this.suite; suite; suite = suite.parentSuite) { +160 for (var i = 0; i < suite.after_.length; i++) { +161 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +162 } +163 } +164 for (var i = 0; i < runner.after_.length; i++) { +165 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +166 } +167 }; +168 +169 jasmine.Spec.prototype.explodes = function() { +170 throw 'explodes function should not have been called'; +171 }; +172 +173 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +174 if (obj == jasmine.undefined) { +175 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +176 } +177 +178 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { +179 throw methodName + '() method does not exist'; +180 } +181 +182 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +183 throw new Error(methodName + ' has already been spied upon'); +184 } +185 +186 var spyObj = jasmine.createSpy(methodName); 187 -188 var spyObj = jasmine.createSpy(methodName); -189 -190 this.spies_.push(spyObj); -191 spyObj.baseObj = obj; -192 spyObj.methodName = methodName; -193 spyObj.originalValue = obj[methodName]; +188 this.spies_.push(spyObj); +189 spyObj.baseObj = obj; +190 spyObj.methodName = methodName; +191 spyObj.originalValue = obj[methodName]; +192 +193 obj[methodName] = spyObj; 194 -195 obj[methodName] = spyObj; -196 -197 return spyObj; -198 }; -199 -200 jasmine.Spec.prototype.removeAllSpies = function() { -201 for (var i = 0; i < this.spies_.length; i++) { -202 var spy = this.spies_[i]; -203 spy.baseObj[spy.methodName] = spy.originalValue; -204 } -205 this.spies_ = []; -206 }; -207 -208 \ No newline at end of file +195 return spyObj; +196 }; +197 +198 jasmine.Spec.prototype.removeAllSpies = function() { +199 for (var i = 0; i < this.spies_.length; i++) { +200 var spy = this.spies_[i]; +201 spy.baseObj[spy.methodName] = spy.originalValue; +202 } +203 this.spies_ = []; +204 }; +205 +206 \ No newline at end of file diff --git a/doc/symbols/src/src_base.js.html b/doc/symbols/src/src_base.js.html index 1b48e2c..388f185 100644 --- a/doc/symbols/src/src_base.js.html +++ b/doc/symbols/src/src_base.js.html @@ -20,520 +20,536 @@ 13 }; 14 15 /** - 16 * Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed. - 17 * - 18 */ - 19 jasmine.DEFAULT_UPDATE_INTERVAL = 250; - 20 - 21 /** - 22 * Allows for bound functions to be comapred. Internal use only. - 23 * - 24 * @ignore - 25 * @private - 26 * @param base {Object} bound 'this' for the function - 27 * @param name {Function} function to find - 28 */ - 29 jasmine.bindOriginal_ = function(base, name) { - 30 var original = base[name]; - 31 if (original.apply) { - 32 return function() { - 33 return original.apply(base, arguments); - 34 }; - 35 } else { - 36 // IE support - 37 return window[name]; - 38 } - 39 }; - 40 - 41 jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); - 42 jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); - 43 jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); - 44 jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); - 45 - 46 jasmine.MessageResult = function(text) { - 47 this.type = 'MessageResult'; - 48 this.text = text; - 49 this.trace = new Error(); // todo: test better - 50 }; - 51 - 52 jasmine.ExpectationResult = function(params) { - 53 this.type = 'ExpectationResult'; - 54 this.matcherName = params.matcherName; - 55 this.passed_ = params.passed; - 56 this.expected = params.expected; - 57 this.actual = params.actual; - 58 - 59 /** @deprecated */ - 60 this.details = params.details; - 61 - 62 this.message = this.passed_ ? 'Passed.' : params.message; - 63 this.trace = this.passed_ ? '' : new Error(this.message); - 64 }; - 65 - 66 jasmine.ExpectationResult.prototype.passed = function () { - 67 return this.passed_; - 68 }; - 69 - 70 /** - 71 * Getter for the Jasmine environment. Ensures one gets created - 72 */ - 73 jasmine.getEnv = function() { - 74 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); - 75 }; - 76 - 77 /** - 78 * @ignore - 79 * @private - 80 * @param value - 81 * @returns {Boolean} - 82 */ - 83 jasmine.isArray_ = function(value) { - 84 return value && - 85 typeof value === 'object' && - 86 typeof value.length === 'number' && - 87 typeof value.splice === 'function' && - 88 !(value.propertyIsEnumerable('length')); - 89 }; - 90 - 91 /** - 92 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. - 93 * - 94 * @param value {Object} an object to be outputted - 95 * @returns {String} - 96 */ - 97 jasmine.pp = function(value) { - 98 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); - 99 stringPrettyPrinter.format(value); -100 return stringPrettyPrinter.string; -101 }; -102 -103 /** -104 * Returns true if the object is a DOM Node. -105 * -106 * @param {Object} obj object to check -107 * @returns {Boolean} -108 */ -109 jasmine.isDomNode = function(obj) { -110 return obj['nodeType'] > 0; -111 }; -112 -113 /** -114 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. -115 * -116 * @example -117 * // don't care about which function is passed in, as long as it's a function -118 * expect(mySpy).wasCalledWith(jasmine.any(Function)); -119 * -120 * @param {Class} clazz -121 * @returns matchable object of the type clazz -122 */ -123 jasmine.any = function(clazz) { -124 return new jasmine.Matchers.Any(clazz); -125 }; -126 -127 /** -128 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. -129 * -130 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine -131 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. -132 * -133 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) -134 * Spies are torn down at the end of every spec. -135 * -136 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. + 16 * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code is just + 17 * a plain old variable and may be redefined by somebody else. + 18 * + 19 * @private + 20 */ + 21 jasmine.undefined = jasmine.___undefined___; + 22 + 23 /** + 24 * Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed. + 25 * + 26 */ + 27 jasmine.DEFAULT_UPDATE_INTERVAL = 250; + 28 + 29 /** + 30 * Allows for bound functions to be compared. Internal use only. + 31 * + 32 * @ignore + 33 * @private + 34 * @param base {Object} bound 'this' for the function + 35 * @param name {Function} function to find + 36 */ + 37 jasmine.bindOriginal_ = function(base, name) { + 38 var original = base[name]; + 39 if (original.apply) { + 40 return function() { + 41 return original.apply(base, arguments); + 42 }; + 43 } else { + 44 // IE support + 45 return window[name]; + 46 } + 47 }; + 48 + 49 jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); + 50 jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); + 51 jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); + 52 jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); + 53 + 54 jasmine.MessageResult = function(text) { + 55 this.type = 'MessageResult'; + 56 this.text = text; + 57 this.trace = new Error(); // todo: test better + 58 }; + 59 + 60 jasmine.ExpectationResult = function(params) { + 61 this.type = 'ExpectationResult'; + 62 this.matcherName = params.matcherName; + 63 this.passed_ = params.passed; + 64 this.expected = params.expected; + 65 this.actual = params.actual; + 66 + 67 /** @deprecated */ + 68 this.details = params.details; + 69 + 70 this.message = this.passed_ ? 'Passed.' : params.message; + 71 this.trace = this.passed_ ? '' : new Error(this.message); + 72 }; + 73 + 74 jasmine.ExpectationResult.prototype.passed = function () { + 75 return this.passed_; + 76 }; + 77 + 78 /** + 79 * Getter for the Jasmine environment. Ensures one gets created + 80 */ + 81 jasmine.getEnv = function() { + 82 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); + 83 }; + 84 + 85 /** + 86 * @ignore + 87 * @private + 88 * @param value + 89 * @returns {Boolean} + 90 */ + 91 jasmine.isArray_ = function(value) { + 92 return value && + 93 typeof value === 'object' && + 94 typeof value.length === 'number' && + 95 typeof value.splice === 'function' && + 96 !(value.propertyIsEnumerable('length')); + 97 }; + 98 + 99 /** +100 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. +101 * +102 * @param value {Object} an object to be outputted +103 * @returns {String} +104 */ +105 jasmine.pp = function(value) { +106 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); +107 stringPrettyPrinter.format(value); +108 return stringPrettyPrinter.string; +109 }; +110 +111 /** +112 * Returns true if the object is a DOM Node. +113 * +114 * @param {Object} obj object to check +115 * @returns {Boolean} +116 */ +117 jasmine.isDomNode = function(obj) { +118 return obj['nodeType'] > 0; +119 }; +120 +121 /** +122 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. +123 * +124 * @example +125 * // don't care about which function is passed in, as long as it's a function +126 * expect(mySpy).wasCalledWith(jasmine.any(Function)); +127 * +128 * @param {Class} clazz +129 * @returns matchable object of the type clazz +130 */ +131 jasmine.any = function(clazz) { +132 return new jasmine.Matchers.Any(clazz); +133 }; +134 +135 /** +136 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. 137 * -138 * @example -139 * // a stub -140 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere -141 * -142 * // spy example -143 * var foo = { -144 * not: function(bool) { return !bool; } -145 * } -146 * -147 * // actual foo.not will not be called, execution stops -148 * spyOn(foo, 'not'); -149 -150 // foo.not spied upon, execution will continue to implementation -151 * spyOn(foo, 'not').andCallThrough(); -152 * -153 * // fake example -154 * var foo = { -155 * not: function(bool) { return !bool; } -156 * } -157 * -158 * // foo.not(val) will return val -159 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); +138 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine +139 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. +140 * +141 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) +142 * Spies are torn down at the end of every spec. +143 * +144 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. +145 * +146 * @example +147 * // a stub +148 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere +149 * +150 * // spy example +151 * var foo = { +152 * not: function(bool) { return !bool; } +153 * } +154 * +155 * // actual foo.not will not be called, execution stops +156 * spyOn(foo, 'not'); +157 +158 // foo.not spied upon, execution will continue to implementation +159 * spyOn(foo, 'not').andCallThrough(); 160 * -161 * // mock example -162 * foo.not(7 == 7); -163 * expect(foo.not).wasCalled(); -164 * expect(foo.not).wasCalledWith(true); +161 * // fake example +162 * var foo = { +163 * not: function(bool) { return !bool; } +164 * } 165 * -166 * @constructor -167 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj -168 * @param {String} name -169 */ -170 jasmine.Spy = function(name) { -171 /** -172 * The name of the spy, if provided. -173 */ -174 this.identity = name || 'unknown'; -175 /** -176 * Is this Object a spy? -177 */ -178 this.isSpy = true; +166 * // foo.not(val) will return val +167 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); +168 * +169 * // mock example +170 * foo.not(7 == 7); +171 * expect(foo.not).wasCalled(); +172 * expect(foo.not).wasCalledWith(true); +173 * +174 * @constructor +175 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj +176 * @param {String} name +177 */ +178 jasmine.Spy = function(name) { 179 /** -180 * The actual function this spy stubs. +180 * The name of the spy, if provided. 181 */ -182 this.plan = function() { -183 }; -184 /** -185 * Tracking of the most recent call to the spy. -186 * @example -187 * var mySpy = jasmine.createSpy('foo'); -188 * mySpy(1, 2); -189 * mySpy.mostRecentCall.args = [1, 2]; -190 */ -191 this.mostRecentCall = {}; -192 -193 /** -194 * Holds arguments for each call to the spy, indexed by call count -195 * @example -196 * var mySpy = jasmine.createSpy('foo'); -197 * mySpy(1, 2); -198 * mySpy(7, 8); -199 * mySpy.mostRecentCall.args = [7, 8]; -200 * mySpy.argsForCall[0] = [1, 2]; -201 * mySpy.argsForCall[1] = [7, 8]; -202 */ -203 this.argsForCall = []; -204 this.calls = []; -205 }; -206 -207 /** -208 * Tells a spy to call through to the actual implemenatation. -209 * -210 * @example -211 * var foo = { -212 * bar: function() { // do some stuff } -213 * } -214 * -215 * // defining a spy on an existing property: foo.bar -216 * spyOn(foo, 'bar').andCallThrough(); -217 */ -218 jasmine.Spy.prototype.andCallThrough = function() { -219 this.plan = this.originalValue; -220 return this; -221 }; -222 -223 /** -224 * For setting the return value of a spy. -225 * -226 * @example -227 * // defining a spy from scratch: foo() returns 'baz' -228 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); -229 * -230 * // defining a spy on an existing property: foo.bar() returns 'baz' -231 * spyOn(foo, 'bar').andReturn('baz'); -232 * -233 * @param {Object} value -234 */ -235 jasmine.Spy.prototype.andReturn = function(value) { -236 this.plan = function() { -237 return value; -238 }; -239 return this; -240 }; -241 -242 /** -243 * For throwing an exception when a spy is called. -244 * -245 * @example -246 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' -247 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); -248 * -249 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' -250 * spyOn(foo, 'bar').andThrow('baz'); -251 * -252 * @param {String} exceptionMsg -253 */ -254 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { -255 this.plan = function() { -256 throw exceptionMsg; -257 }; -258 return this; -259 }; -260 -261 /** -262 * Calls an alternate implementation when a spy is called. -263 * -264 * @example -265 * var baz = function() { -266 * // do some stuff, return something -267 * } -268 * // defining a spy from scratch: foo() calls the function baz -269 * var foo = jasmine.createSpy('spy on foo').andCall(baz); -270 * -271 * // defining a spy on an existing property: foo.bar() calls an anonymnous function -272 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); -273 * -274 * @param {Function} fakeFunc -275 */ -276 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { -277 this.plan = fakeFunc; -278 return this; -279 }; -280 -281 /** -282 * Resets all of a spy's the tracking variables so that it can be used again. -283 * -284 * @example -285 * spyOn(foo, 'bar'); -286 * -287 * foo.bar(); -288 * -289 * expect(foo.bar.callCount).toEqual(1); -290 * -291 * foo.bar.reset(); -292 * -293 * expect(foo.bar.callCount).toEqual(0); -294 */ -295 jasmine.Spy.prototype.reset = function() { -296 this.wasCalled = false; -297 this.callCount = 0; -298 this.argsForCall = []; -299 this.calls = []; -300 this.mostRecentCall = {}; -301 }; -302 -303 jasmine.createSpy = function(name) { -304 -305 var spyObj = function() { -306 spyObj.wasCalled = true; -307 spyObj.callCount++; -308 var args = jasmine.util.argsToArray(arguments); -309 spyObj.mostRecentCall.object = this; -310 spyObj.mostRecentCall.args = args; -311 spyObj.argsForCall.push(args); -312 spyObj.calls.push({object: this, args: args}); -313 return spyObj.plan.apply(this, arguments); -314 }; -315 -316 var spy = new jasmine.Spy(name); -317 -318 for (var prop in spy) { -319 spyObj[prop] = spy[prop]; -320 } -321 -322 spyObj.reset(); +182 this.identity = name || 'unknown'; +183 /** +184 * Is this Object a spy? +185 */ +186 this.isSpy = true; +187 /** +188 * The actual function this spy stubs. +189 */ +190 this.plan = function() { +191 }; +192 /** +193 * Tracking of the most recent call to the spy. +194 * @example +195 * var mySpy = jasmine.createSpy('foo'); +196 * mySpy(1, 2); +197 * mySpy.mostRecentCall.args = [1, 2]; +198 */ +199 this.mostRecentCall = {}; +200 +201 /** +202 * Holds arguments for each call to the spy, indexed by call count +203 * @example +204 * var mySpy = jasmine.createSpy('foo'); +205 * mySpy(1, 2); +206 * mySpy(7, 8); +207 * mySpy.mostRecentCall.args = [7, 8]; +208 * mySpy.argsForCall[0] = [1, 2]; +209 * mySpy.argsForCall[1] = [7, 8]; +210 */ +211 this.argsForCall = []; +212 this.calls = []; +213 }; +214 +215 /** +216 * Tells a spy to call through to the actual implemenatation. +217 * +218 * @example +219 * var foo = { +220 * bar: function() { // do some stuff } +221 * } +222 * +223 * // defining a spy on an existing property: foo.bar +224 * spyOn(foo, 'bar').andCallThrough(); +225 */ +226 jasmine.Spy.prototype.andCallThrough = function() { +227 this.plan = this.originalValue; +228 return this; +229 }; +230 +231 /** +232 * For setting the return value of a spy. +233 * +234 * @example +235 * // defining a spy from scratch: foo() returns 'baz' +236 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); +237 * +238 * // defining a spy on an existing property: foo.bar() returns 'baz' +239 * spyOn(foo, 'bar').andReturn('baz'); +240 * +241 * @param {Object} value +242 */ +243 jasmine.Spy.prototype.andReturn = function(value) { +244 this.plan = function() { +245 return value; +246 }; +247 return this; +248 }; +249 +250 /** +251 * For throwing an exception when a spy is called. +252 * +253 * @example +254 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' +255 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); +256 * +257 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' +258 * spyOn(foo, 'bar').andThrow('baz'); +259 * +260 * @param {String} exceptionMsg +261 */ +262 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { +263 this.plan = function() { +264 throw exceptionMsg; +265 }; +266 return this; +267 }; +268 +269 /** +270 * Calls an alternate implementation when a spy is called. +271 * +272 * @example +273 * var baz = function() { +274 * // do some stuff, return something +275 * } +276 * // defining a spy from scratch: foo() calls the function baz +277 * var foo = jasmine.createSpy('spy on foo').andCall(baz); +278 * +279 * // defining a spy on an existing property: foo.bar() calls an anonymnous function +280 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); +281 * +282 * @param {Function} fakeFunc +283 */ +284 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { +285 this.plan = fakeFunc; +286 return this; +287 }; +288 +289 /** +290 * Resets all of a spy's the tracking variables so that it can be used again. +291 * +292 * @example +293 * spyOn(foo, 'bar'); +294 * +295 * foo.bar(); +296 * +297 * expect(foo.bar.callCount).toEqual(1); +298 * +299 * foo.bar.reset(); +300 * +301 * expect(foo.bar.callCount).toEqual(0); +302 */ +303 jasmine.Spy.prototype.reset = function() { +304 this.wasCalled = false; +305 this.callCount = 0; +306 this.argsForCall = []; +307 this.calls = []; +308 this.mostRecentCall = {}; +309 }; +310 +311 jasmine.createSpy = function(name) { +312 +313 var spyObj = function() { +314 spyObj.wasCalled = true; +315 spyObj.callCount++; +316 var args = jasmine.util.argsToArray(arguments); +317 spyObj.mostRecentCall.object = this; +318 spyObj.mostRecentCall.args = args; +319 spyObj.argsForCall.push(args); +320 spyObj.calls.push({object: this, args: args}); +321 return spyObj.plan.apply(this, arguments); +322 }; 323 -324 return spyObj; -325 }; -326 -327 /** -328 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something -329 * large in one call. -330 * -331 * @param {String} baseName name of spy class -332 * @param {Array} methodNames array of names of methods to make spies -333 */ -334 jasmine.createSpyObj = function(baseName, methodNames) { -335 var obj = {}; -336 for (var i = 0; i < methodNames.length; i++) { -337 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); -338 } -339 return obj; -340 }; -341 -342 jasmine.log = function(message) { -343 jasmine.getEnv().currentSpec.log(message); -344 }; -345 -346 /** -347 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. +324 var spy = new jasmine.Spy(name); +325 +326 for (var prop in spy) { +327 spyObj[prop] = spy[prop]; +328 } +329 +330 spyObj.reset(); +331 +332 return spyObj; +333 }; +334 +335 /** +336 * Determines whether an object is a spy. +337 * +338 * @param {jasmine.Spy|Object} putativeSpy +339 * @returns {Boolean} +340 */ +341 jasmine.isSpy = function(putativeSpy) { +342 return putativeSpy && putativeSpy.isSpy; +343 }; +344 +345 /** +346 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something +347 * large in one call. 348 * -349 * @example -350 * // spy example -351 * var foo = { -352 * not: function(bool) { return !bool; } -353 * } -354 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops -355 * -356 * @see jasmine.createSpy -357 * @param obj -358 * @param methodName -359 * @returns a Jasmine spy that can be chained with all spy methods -360 */ -361 var spyOn = function(obj, methodName) { -362 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -363 }; -364 -365 /** -366 * Creates a Jasmine spec that will be added to the current suite. -367 * -368 * // TODO: pending tests -369 * -370 * @example -371 * it('should be true', function() { -372 * expect(true).toEqual(true); -373 * }); -374 * -375 * @param {String} desc description of this specification -376 * @param {Function} func defines the preconditions and expectations of the spec -377 */ -378 var it = function(desc, func) { -379 return jasmine.getEnv().it(desc, func); -380 }; -381 -382 /** -383 * Creates a <em>disabled</em> Jasmine spec. -384 * -385 * A convenience method that allows existing specs to be disabled temporarily during development. -386 * -387 * @param {String} desc description of this specification -388 * @param {Function} func defines the preconditions and expectations of the spec -389 */ -390 var xit = function(desc, func) { -391 return jasmine.getEnv().xit(desc, func); -392 }; -393 -394 /** -395 * Starts a chain for a Jasmine expectation. -396 * -397 * It is passed an Object that is the actual value and should chain to one of the many -398 * jasmine.Matchers functions. -399 * -400 * @param {Object} actual Actual value to test against and expected value -401 */ -402 var expect = function(actual) { -403 return jasmine.getEnv().currentSpec.expect(actual); -404 }; -405 -406 /** -407 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. -408 * -409 * @param {Function} func Function that defines part of a jasmine spec. -410 */ -411 var runs = function(func) { -412 jasmine.getEnv().currentSpec.runs(func); -413 }; -414 -415 /** -416 * Waits for a timeout before moving to the next runs()-defined block. -417 * @param {Number} timeout -418 */ -419 var waits = function(timeout) { -420 jasmine.getEnv().currentSpec.waits(timeout); -421 }; -422 -423 /** -424 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. -425 * -426 * @param {Number} timeout -427 * @param {Function} latchFunction -428 * @param {String} message -429 */ -430 var waitsFor = function(timeout, latchFunction, message) { -431 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); -432 }; -433 -434 /** -435 * A function that is called before each spec in a suite. -436 * -437 * Used for spec setup, including validating assumptions. -438 * -439 * @param {Function} beforeEachFunction -440 */ -441 var beforeEach = function(beforeEachFunction) { -442 jasmine.getEnv().beforeEach(beforeEachFunction); -443 }; -444 -445 /** -446 * A function that is called after each spec in a suite. -447 * -448 * Used for restoring any state that is hijacked during spec execution. -449 * -450 * @param {Function} afterEachFunction -451 */ -452 var afterEach = function(afterEachFunction) { -453 jasmine.getEnv().afterEach(afterEachFunction); -454 }; -455 -456 /** -457 * Defines a suite of specifications. -458 * -459 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared -460 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization -461 * of setup in some tests. -462 * -463 * @example -464 * // TODO: a simple suite +349 * @param {String} baseName name of spy class +350 * @param {Array} methodNames array of names of methods to make spies +351 */ +352 jasmine.createSpyObj = function(baseName, methodNames) { +353 var obj = {}; +354 for (var i = 0; i < methodNames.length; i++) { +355 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); +356 } +357 return obj; +358 }; +359 +360 jasmine.log = function(message) { +361 jasmine.getEnv().currentSpec.log(message); +362 }; +363 +364 /** +365 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. +366 * +367 * @example +368 * // spy example +369 * var foo = { +370 * not: function(bool) { return !bool; } +371 * } +372 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops +373 * +374 * @see jasmine.createSpy +375 * @param obj +376 * @param methodName +377 * @returns a Jasmine spy that can be chained with all spy methods +378 */ +379 var spyOn = function(obj, methodName) { +380 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +381 }; +382 +383 /** +384 * Creates a Jasmine spec that will be added to the current suite. +385 * +386 * // TODO: pending tests +387 * +388 * @example +389 * it('should be true', function() { +390 * expect(true).toEqual(true); +391 * }); +392 * +393 * @param {String} desc description of this specification +394 * @param {Function} func defines the preconditions and expectations of the spec +395 */ +396 var it = function(desc, func) { +397 return jasmine.getEnv().it(desc, func); +398 }; +399 +400 /** +401 * Creates a <em>disabled</em> Jasmine spec. +402 * +403 * A convenience method that allows existing specs to be disabled temporarily during development. +404 * +405 * @param {String} desc description of this specification +406 * @param {Function} func defines the preconditions and expectations of the spec +407 */ +408 var xit = function(desc, func) { +409 return jasmine.getEnv().xit(desc, func); +410 }; +411 +412 /** +413 * Starts a chain for a Jasmine expectation. +414 * +415 * It is passed an Object that is the actual value and should chain to one of the many +416 * jasmine.Matchers functions. +417 * +418 * @param {Object} actual Actual value to test against and expected value +419 */ +420 var expect = function(actual) { +421 return jasmine.getEnv().currentSpec.expect(actual); +422 }; +423 +424 /** +425 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. +426 * +427 * @param {Function} func Function that defines part of a jasmine spec. +428 */ +429 var runs = function(func) { +430 jasmine.getEnv().currentSpec.runs(func); +431 }; +432 +433 /** +434 * Waits for a timeout before moving to the next runs()-defined block. +435 * @param {Number} timeout +436 */ +437 var waits = function(timeout) { +438 jasmine.getEnv().currentSpec.waits(timeout); +439 }; +440 +441 /** +442 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. +443 * +444 * @param {Number} timeout +445 * @param {Function} latchFunction +446 * @param {String} message +447 */ +448 var waitsFor = function(timeout, latchFunction, message) { +449 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +450 }; +451 +452 /** +453 * A function that is called before each spec in a suite. +454 * +455 * Used for spec setup, including validating assumptions. +456 * +457 * @param {Function} beforeEachFunction +458 */ +459 var beforeEach = function(beforeEachFunction) { +460 jasmine.getEnv().beforeEach(beforeEachFunction); +461 }; +462 +463 /** +464 * A function that is called after each spec in a suite. 465 * -466 * // TODO: a simple suite with a nested describe block +466 * Used for restoring any state that is hijacked during spec execution. 467 * -468 * @param {String} description A string, usually the class under test. -469 * @param {Function} specDefinitions function that defines several specs. -470 */ -471 var describe = function(description, specDefinitions) { -472 return jasmine.getEnv().describe(description, specDefinitions); -473 }; -474 -475 /** -476 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. -477 * -478 * @param {String} description A string, usually the class under test. -479 * @param {Function} specDefinitions function that defines several specs. -480 */ -481 var xdescribe = function(description, specDefinitions) { -482 return jasmine.getEnv().xdescribe(description, specDefinitions); -483 }; -484 -485 -486 jasmine.XmlHttpRequest = XMLHttpRequest; -487 -488 // Provide the XMLHttpRequest class for IE 5.x-6.x: -489 if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { -490 try { -491 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); -492 } catch(e) { -493 } -494 try { -495 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); -496 } catch(e) { -497 } -498 try { -499 return new ActiveXObject("Msxml2.XMLHTTP"); -500 } catch(e) { -501 } -502 try { -503 return new ActiveXObject("Microsoft.XMLHTTP"); -504 } catch(e) { -505 } -506 throw new Error("This browser does not support XMLHttpRequest."); -507 }; -508 -509 /** -510 * Adds suite files to an HTML document so that they are executed, thus adding them to the current -511 * Jasmine environment. -512 * -513 * @param {String} url path to the file to include -514 * @param {Boolean} opt_global -515 */ -516 jasmine.include = function(url, opt_global) { -517 if (opt_global) { -518 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); -519 } else { -520 var xhr; -521 try { -522 xhr = new jasmine.XmlHttpRequest(); -523 xhr.open("GET", url, false); -524 xhr.send(null); -525 } catch(e) { -526 throw new Error("couldn't fetch " + url + ": " + e); -527 } -528 -529 return eval(xhr.responseText); -530 } -531 }; -532 \ No newline at end of file +468 * @param {Function} afterEachFunction +469 */ +470 var afterEach = function(afterEachFunction) { +471 jasmine.getEnv().afterEach(afterEachFunction); +472 }; +473 +474 /** +475 * Defines a suite of specifications. +476 * +477 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared +478 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization +479 * of setup in some tests. +480 * +481 * @example +482 * // TODO: a simple suite +483 * +484 * // TODO: a simple suite with a nested describe block +485 * +486 * @param {String} description A string, usually the class under test. +487 * @param {Function} specDefinitions function that defines several specs. +488 */ +489 var describe = function(description, specDefinitions) { +490 return jasmine.getEnv().describe(description, specDefinitions); +491 }; +492 +493 /** +494 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. +495 * +496 * @param {String} description A string, usually the class under test. +497 * @param {Function} specDefinitions function that defines several specs. +498 */ +499 var xdescribe = function(description, specDefinitions) { +500 return jasmine.getEnv().xdescribe(description, specDefinitions); +501 }; +502 +503 +504 // Provide the XMLHttpRequest class for IE 5.x-6.x: +505 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { +506 try { +507 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); +508 } catch(e) { +509 } +510 try { +511 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); +512 } catch(e) { +513 } +514 try { +515 return new ActiveXObject("Msxml2.XMLHTTP"); +516 } catch(e) { +517 } +518 try { +519 return new ActiveXObject("Microsoft.XMLHTTP"); +520 } catch(e) { +521 } +522 throw new Error("This browser does not support XMLHttpRequest."); +523 } : XMLHttpRequest; +524 +525 /** +526 * Adds suite files to an HTML document so that they are executed, thus adding them to the current +527 * Jasmine environment. +528 * +529 * @param {String} url path to the file to include +530 * @param {Boolean} opt_global +531 */ +532 jasmine.include = function(url, opt_global) { +533 if (opt_global) { +534 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); +535 } else { +536 var xhr; +537 try { +538 xhr = new jasmine.XmlHttpRequest(); +539 xhr.open("GET", url, false); +540 xhr.send(null); +541 } catch(e) { +542 throw new Error("couldn't fetch " + url + ": " + e); +543 } +544 +545 return eval(xhr.responseText); +546 } +547 }; +548 \ No newline at end of file diff --git a/doc/symbols/src/src_mock-timeout.js.html b/doc/symbols/src/src_mock-timeout.js.html index 48e5382..664a3c3 100644 --- a/doc/symbols/src/src_mock-timeout.js.html +++ b/doc/symbols/src/src_mock-timeout.js.html @@ -25,11 +25,11 @@ 18 }; 19 20 self.clearTimeout = function(timeoutKey) { - 21 self.scheduledFunctions[timeoutKey] = undefined; + 21 self.scheduledFunctions[timeoutKey] = jasmine.undefined; 22 }; 23 24 self.clearInterval = function(timeoutKey) { - 25 self.scheduledFunctions[timeoutKey] = undefined; + 25 self.scheduledFunctions[timeoutKey] = jasmine.undefined; 26 }; 27 28 }; @@ -52,11 +52,11 @@ 45 var funcsToRun = []; 46 for (var timeoutKey in this.scheduledFunctions) { 47 scheduledFunc = this.scheduledFunctions[timeoutKey]; - 48 if (scheduledFunc != undefined && + 48 if (scheduledFunc != jasmine.undefined && 49 scheduledFunc.runAtMillis >= oldMillis && 50 scheduledFunc.runAtMillis <= nowMillis) { 51 funcsToRun.push(scheduledFunc); - 52 this.scheduledFunctions[timeoutKey] = undefined; + 52 this.scheduledFunctions[timeoutKey] = jasmine.undefined; 53 } 54 } 55 diff --git a/examples/ruby/spec/jasmine_spec.rb b/examples/ruby/spec/jasmine_spec.rb index 1b37d8b..de4f09f 100644 --- a/examples/ruby/spec/jasmine_spec.rb +++ b/examples/ruby/spec/jasmine_spec.rb @@ -11,7 +11,7 @@ jasmine_runner = if ENV['SAUCELABS'] == 'true' :saucelabs_config_file => File.expand_path(File.join(File.dirname(__FILE__), "saucelabs.yml"))) else require "selenium_rc" - Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, + Jasmine::Runner.new(SeleniumRC::Server.new('localhost').jar_path, JasmineHelper.specs, JasmineHelper.dir_mappings) end diff --git a/geminstaller.yml b/geminstaller.yml index a89fb78..56267f2 100644 --- a/geminstaller.yml +++ b/geminstaller.yml @@ -6,8 +6,8 @@ gems: version: 0.0.2.1 - name: json version: 1.1.9 -- name: pivotal-selenium-rc - version: 1.11.20090610 +- name: selenium-rc + version: 2.1.0 - name: rack version: 1.0.0 - name: thin diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index bfb4494..850daae 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -2255,5 +2255,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1261582590 + "revision": 1261632445 }; diff --git a/spec/jasmine_spec.rb b/spec/jasmine_spec.rb index 1b37d8b..de4f09f 100644 --- a/spec/jasmine_spec.rb +++ b/spec/jasmine_spec.rb @@ -11,7 +11,7 @@ jasmine_runner = if ENV['SAUCELABS'] == 'true' :saucelabs_config_file => File.expand_path(File.join(File.dirname(__FILE__), "saucelabs.yml"))) else require "selenium_rc" - Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, + Jasmine::Runner.new(SeleniumRC::Server.new('localhost').jar_path, JasmineHelper.specs, JasmineHelper.dir_mappings) end From e986b024bc5a7a1e67f02e57dee59fb26ed0b282 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Fri, 25 Dec 2009 14:19:27 -0500 Subject: [PATCH 06/29] Update generated files. --- doc/files.html | 2 +- doc/index.html | 2 +- doc/symbols/_global_.html | 2 +- doc/symbols/jasmine.Block.html | 2 +- doc/symbols/jasmine.Clock.html | 2 +- doc/symbols/jasmine.Env.html | 2 +- doc/symbols/jasmine.JsApiReporter.html | 2 +- doc/symbols/jasmine.Matchers.html | 98 ++-- doc/symbols/jasmine.MultiReporter.html | 2 +- doc/symbols/jasmine.NestedResults.html | 2 +- doc/symbols/jasmine.Reporter.html | 2 +- doc/symbols/jasmine.Runner.html | 2 +- doc/symbols/jasmine.Spec.html | 2 +- doc/symbols/jasmine.Spy.html | 2 +- doc/symbols/jasmine.Suite.html | 2 +- doc/symbols/jasmine.html | 2 +- doc/symbols/jasmine.util.html | 2 +- doc/symbols/src/src_Env.js.html | 405 +++++++++-------- doc/symbols/src/src_Matchers.js.html | 599 +++++++++++++------------ doc/symbols/src/src_Spec.js.html | 200 ++++----- lib/jasmine-0.10.0.js | 66 +-- 21 files changed, 722 insertions(+), 678 deletions(-) diff --git a/doc/files.html b/doc/files.html index dfdecfe..50ff90b 100644 --- a/doc/files.html +++ b/doc/files.html @@ -454,7 +454,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index fa86084..1aa2b28 100644 --- a/doc/index.html +++ b/doc/index.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 57f29d3..6e50334 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -912,7 +912,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index a04e2c9..73c5e7d 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -411,7 +411,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Clock.html b/doc/symbols/jasmine.Clock.html index fd7c165..627ae47 100644 --- a/doc/symbols/jasmine.Clock.html +++ b/doc/symbols/jasmine.Clock.html @@ -672,7 +672,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 40efbdd..35625fc 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -1163,7 +1163,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index ca02c07..61255dd 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -816,7 +816,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index 4ec8408..bc20fdc 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -304,7 +304,7 @@ ul.inheritsList   -
message(expected) +
@@ -403,7 +403,7 @@ ul.inheritsList   -
toContain(item) +
toContain(expected)
Matcher that checks that the expected item is an element in the actual Array.
@@ -421,7 +421,7 @@ ul.inheritsList   -
toMatch(reg_exp) +
toMatch(expected)
Matcher that compares the actual to the expected using a regular expression.
@@ -439,7 +439,7 @@ ul.inheritsList   -
toNotContain(item) +
toNotContain(expected)
Matcher that checks that the expected item is NOT an element in the actual Array.
@@ -457,7 +457,7 @@ ul.inheritsList   -
toNotMatch(reg_exp) +
toNotMatch(expected)
Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
@@ -466,7 +466,7 @@ ul.inheritsList   -
toThrow(expectedException) +
toThrow(expected)
Matcher that checks that the expected exception was thrown by the actual.
@@ -508,6 +508,15 @@ ul.inheritsList + + <static>   + +
jasmine.Matchers.wrapInto_(prototype, matchersClass) +
+
+ + + @@ -661,7 +670,7 @@ ul.inheritsList
- message(expected) + message()
@@ -673,17 +682,6 @@ ul.inheritsList -
-
Parameters:
- -
- expected - -
-
- -
- @@ -1014,7 +1012,7 @@ ul.inheritsList
- toContain(item) + toContain(expected)
@@ -1030,7 +1028,7 @@ ul.inheritsList
Parameters:
- {Object} item + {Object} expected
@@ -1086,7 +1084,7 @@ ul.inheritsList
- toMatch(reg_exp) + toMatch(expected)
@@ -1103,7 +1101,7 @@ a pattern or a String.
Parameters:
- reg_exp + expected
@@ -1159,7 +1157,7 @@ a pattern or a String.
- toNotContain(item) + toNotContain(expected)
@@ -1175,7 +1173,7 @@ a pattern or a String.
Parameters:
- {Object} item + {Object} expected
@@ -1231,7 +1229,7 @@ a pattern or a String.
- toNotMatch(reg_exp) + toNotMatch(expected)
@@ -1247,7 +1245,7 @@ a pattern or a String.
Parameters:
- reg_exp + expected
@@ -1267,7 +1265,7 @@ a pattern or a String.
- toThrow(expectedException) + toThrow(expected)
@@ -1283,7 +1281,7 @@ a pattern or a String.
Parameters:
- {String} expectedException + {String} expected
@@ -1401,6 +1399,48 @@ a pattern or a String. +
+ + +
<static> + + + jasmine.Matchers.wrapInto_(prototype, matchersClass) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ prototype + +
+
+ +
+ matchersClass + +
+
+ +
+ + + + + + + + @@ -1415,7 +1455,7 @@ a pattern or a String.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 8583a03..36fc55b 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -388,7 +388,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 395225e..cff8abc 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 3646e49..3420f20 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -568,7 +568,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index c3ac98a..ba336dc 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 3c6473c..f411d58 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -1253,7 +1253,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index 0cb83ac..37667bc 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -849,7 +849,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index d5f40c6..11d664c 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -699,7 +699,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 835bd0f..6464a3f 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -1339,7 +1339,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index bb10c02..445374f 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -529,7 +529,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Dec 23 2009 21:27:32 GMT-0800 (PST) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST)
diff --git a/doc/symbols/src/src_Env.js.html b/doc/symbols/src/src_Env.js.html index 7b46e68..9c858a7 100644 --- a/doc/symbols/src/src_Env.js.html +++ b/doc/symbols/src/src_Env.js.html @@ -33,211 +33,208 @@ 26 }; 27 jasmine.util.inherit(this.matchersClass, jasmine.Matchers); 28 - 29 for (var methodName in jasmine.Matchers.prototype) { - 30 var orig = jasmine.Matchers.prototype[methodName]; - 31 this.matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); - 32 } - 33 }; - 34 - 35 - 36 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; - 37 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; - 38 jasmine.Env.prototype.setInterval = jasmine.setInterval; - 39 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; - 40 - 41 /** - 42 * @returns an object containing jasmine version build info, if set. - 43 */ - 44 jasmine.Env.prototype.version = function () { - 45 if (jasmine.version_) { - 46 return jasmine.version_; - 47 } else { - 48 throw new Error('Version not set'); - 49 } - 50 }; - 51 - 52 /** - 53 * @returns a sequential integer starting at 0 - 54 */ - 55 jasmine.Env.prototype.nextSpecId = function () { - 56 return this.nextSpecId_++; - 57 }; - 58 - 59 /** - 60 * @returns a sequential integer starting at 0 - 61 */ - 62 jasmine.Env.prototype.nextSuiteId = function () { - 63 return this.nextSuiteId_++; - 64 }; - 65 - 66 /** - 67 * Register a reporter to receive status updates from Jasmine. - 68 * @param {jasmine.Reporter} reporter An object which will receive status updates. - 69 */ - 70 jasmine.Env.prototype.addReporter = function(reporter) { - 71 this.reporter.addReporter(reporter); - 72 }; - 73 - 74 jasmine.Env.prototype.execute = function() { - 75 this.currentRunner_.execute(); - 76 }; + 29 jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); + 30 }; + 31 + 32 + 33 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; + 34 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; + 35 jasmine.Env.prototype.setInterval = jasmine.setInterval; + 36 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; + 37 + 38 /** + 39 * @returns an object containing jasmine version build info, if set. + 40 */ + 41 jasmine.Env.prototype.version = function () { + 42 if (jasmine.version_) { + 43 return jasmine.version_; + 44 } else { + 45 throw new Error('Version not set'); + 46 } + 47 }; + 48 + 49 /** + 50 * @returns a sequential integer starting at 0 + 51 */ + 52 jasmine.Env.prototype.nextSpecId = function () { + 53 return this.nextSpecId_++; + 54 }; + 55 + 56 /** + 57 * @returns a sequential integer starting at 0 + 58 */ + 59 jasmine.Env.prototype.nextSuiteId = function () { + 60 return this.nextSuiteId_++; + 61 }; + 62 + 63 /** + 64 * Register a reporter to receive status updates from Jasmine. + 65 * @param {jasmine.Reporter} reporter An object which will receive status updates. + 66 */ + 67 jasmine.Env.prototype.addReporter = function(reporter) { + 68 this.reporter.addReporter(reporter); + 69 }; + 70 + 71 jasmine.Env.prototype.execute = function() { + 72 this.currentRunner_.execute(); + 73 }; + 74 + 75 jasmine.Env.prototype.describe = function(description, specDefinitions) { + 76 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); 77 - 78 jasmine.Env.prototype.describe = function(description, specDefinitions) { - 79 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); - 80 - 81 var parentSuite = this.currentSuite; - 82 if (parentSuite) { - 83 parentSuite.add(suite); - 84 } else { - 85 this.currentRunner_.add(suite); - 86 } - 87 - 88 this.currentSuite = suite; - 89 - 90 specDefinitions.call(suite); - 91 - 92 this.currentSuite = parentSuite; + 78 var parentSuite = this.currentSuite; + 79 if (parentSuite) { + 80 parentSuite.add(suite); + 81 } else { + 82 this.currentRunner_.add(suite); + 83 } + 84 + 85 this.currentSuite = suite; + 86 + 87 specDefinitions.call(suite); + 88 + 89 this.currentSuite = parentSuite; + 90 + 91 return suite; + 92 }; 93 - 94 return suite; - 95 }; - 96 - 97 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { - 98 if (this.currentSuite) { - 99 this.currentSuite.beforeEach(beforeEachFunction); -100 } else { -101 this.currentRunner_.beforeEach(beforeEachFunction); -102 } -103 }; -104 -105 jasmine.Env.prototype.currentRunner = function () { -106 return this.currentRunner_; -107 }; -108 -109 jasmine.Env.prototype.afterEach = function(afterEachFunction) { -110 if (this.currentSuite) { -111 this.currentSuite.afterEach(afterEachFunction); -112 } else { -113 this.currentRunner_.afterEach(afterEachFunction); -114 } -115 -116 }; -117 -118 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { -119 return { -120 execute: function() { -121 } -122 }; -123 }; -124 -125 jasmine.Env.prototype.it = function(description, func) { -126 var spec = new jasmine.Spec(this, this.currentSuite, description); -127 this.currentSuite.add(spec); -128 this.currentSpec = spec; -129 -130 if (func) { -131 spec.runs(func); -132 } + 94 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { + 95 if (this.currentSuite) { + 96 this.currentSuite.beforeEach(beforeEachFunction); + 97 } else { + 98 this.currentRunner_.beforeEach(beforeEachFunction); + 99 } +100 }; +101 +102 jasmine.Env.prototype.currentRunner = function () { +103 return this.currentRunner_; +104 }; +105 +106 jasmine.Env.prototype.afterEach = function(afterEachFunction) { +107 if (this.currentSuite) { +108 this.currentSuite.afterEach(afterEachFunction); +109 } else { +110 this.currentRunner_.afterEach(afterEachFunction); +111 } +112 +113 }; +114 +115 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +116 return { +117 execute: function() { +118 } +119 }; +120 }; +121 +122 jasmine.Env.prototype.it = function(description, func) { +123 var spec = new jasmine.Spec(this, this.currentSuite, description); +124 this.currentSuite.add(spec); +125 this.currentSpec = spec; +126 +127 if (func) { +128 spec.runs(func); +129 } +130 +131 return spec; +132 }; 133 -134 return spec; -135 }; -136 -137 jasmine.Env.prototype.xit = function(desc, func) { -138 return { -139 id: this.nextSpecId(), -140 runs: function() { -141 } -142 }; -143 }; -144 -145 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { -146 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { -147 return true; -148 } +134 jasmine.Env.prototype.xit = function(desc, func) { +135 return { +136 id: this.nextSpecId(), +137 runs: function() { +138 } +139 }; +140 }; +141 +142 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { +143 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { +144 return true; +145 } +146 +147 a.__Jasmine_been_here_before__ = b; +148 b.__Jasmine_been_here_before__ = a; 149 -150 a.__Jasmine_been_here_before__ = b; -151 b.__Jasmine_been_here_before__ = a; -152 -153 var hasKey = function(obj, keyName) { -154 return obj != null && obj[keyName] !== jasmine.undefined; -155 }; -156 -157 for (var property in b) { -158 if (!hasKey(a, property) && hasKey(b, property)) { -159 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); -160 } -161 } -162 for (property in a) { -163 if (!hasKey(b, property) && hasKey(a, property)) { -164 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); -165 } -166 } -167 for (property in b) { -168 if (property == '__Jasmine_been_here_before__') continue; -169 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { -170 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); -171 } -172 } -173 -174 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { -175 mismatchValues.push("arrays were not the same length"); -176 } -177 -178 delete a.__Jasmine_been_here_before__; -179 delete b.__Jasmine_been_here_before__; -180 return (mismatchKeys.length == 0 && mismatchValues.length == 0); -181 }; -182 -183 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { -184 mismatchKeys = mismatchKeys || []; -185 mismatchValues = mismatchValues || []; -186 -187 if (a === b) return true; -188 -189 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { -190 return (a == jasmine.undefined && b == jasmine.undefined); -191 } -192 -193 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -194 return a === b; -195 } -196 -197 if (a instanceof Date && b instanceof Date) { -198 return a.getTime() == b.getTime(); -199 } -200 -201 if (a instanceof jasmine.Matchers.Any) { -202 return a.matches(b); -203 } -204 -205 if (b instanceof jasmine.Matchers.Any) { -206 return b.matches(a); -207 } -208 -209 if (typeof a === "object" && typeof b === "object") { -210 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -211 } -212 -213 for (var i = 0; i < this.equalityTesters_.length; i++) { -214 var equalityTester = this.equalityTesters_[i]; -215 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -216 if (result !== jasmine.undefined) return result; -217 } -218 -219 //Straight check -220 return (a === b); -221 }; -222 -223 jasmine.Env.prototype.contains_ = function(haystack, needle) { -224 if (jasmine.isArray_(haystack)) { -225 for (var i = 0; i < haystack.length; i++) { -226 if (this.equals_(haystack[i], needle)) return true; -227 } -228 return false; -229 } -230 return haystack.indexOf(needle) >= 0; -231 }; -232 -233 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -234 this.equalityTesters_.push(equalityTester); -235 }; -236 \ No newline at end of file +150 var hasKey = function(obj, keyName) { +151 return obj != null && obj[keyName] !== jasmine.undefined; +152 }; +153 +154 for (var property in b) { +155 if (!hasKey(a, property) && hasKey(b, property)) { +156 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); +157 } +158 } +159 for (property in a) { +160 if (!hasKey(b, property) && hasKey(a, property)) { +161 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); +162 } +163 } +164 for (property in b) { +165 if (property == '__Jasmine_been_here_before__') continue; +166 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { +167 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); +168 } +169 } +170 +171 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { +172 mismatchValues.push("arrays were not the same length"); +173 } +174 +175 delete a.__Jasmine_been_here_before__; +176 delete b.__Jasmine_been_here_before__; +177 return (mismatchKeys.length == 0 && mismatchValues.length == 0); +178 }; +179 +180 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +181 mismatchKeys = mismatchKeys || []; +182 mismatchValues = mismatchValues || []; +183 +184 if (a === b) return true; +185 +186 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { +187 return (a == jasmine.undefined && b == jasmine.undefined); +188 } +189 +190 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +191 return a === b; +192 } +193 +194 if (a instanceof Date && b instanceof Date) { +195 return a.getTime() == b.getTime(); +196 } +197 +198 if (a instanceof jasmine.Matchers.Any) { +199 return a.matches(b); +200 } +201 +202 if (b instanceof jasmine.Matchers.Any) { +203 return b.matches(a); +204 } +205 +206 if (typeof a === "object" && typeof b === "object") { +207 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +208 } +209 +210 for (var i = 0; i < this.equalityTesters_.length; i++) { +211 var equalityTester = this.equalityTesters_[i]; +212 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); +213 if (result !== jasmine.undefined) return result; +214 } +215 +216 //Straight check +217 return (a === b); +218 }; +219 +220 jasmine.Env.prototype.contains_ = function(haystack, needle) { +221 if (jasmine.isArray_(haystack)) { +222 for (var i = 0; i < haystack.length; i++) { +223 if (this.equals_(haystack[i], needle)) return true; +224 } +225 return false; +226 } +227 return haystack.indexOf(needle) >= 0; +228 }; +229 +230 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +231 this.equalityTesters_.push(equalityTester); +232 }; +233 \ No newline at end of file diff --git a/doc/symbols/src/src_Matchers.js.html b/doc/symbols/src/src_Matchers.js.html index 0000319..20f9391 100644 --- a/doc/symbols/src/src_Matchers.js.html +++ b/doc/symbols/src/src_Matchers.js.html @@ -15,307 +15,314 @@ 8 this.env = env; 9 this.actual = actual; 10 this.spec = spec; - 11 }; - 12 - 13 jasmine.Matchers.pp = function(str) { - 14 return jasmine.util.htmlEscape(jasmine.pp(str)); - 15 }; - 16 - 17 jasmine.Matchers.prototype.report = function(result, failing_message, details) { - 18 var expectationResult = new jasmine.ExpectationResult({ - 19 passed: result, - 20 message: failing_message, - 21 details: details - 22 }); - 23 this.spec.addMatcherResult(expectationResult); - 24 return result; - 25 }; - 26 - 27 jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { - 28 return function() { - 29 var matcherArgs = jasmine.util.argsToArray(arguments); - 30 var result = matcherFunction.apply(this, arguments); - 31 var message; - 32 if (!result) { - 33 if (this.message) { - 34 message = this.message.apply(this, arguments); - 35 } else { - 36 var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); - 37 message = "Expected " + jasmine.pp(this.actual) + " " + englishyPredicate; - 38 if (matcherArgs.length > 0) { - 39 for (var i = 0; i < matcherArgs.length; i++) { - 40 if (i > 0) message += ","; - 41 message += " " + jasmine.pp(matcherArgs[i]); - 42 } - 43 } - 44 message += "."; - 45 } - 46 } - 47 var expectationResult = new jasmine.ExpectationResult({ - 48 matcherName: matcherName, - 49 passed: result, - 50 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], - 51 actual: this.actual, - 52 message: message - 53 }); - 54 this.spec.addMatcherResult(expectationResult); - 55 return result; - 56 }; - 57 }; - 58 - 59 - 60 - 61 - 62 /** - 63 * toBe: compares the actual to the expected using === - 64 * @param expected - 65 */ - 66 - 67 jasmine.Matchers.prototype.toBe = function(expected) { - 68 return this.actual === expected; - 69 }; - 70 - 71 /** - 72 * toNotBe: compares the actual to the expected using !== - 73 * @param expected - 74 */ - 75 jasmine.Matchers.prototype.toNotBe = function(expected) { - 76 return this.actual !== expected; - 77 }; - 78 - 79 /** - 80 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. - 81 * - 82 * @param expected - 83 */ + 11 this.reportWasCalled_ = false; + 12 }; + 13 + 14 jasmine.Matchers.pp = function(str) { + 15 return jasmine.util.htmlEscape(jasmine.pp(str)); + 16 }; + 17 + 18 /** @deprecated */ + 19 jasmine.Matchers.prototype.report = function(result, failing_message, details) { + 20 // todo first: report deprecation warning [xw] + 21 // todo later: throw new Error("As of jasmine 0.xx, custom matchers must be implemented differently -- please see jasmine docs"); + 22 this.reportWasCalled_ = true; + 23 var expectationResult = new jasmine.ExpectationResult({ + 24 passed: result, + 25 message: failing_message, + 26 details: details + 27 }); + 28 this.spec.addMatcherResult(expectationResult); + 29 return result; + 30 }; + 31 + 32 jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { + 33 for (var methodName in prototype) { + 34 if (methodName == 'report') continue; + 35 var orig = prototype[methodName]; + 36 matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); + 37 } + 38 }; + 39 + 40 jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { + 41 return function() { + 42 var matcherArgs = jasmine.util.argsToArray(arguments); + 43 var result = matcherFunction.apply(this, arguments); + 44 if (this.reportWasCalled_) return result; + 45 + 46 var message; + 47 if (!result) { + 48 if (this.message) { + 49 message = this.message.apply(this, arguments); + 50 } else { + 51 var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); + 52 message = "Expected " + jasmine.pp(this.actual) + " " + englishyPredicate; + 53 if (matcherArgs.length > 0) { + 54 for (var i = 0; i < matcherArgs.length; i++) { + 55 if (i > 0) message += ","; + 56 message += " " + jasmine.pp(matcherArgs[i]); + 57 } + 58 } + 59 message += "."; + 60 } + 61 } + 62 var expectationResult = new jasmine.ExpectationResult({ + 63 matcherName: matcherName, + 64 passed: result, + 65 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], + 66 actual: this.actual, + 67 message: message + 68 }); + 69 this.spec.addMatcherResult(expectationResult); + 70 return result; + 71 }; + 72 }; + 73 + 74 + 75 + 76 + 77 /** + 78 * toBe: compares the actual to the expected using === + 79 * @param expected + 80 */ + 81 jasmine.Matchers.prototype.toBe = function(expected) { + 82 return this.actual === expected; + 83 }; 84 - 85 jasmine.Matchers.prototype.toEqual = function(expected) { - 86 return this.env.equals_(this.actual, expected); - 87 }; - 88 - 89 /** - 90 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual - 91 * @param expected - 92 */ - 93 jasmine.Matchers.prototype.toNotEqual = function(expected) { - 94 return !this.env.equals_(this.actual, expected); - 95 }; - 96 - 97 /** - 98 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes - 99 * a pattern or a String. -100 * -101 * @param reg_exp -102 */ -103 jasmine.Matchers.prototype.toMatch = function(expected) { -104 return new RegExp(expected).test(this.actual); -105 }; -106 -107 /** -108 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -109 * @param reg_exp -110 */ -111 jasmine.Matchers.prototype.toNotMatch = function(expected) { -112 return !(new RegExp(expected).test(this.actual)); -113 }; -114 -115 /** -116 * Matcher that compares the actual to jasmine.undefined. -117 */ -118 jasmine.Matchers.prototype.toBeDefined = function() { -119 return (this.actual !== jasmine.undefined); -120 }; -121 -122 /** -123 * Matcher that compares the actual to jasmine.undefined. -124 */ -125 jasmine.Matchers.prototype.toBeUndefined = function() { -126 return (this.actual === jasmine.undefined); -127 }; -128 -129 /** -130 * Matcher that compares the actual to null. -131 */ -132 jasmine.Matchers.prototype.toBeNull = function() { -133 return (this.actual === null); -134 }; -135 -136 /** -137 * Matcher that boolean not-nots the actual. -138 */ -139 jasmine.Matchers.prototype.toBeTruthy = function() { -140 return !!this.actual; -141 }; -142 -143 -144 /** -145 * Matcher that boolean nots the actual. -146 */ -147 jasmine.Matchers.prototype.toBeFalsy = function() { -148 return !this.actual; -149 }; -150 -151 /** -152 * Matcher that checks to see if the actual, a Jasmine spy, was called. -153 */ -154 jasmine.Matchers.prototype.wasCalled = function() { -155 if (arguments.length > 0) { -156 throw new Error('wasCalled does not take arguments, use wasCalledWith'); -157 } -158 -159 if (!jasmine.isSpy(this.actual)) { -160 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -161 } -162 -163 this.message = function() { -164 return "Expected spy " + this.actual.identity + " to have been called."; -165 }; -166 -167 return this.actual.wasCalled; -168 }; -169 -170 /** -171 * Matcher that checks to see if the actual, a Jasmine spy, was not called. -172 */ -173 jasmine.Matchers.prototype.wasNotCalled = function() { -174 if (arguments.length > 0) { -175 throw new Error('wasNotCalled does not take arguments'); -176 } -177 -178 if (!jasmine.isSpy(this.actual)) { -179 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -180 } -181 -182 this.message = function() { -183 return "Expected spy " + this.actual.identity + " to not have been called."; -184 }; -185 -186 return !this.actual.wasCalled; -187 }; -188 -189 /** -190 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. -191 * -192 * @example -193 * -194 */ -195 jasmine.Matchers.prototype.wasCalledWith = function() { -196 if (!jasmine.isSpy(this.actual)) { -197 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -198 } -199 -200 this.message = function() { -201 if (this.actual.callCount == 0) { -202 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; -203 } else { -204 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); -205 } -206 }; -207 -208 return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); -209 }; -210 -211 jasmine.Matchers.prototype.wasNotCalledWith = function() { -212 if (!jasmine.isSpy(this.actual)) { -213 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -214 } -215 -216 this.message = function() { -217 return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; -218 }; -219 -220 return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); -221 }; -222 -223 /** -224 * Matcher that checks that the expected item is an element in the actual Array. -225 * -226 * @param {Object} item -227 */ -228 jasmine.Matchers.prototype.toContain = function(expected) { -229 return this.env.contains_(this.actual, expected); -230 }; -231 -232 /** -233 * Matcher that checks that the expected item is NOT an element in the actual Array. -234 * -235 * @param {Object} item -236 */ -237 jasmine.Matchers.prototype.toNotContain = function(expected) { -238 return !this.env.contains_(this.actual, expected); -239 }; -240 -241 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -242 return this.actual < expected; + 85 /** + 86 * toNotBe: compares the actual to the expected using !== + 87 * @param expected + 88 */ + 89 jasmine.Matchers.prototype.toNotBe = function(expected) { + 90 return this.actual !== expected; + 91 }; + 92 + 93 /** + 94 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. + 95 * + 96 * @param expected + 97 */ + 98 jasmine.Matchers.prototype.toEqual = function(expected) { + 99 return this.env.equals_(this.actual, expected); +100 }; +101 +102 /** +103 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual +104 * @param expected +105 */ +106 jasmine.Matchers.prototype.toNotEqual = function(expected) { +107 return !this.env.equals_(this.actual, expected); +108 }; +109 +110 /** +111 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +112 * a pattern or a String. +113 * +114 * @param expected +115 */ +116 jasmine.Matchers.prototype.toMatch = function(expected) { +117 return new RegExp(expected).test(this.actual); +118 }; +119 +120 /** +121 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +122 * @param expected +123 */ +124 jasmine.Matchers.prototype.toNotMatch = function(expected) { +125 return !(new RegExp(expected).test(this.actual)); +126 }; +127 +128 /** +129 * Matcher that compares the actual to jasmine.undefined. +130 */ +131 jasmine.Matchers.prototype.toBeDefined = function() { +132 return (this.actual !== jasmine.undefined); +133 }; +134 +135 /** +136 * Matcher that compares the actual to jasmine.undefined. +137 */ +138 jasmine.Matchers.prototype.toBeUndefined = function() { +139 return (this.actual === jasmine.undefined); +140 }; +141 +142 /** +143 * Matcher that compares the actual to null. +144 */ +145 jasmine.Matchers.prototype.toBeNull = function() { +146 return (this.actual === null); +147 }; +148 +149 /** +150 * Matcher that boolean not-nots the actual. +151 */ +152 jasmine.Matchers.prototype.toBeTruthy = function() { +153 return !!this.actual; +154 }; +155 +156 +157 /** +158 * Matcher that boolean nots the actual. +159 */ +160 jasmine.Matchers.prototype.toBeFalsy = function() { +161 return !this.actual; +162 }; +163 +164 /** +165 * Matcher that checks to see if the actual, a Jasmine spy, was called. +166 */ +167 jasmine.Matchers.prototype.wasCalled = function() { +168 if (arguments.length > 0) { +169 throw new Error('wasCalled does not take arguments, use wasCalledWith'); +170 } +171 +172 if (!jasmine.isSpy(this.actual)) { +173 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +174 } +175 +176 this.message = function() { +177 return "Expected spy " + this.actual.identity + " to have been called."; +178 }; +179 +180 return this.actual.wasCalled; +181 }; +182 +183 /** +184 * Matcher that checks to see if the actual, a Jasmine spy, was not called. +185 */ +186 jasmine.Matchers.prototype.wasNotCalled = function() { +187 if (arguments.length > 0) { +188 throw new Error('wasNotCalled does not take arguments'); +189 } +190 +191 if (!jasmine.isSpy(this.actual)) { +192 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +193 } +194 +195 this.message = function() { +196 return "Expected spy " + this.actual.identity + " to not have been called."; +197 }; +198 +199 return !this.actual.wasCalled; +200 }; +201 +202 /** +203 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. +204 * +205 * @example +206 * +207 */ +208 jasmine.Matchers.prototype.wasCalledWith = function() { +209 if (!jasmine.isSpy(this.actual)) { +210 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +211 } +212 +213 this.message = function() { +214 if (this.actual.callCount == 0) { +215 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; +216 } else { +217 return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); +218 } +219 }; +220 +221 return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +222 }; +223 +224 jasmine.Matchers.prototype.wasNotCalledWith = function() { +225 if (!jasmine.isSpy(this.actual)) { +226 throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +227 } +228 +229 this.message = function() { +230 return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; +231 }; +232 +233 return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +234 }; +235 +236 /** +237 * Matcher that checks that the expected item is an element in the actual Array. +238 * +239 * @param {Object} expected +240 */ +241 jasmine.Matchers.prototype.toContain = function(expected) { +242 return this.env.contains_(this.actual, expected); 243 }; 244 -245 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -246 return this.actual > expected; -247 }; -248 -249 /** -250 * Matcher that checks that the expected exception was thrown by the actual. -251 * -252 * @param {String} expectedException -253 */ -254 jasmine.Matchers.prototype.toThrow = function(expected) { -255 function getException_(actual, expected) { -256 var exception; -257 if (typeof actual != 'function') { -258 throw new Error('Actual is not a function'); -259 } -260 try { -261 actual(); -262 } catch (e) { -263 exception = e; -264 } -265 return exception; -266 } -267 +245 /** +246 * Matcher that checks that the expected item is NOT an element in the actual Array. +247 * +248 * @param {Object} expected +249 */ +250 jasmine.Matchers.prototype.toNotContain = function(expected) { +251 return !this.env.contains_(this.actual, expected); +252 }; +253 +254 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +255 return this.actual < expected; +256 }; +257 +258 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +259 return this.actual > expected; +260 }; +261 +262 /** +263 * Matcher that checks that the expected exception was thrown by the actual. +264 * +265 * @param {String} expected +266 */ +267 jasmine.Matchers.prototype.toThrow = function(expected) { 268 var result = false; -269 var exception = getException_(this.actual, expected); -270 if (exception) { -271 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +269 var exception; +270 if (typeof this.actual != 'function') { +271 throw new Error('Actual is not a function'); 272 } -273 -274 this.message = function(expected) { -275 var exception = getException_(this.actual, expected); -276 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -277 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); -278 } else { -279 return "Expected function to throw an exception."; -280 } -281 }; -282 -283 return result; -284 }; -285 -286 jasmine.Matchers.Any = function(expectedClass) { -287 this.expectedClass = expectedClass; -288 }; +273 try { +274 this.actual(); +275 } catch (e) { +276 exception = e; +277 } +278 if (exception) { +279 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +280 } +281 +282 this.message = function() { +283 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { +284 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); +285 } else { +286 return "Expected function to throw an exception."; +287 } +288 }; 289 -290 jasmine.Matchers.Any.prototype.matches = function(other) { -291 if (this.expectedClass == String) { -292 return typeof other == 'string' || other instanceof String; -293 } -294 -295 if (this.expectedClass == Number) { -296 return typeof other == 'number' || other instanceof Number; -297 } -298 -299 if (this.expectedClass == Function) { -300 return typeof other == 'function' || other instanceof Function; -301 } -302 -303 if (this.expectedClass == Object) { -304 return typeof other == 'object'; -305 } -306 -307 return other instanceof this.expectedClass; -308 }; +290 return result; +291 }; +292 +293 jasmine.Matchers.Any = function(expectedClass) { +294 this.expectedClass = expectedClass; +295 }; +296 +297 jasmine.Matchers.Any.prototype.matches = function(other) { +298 if (this.expectedClass == String) { +299 return typeof other == 'string' || other instanceof String; +300 } +301 +302 if (this.expectedClass == Number) { +303 return typeof other == 'number' || other instanceof Number; +304 } +305 +306 if (this.expectedClass == Function) { +307 return typeof other == 'function' || other instanceof Function; +308 } 309 -310 jasmine.Matchers.Any.prototype.toString = function() { -311 return '<jasmine.any(' + this.expectedClass + ')>'; -312 }; +310 if (this.expectedClass == Object) { +311 return typeof other == 'object'; +312 } 313 -314 \ No newline at end of file +314 return other instanceof this.expectedClass; +315 }; +316 +317 jasmine.Matchers.Any.prototype.toString = function() { +318 return '<jasmine.any(' + this.expectedClass + ')>'; +319 }; +320 +321 \ No newline at end of file diff --git a/doc/symbols/src/src_Spec.js.html b/doc/symbols/src/src_Spec.js.html index 2523022..8b69c25 100644 --- a/doc/symbols/src/src_Spec.js.html +++ b/doc/symbols/src/src_Spec.js.html @@ -105,109 +105,107 @@ 98 parent.apply(this, arguments); 99 }; 100 jasmine.util.inherit(newMatchersClass, parent); -101 for (var method in matchersPrototype) { -102 newMatchersClass.prototype[method] = matchersPrototype[method]; -103 } -104 this.matchersClass = newMatchersClass; -105 }; -106 -107 jasmine.Spec.prototype.finishCallback = function() { -108 this.env.reporter.reportSpecResults(this); -109 }; -110 -111 jasmine.Spec.prototype.finish = function(onComplete) { -112 this.removeAllSpies(); -113 this.finishCallback(); -114 if (onComplete) { -115 onComplete(); -116 } -117 }; +101 jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); +102 this.matchersClass = newMatchersClass; +103 }; +104 +105 jasmine.Spec.prototype.finishCallback = function() { +106 this.env.reporter.reportSpecResults(this); +107 }; +108 +109 jasmine.Spec.prototype.finish = function(onComplete) { +110 this.removeAllSpies(); +111 this.finishCallback(); +112 if (onComplete) { +113 onComplete(); +114 } +115 }; +116 +117 jasmine.Spec.prototype.after = function(doAfter, test) { 118 -119 jasmine.Spec.prototype.after = function(doAfter, test) { -120 -121 if (this.queue.isRunning()) { -122 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -123 } else { -124 this.afterCallbacks.unshift(doAfter); -125 } -126 }; -127 -128 jasmine.Spec.prototype.execute = function(onComplete) { -129 var spec = this; -130 if (!spec.env.specFilter(spec)) { -131 spec.results_.skipped = true; -132 spec.finish(onComplete); -133 return; -134 } -135 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +119 if (this.queue.isRunning()) { +120 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +121 } else { +122 this.afterCallbacks.unshift(doAfter); +123 } +124 }; +125 +126 jasmine.Spec.prototype.execute = function(onComplete) { +127 var spec = this; +128 if (!spec.env.specFilter(spec)) { +129 spec.results_.skipped = true; +130 spec.finish(onComplete); +131 return; +132 } +133 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); +134 +135 spec.env.currentSpec = spec; 136 -137 spec.env.currentSpec = spec; +137 spec.addBeforesAndAftersToQueue(); 138 -139 spec.addBeforesAndAftersToQueue(); -140 -141 spec.queue.start(function () { -142 spec.finish(onComplete); -143 }); -144 }; -145 -146 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -147 var runner = this.env.currentRunner(); -148 for (var suite = this.suite; suite; suite = suite.parentSuite) { -149 for (var i = 0; i < suite.before_.length; i++) { -150 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -151 } -152 } -153 for (var i = 0; i < runner.before_.length; i++) { -154 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -155 } -156 for (i = 0; i < this.afterCallbacks.length; i++) { -157 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -158 } -159 for (suite = this.suite; suite; suite = suite.parentSuite) { -160 for (var i = 0; i < suite.after_.length; i++) { -161 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -162 } -163 } -164 for (var i = 0; i < runner.after_.length; i++) { -165 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -166 } -167 }; -168 -169 jasmine.Spec.prototype.explodes = function() { -170 throw 'explodes function should not have been called'; -171 }; -172 -173 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -174 if (obj == jasmine.undefined) { -175 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -176 } -177 -178 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { -179 throw methodName + '() method does not exist'; -180 } -181 -182 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -183 throw new Error(methodName + ' has already been spied upon'); -184 } +139 spec.queue.start(function () { +140 spec.finish(onComplete); +141 }); +142 }; +143 +144 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +145 var runner = this.env.currentRunner(); +146 for (var suite = this.suite; suite; suite = suite.parentSuite) { +147 for (var i = 0; i < suite.before_.length; i++) { +148 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +149 } +150 } +151 for (var i = 0; i < runner.before_.length; i++) { +152 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +153 } +154 for (i = 0; i < this.afterCallbacks.length; i++) { +155 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +156 } +157 for (suite = this.suite; suite; suite = suite.parentSuite) { +158 for (var i = 0; i < suite.after_.length; i++) { +159 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +160 } +161 } +162 for (var i = 0; i < runner.after_.length; i++) { +163 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +164 } +165 }; +166 +167 jasmine.Spec.prototype.explodes = function() { +168 throw 'explodes function should not have been called'; +169 }; +170 +171 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +172 if (obj == jasmine.undefined) { +173 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +174 } +175 +176 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { +177 throw methodName + '() method does not exist'; +178 } +179 +180 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +181 throw new Error(methodName + ' has already been spied upon'); +182 } +183 +184 var spyObj = jasmine.createSpy(methodName); 185 -186 var spyObj = jasmine.createSpy(methodName); -187 -188 this.spies_.push(spyObj); -189 spyObj.baseObj = obj; -190 spyObj.methodName = methodName; -191 spyObj.originalValue = obj[methodName]; +186 this.spies_.push(spyObj); +187 spyObj.baseObj = obj; +188 spyObj.methodName = methodName; +189 spyObj.originalValue = obj[methodName]; +190 +191 obj[methodName] = spyObj; 192 -193 obj[methodName] = spyObj; -194 -195 return spyObj; -196 }; -197 -198 jasmine.Spec.prototype.removeAllSpies = function() { -199 for (var i = 0; i < this.spies_.length; i++) { -200 var spy = this.spies_[i]; -201 spy.baseObj[spy.methodName] = spy.originalValue; -202 } -203 this.spies_ = []; -204 }; -205 -206 \ No newline at end of file +193 return spyObj; +194 }; +195 +196 jasmine.Spec.prototype.removeAllSpies = function() { +197 for (var i = 0; i < this.spies_.length; i++) { +198 var spy = this.spies_[i]; +199 spy.baseObj[spy.methodName] = spy.originalValue; +200 } +201 this.spies_ = []; +202 }; +203 +204 \ No newline at end of file diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 850daae..bb7547e 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -640,10 +640,7 @@ jasmine.Env = function() { }; jasmine.util.inherit(this.matchersClass, jasmine.Matchers); - for (var methodName in jasmine.Matchers.prototype) { - var orig = jasmine.Matchers.prototype[methodName]; - this.matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); - } + jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); }; @@ -1009,13 +1006,18 @@ jasmine.Matchers = function(env, actual, spec) { this.env = env; this.actual = actual; this.spec = spec; + this.reportWasCalled_ = false; }; jasmine.Matchers.pp = function(str) { return jasmine.util.htmlEscape(jasmine.pp(str)); }; +/** @deprecated */ jasmine.Matchers.prototype.report = function(result, failing_message, details) { +// todo first: report deprecation warning [xw] +// todo later: throw new Error("As of jasmine 0.xx, custom matchers must be implemented differently -- please see jasmine docs"); + this.reportWasCalled_ = true; var expectationResult = new jasmine.ExpectationResult({ passed: result, message: failing_message, @@ -1025,10 +1027,20 @@ jasmine.Matchers.prototype.report = function(result, failing_message, details) { return result; }; +jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { + for (var methodName in prototype) { + if (methodName == 'report') continue; + var orig = prototype[methodName]; + matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); + } +}; + jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { return function() { var matcherArgs = jasmine.util.argsToArray(arguments); var result = matcherFunction.apply(this, arguments); + if (this.reportWasCalled_) return result; + var message; if (!result) { if (this.message) { @@ -1064,7 +1076,6 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { * toBe: compares the actual to the expected using === * @param expected */ - jasmine.Matchers.prototype.toBe = function(expected) { return this.actual === expected; }; @@ -1082,7 +1093,6 @@ jasmine.Matchers.prototype.toNotBe = function(expected) { * * @param expected */ - jasmine.Matchers.prototype.toEqual = function(expected) { return this.env.equals_(this.actual, expected); }; @@ -1099,7 +1109,7 @@ jasmine.Matchers.prototype.toNotEqual = function(expected) { * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes * a pattern or a String. * - * @param reg_exp + * @param expected */ jasmine.Matchers.prototype.toMatch = function(expected) { return new RegExp(expected).test(this.actual); @@ -1107,7 +1117,7 @@ jasmine.Matchers.prototype.toMatch = function(expected) { /** * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch - * @param reg_exp + * @param expected */ jasmine.Matchers.prototype.toNotMatch = function(expected) { return !(new RegExp(expected).test(this.actual)); @@ -1224,7 +1234,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() { /** * Matcher that checks that the expected item is an element in the actual Array. * - * @param {Object} item + * @param {Object} expected */ jasmine.Matchers.prototype.toContain = function(expected) { return this.env.contains_(this.actual, expected); @@ -1233,7 +1243,7 @@ jasmine.Matchers.prototype.toContain = function(expected) { /** * Matcher that checks that the expected item is NOT an element in the actual Array. * - * @param {Object} item + * @param {Object} expected */ jasmine.Matchers.prototype.toNotContain = function(expected) { return !this.env.contains_(this.actual, expected); @@ -1250,32 +1260,26 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { /** * Matcher that checks that the expected exception was thrown by the actual. * - * @param {String} expectedException + * @param {String} expected */ jasmine.Matchers.prototype.toThrow = function(expected) { - function getException_(actual, expected) { - var exception; - if (typeof actual != 'function') { - throw new Error('Actual is not a function'); - } - try { - actual(); - } catch (e) { - exception = e; - } - return exception; - } - var result = false; - var exception = getException_(this.actual, expected); + var exception; + if (typeof this.actual != 'function') { + throw new Error('Actual is not a function'); + } + try { + this.actual(); + } catch (e) { + exception = e; + } if (exception) { result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); } - this.message = function(expected) { - var exception = getException_(this.actual, expected); + this.message = function() { if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { - return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); + return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); } else { return "Expected function to throw an exception."; } @@ -1847,9 +1851,7 @@ jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { parent.apply(this, arguments); }; jasmine.util.inherit(newMatchersClass, parent); - for (var method in matchersPrototype) { - newMatchersClass.prototype[method] = matchersPrototype[method]; - } + jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); this.matchersClass = newMatchersClass; }; @@ -2255,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1261632445 + "revision": 1261768736 }; From c78460289affe72ecf01abb5fe1b64bc6feb36c7 Mon Sep 17 00:00:00 2001 From: David Goudreau & Rajan Agaskar Date: Mon, 28 Dec 2009 15:45:15 -0800 Subject: [PATCH 07/29] trying to get saucelabs ci build to work --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 2bb0f6e..937d5c7 100644 --- a/Rakefile +++ b/Rakefile @@ -135,6 +135,7 @@ jasmine.version_= { desc "Run continuous integration tests using Sauce Labs 'Selenium in the Cloud'" task :saucelabs => 'jasmine:build' do + `cp ../saucelabs.yml ./spec` ENV['SAUCELABS'] = 'true' Rake::Task['jasmine:test:ci:local'].invoke end From ca841c92483cb39cf34c3e66a20bea76ad4d7f4a Mon Sep 17 00:00:00 2001 From: David Goudreau & Rajan Agaskar Date: Mon, 28 Dec 2009 16:02:09 -0800 Subject: [PATCH 08/29] Adding geminstaller as build dependency --- Rakefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 937d5c7..8c7a577 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ namespace :jasmine do end desc 'Builds lib/jasmine from source' - task :build => :lint do + task :build => [:lint, 'gems:geminstaller'] do puts 'Building Jasmine from source' require 'json' @@ -143,3 +143,10 @@ jasmine.version_= { end end + +namespace :gems do + desc "Run geminstaller." + task :geminstaller do + `geminstaller --sudo -c config/geminstaller.yml` + end +end \ No newline at end of file From 02db3338fbb6235c33901e9e565f0b9913b1ebcd Mon Sep 17 00:00:00 2001 From: David Goudreau & Rajan Agaskar Date: Mon, 28 Dec 2009 16:19:39 -0800 Subject: [PATCH 09/29] Add gems:geminstaller task --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 8c7a577..17e2c60 100644 --- a/Rakefile +++ b/Rakefile @@ -147,6 +147,6 @@ end namespace :gems do desc "Run geminstaller." task :geminstaller do - `geminstaller --sudo -c config/geminstaller.yml` + `geminstaller --sudo` end end \ No newline at end of file From 99ab1f0e81de1b77d9bee2ef73674208980fc75a Mon Sep 17 00:00:00 2001 From: David Goudreau & Rajan Agaskar Date: Mon, 28 Dec 2009 16:32:20 -0800 Subject: [PATCH 10/29] Remove saucelabs.yml copying --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 17e2c60..1d3b425 100644 --- a/Rakefile +++ b/Rakefile @@ -135,7 +135,6 @@ jasmine.version_= { desc "Run continuous integration tests using Sauce Labs 'Selenium in the Cloud'" task :saucelabs => 'jasmine:build' do - `cp ../saucelabs.yml ./spec` ENV['SAUCELABS'] = 'true' Rake::Task['jasmine:test:ci:local'].invoke end From 163f5977a55f0cfb6b083dfe5c4b8e241dc34c43 Mon Sep 17 00:00:00 2001 From: David Goudreau & Rajan Agaskar Date: Mon, 28 Dec 2009 16:45:01 -0800 Subject: [PATCH 11/29] making jasmine know about ci --- Rakefile | 6 +++++- cruise_config.rb | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cruise_config.rb diff --git a/Rakefile b/Rakefile index 1d3b425..7a88614 100644 --- a/Rakefile +++ b/Rakefile @@ -134,13 +134,17 @@ jasmine.version_= { end desc "Run continuous integration tests using Sauce Labs 'Selenium in the Cloud'" - task :saucelabs => 'jasmine:build' do + task :saucelabs => ['jasmine:copy_saucelabs_config', 'jasmine:build'] do ENV['SAUCELABS'] = 'true' Rake::Task['jasmine:test:ci:local'].invoke end end end + desc 'Copy saucelabs.yml to work directory' + task 'copy_saucelabs_config' do + FileUtils.cp '../saucelabs.yml', 'spec' + end end namespace :gems do diff --git a/cruise_config.rb b/cruise_config.rb new file mode 100644 index 0000000..20d2a5c --- /dev/null +++ b/cruise_config.rb @@ -0,0 +1,21 @@ +# Project-specific configuration for CruiseControl.rb +Project.configure do |project| + + # Send email notifications about broken and fixed builds to email1@your.site, email2@your.site (default: send to nobody) + # project.email_notifier.emails = ['email1@your.site', 'email2@your.site'] + + # Set email 'from' field to john@doe.com: + # project.email_notifier.from = 'john@doe.com' + + # Build the project by invoking rake task 'custom' + project.rake_task = 'jasmine:test:ci:saucelabs' + + # Build the project by invoking shell script "build_my_app.sh". Keep in mind that when the script is invoked, + # current working directory is [cruise data]/projects/your_project/work, so if you do not keep build_my_app.sh + # in version control, it should be '../build_my_app.sh' instead + #project.build_command = 'cp ../saucelabs.yml .' + + # Ping Subversion for new revisions every 5 minutes (default: 30 seconds) + # project.scheduler.polling_interval = 5.minutes + +end From 81c2779731119e3350b75529a06a56957c8d60bf Mon Sep 17 00:00:00 2001 From: Rajan Agaskar Date: Wed, 30 Dec 2009 17:03:02 -0800 Subject: [PATCH 12/29] HTML example name refactor --- examples/html/{example_suite.html => example_runner.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/html/{example_suite.html => example_runner.html} (100%) diff --git a/examples/html/example_suite.html b/examples/html/example_runner.html similarity index 100% rename from examples/html/example_suite.html rename to examples/html/example_runner.html From d72b18c47b480e0a2c847f16f334fc90899c70c8 Mon Sep 17 00:00:00 2001 From: "Davis W. Frank & Rajan Agaskar" Date: Mon, 4 Jan 2010 14:57:05 -0800 Subject: [PATCH 13/29] README updates --- README.markdown | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 5977992..0403e29 100644 --- a/README.markdown +++ b/README.markdown @@ -18,10 +18,9 @@ Quick Start open `http://localhost:8888/` in your favorite browser. ### HTML Suite Running + [Get the latest release from the downloads page](http://github.com/pivotal/jasmine/downloads) - git clone git://github.com/pivotal/jasmine.git - -open `examples/test/html/example_suite.html` in your favorite browser. +open `example/example_runner.html` in your favorite browser ### Automatic Suite Running (w/ Selenium) @@ -35,8 +34,7 @@ open `examples/test/html/example_suite.html` in your favorite browser. Releases ---------- -0.10.0 [[download]](http://github.com/pivotal/jasmine/zipball/master) -`git clone git://github.com/pivotal/jasmine.git` +0.10.0 [[download]](http://cloud.github.com/downloads/pivotal/jasmine/jasmine-0.10.0.zip) 0.9.0 [[download]](http://github.com/pivotal/jasmine/zipball/0.9.0) @@ -467,6 +465,7 @@ We now have a Google Group for support & discussion. * Homepage: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js) * Group email: [jasmine-js@googlegroups.com](jasmine-js@googlegroups.com) +* Current build status of Jasmine is visible at [ci.pivotallabs.com](http://ci.pivotallabs.com) ## Maintainers From db1c6e659d0aa01eae649630cb18af6552adf9c5 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Sat, 23 Jan 2010 13:50:44 -0800 Subject: [PATCH 14/29] Updated ruby contrib so that CI task now compatible with Prototype --- contrib/ruby/jasmine_spec_builder.rb | 4 ++-- doc/files.html | 2 +- doc/index.html | 2 +- doc/symbols/_global_.html | 2 +- doc/symbols/jasmine.Block.html | 2 +- doc/symbols/jasmine.Clock.html | 2 +- doc/symbols/jasmine.Env.html | 2 +- doc/symbols/jasmine.JsApiReporter.html | 2 +- doc/symbols/jasmine.Matchers.html | 2 +- doc/symbols/jasmine.MultiReporter.html | 2 +- doc/symbols/jasmine.NestedResults.html | 2 +- doc/symbols/jasmine.Reporter.html | 2 +- doc/symbols/jasmine.Runner.html | 2 +- doc/symbols/jasmine.Spec.html | 2 +- doc/symbols/jasmine.Spy.html | 2 +- doc/symbols/jasmine.Suite.html | 2 +- doc/symbols/jasmine.html | 2 +- doc/symbols/jasmine.util.html | 2 +- lib/jasmine-0.10.0.js | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) diff --git a/contrib/ruby/jasmine_spec_builder.rb b/contrib/ruby/jasmine_spec_builder.rb index 260c9e2..06ac7f5 100644 --- a/contrib/ruby/jasmine_spec_builder.rb +++ b/contrib/ruby/jasmine_spec_builder.rb @@ -58,7 +58,7 @@ module Jasmine sleep 0.1 end - @suites = eval_js('JSON.stringify(jsApiReporter.suites())') + @suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && result && result.toJSON) { result.toJSON()} else { JSON.stringify(result) }") end def results_for(spec_id) @@ -69,7 +69,7 @@ module Jasmine def load_results @spec_results = {} @spec_ids.each_slice(50) do |slice| - @spec_results.merge!(eval_js("JSON.stringify(jsApiReporter.resultsForSpecs(#{JSON.generate(slice)}))")) + @spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{JSON.generate(slice)}); if (window.Prototype && result && result.toJSON) { result.toJSON()} else { JSON.stringify(result) }")) end @spec_results end diff --git a/doc/files.html b/doc/files.html index 50ff90b..bf7627d 100644 --- a/doc/files.html +++ b/doc/files.html @@ -454,7 +454,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 1aa2b28..286c31b 100644 --- a/doc/index.html +++ b/doc/index.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 6e50334..7cc1447 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -912,7 +912,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:21 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 73c5e7d..aa3f4e7 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -411,7 +411,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Clock.html b/doc/symbols/jasmine.Clock.html index 627ae47..6f8aa91 100644 --- a/doc/symbols/jasmine.Clock.html +++ b/doc/symbols/jasmine.Clock.html @@ -672,7 +672,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 35625fc..44245e8 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -1163,7 +1163,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 61255dd..5bedb54 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -816,7 +816,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index bc20fdc..f176252 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -1455,7 +1455,7 @@ a pattern or a String.
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 36fc55b..160c5d9 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -388,7 +388,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index cff8abc..4599bee 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 3420f20..0c8a42c 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -568,7 +568,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index ba336dc..ea05684 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -704,7 +704,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index f411d58..5fe4f4c 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -1253,7 +1253,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index 37667bc..bd08ca0 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -849,7 +849,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index 11d664c..6ed8176 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -699,7 +699,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index 6464a3f..2904d8a 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -1339,7 +1339,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:21 GMT-0800 (PST)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 445374f..f630c16 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -529,7 +529,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Fri Dec 25 2009 14:19:05 GMT-0500 (EST) + Documentation generated by JsDoc Toolkit 2.1.0 on Sat Jan 23 2010 13:48:22 GMT-0800 (PST)
diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index bb7547e..908b8e9 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -2257,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1261768736 + "revision": 1264283294 }; From b12605274de8f7cc293bf65cf8b217c20e12a65c Mon Sep 17 00:00:00 2001 From: ragaskar Date: Wed, 27 Jan 2010 19:19:30 -0800 Subject: [PATCH 15/29] Minor css bugfix, doc update --- README.markdown | 3 ++- lib/jasmine-0.10.0.js | 2 +- lib/jasmine.css | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 0403e29..95631eb 100644 --- a/README.markdown +++ b/README.markdown @@ -471,8 +471,9 @@ We now have a Google Group for support & discussion. * [Davis W. Frank](mailto:dwfrank@pivotallabs.com), Pivotal Labs * [Rajan Agaskar](mailto:rajan@pivotallabs.com), Pivotal Labs +* [Christian Williams](mailto:xian@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. * Thanks to Pivot [Jessica Miller](http://www.jessicamillerworks.com/) for our fancy pass/fail/pending icons -* Huge contributions have been made by [Christian Williams](mailto:xian@pivotallabs.com) (the master "spy" coder), [Erik Hanson](mailto:erik@pivotallabs.com), [Adam Abrons](mailto:adam@pivotallabs.com) and [Carl Jackson](mailto:carl@pivotallabs.com), and many other Pivots. +* Huge contributions have been made by [Erik Hanson](mailto:erik@pivotallabs.com), [Adam Abrons](mailto:adam@pivotallabs.com) and [Carl Jackson](mailto:carl@pivotallabs.com), and many other Pivots. diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 908b8e9..31e25e4 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -2257,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1264283294 + "revision": 1264648722 }; diff --git a/lib/jasmine.css b/lib/jasmine.css index 61ea145..15927d9 100644 --- a/lib/jasmine.css +++ b/lib/jasmine.css @@ -82,5 +82,5 @@ body .run_spec { #jasmine_content { position:fixed; - left: 100%; + right: 100%; } From 8679090bf312393a29ac9fb14124178c70447161 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Sat, 20 Feb 2010 14:08:45 -0500 Subject: [PATCH 16/29] Convert tabs to spaces. --- README.markdown | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/README.markdown b/README.markdown index 95631eb..b3640c8 100644 --- a/README.markdown +++ b/README.markdown @@ -8,10 +8,10 @@ Quick Start ### Ruby Suite Running sudo gem sources -a http://gems.github.com - sudo gem install geminstaller + sudo gem install geminstaller git clone git://github.com/pivotal/jasmine.git cd jasmine - sudo geminstaller + sudo geminstaller cd examples/ruby rake jasmine_server @@ -20,12 +20,12 @@ open `http://localhost:8888/` in your favorite browser. ### HTML Suite Running [Get the latest release from the downloads page](http://github.com/pivotal/jasmine/downloads) -open `example/example_runner.html` in your favorite browser +open `example/example_runner.html` in your favorite browser ### Automatic Suite Running (w/ Selenium) sudo gem sources -a http://gems.github.com - sudo gem install geminstaller + sudo gem install geminstaller git clone git://github.com/pivotal/jasmine.git cd jasmine sudo geminstaller @@ -77,7 +77,7 @@ Exciting changes are afoot and many syntax changes have been made to make Jasmin Each spec is, naturally, a JavaScript function. You tell Jasmine about this spec with a call to `it()` with a string and the function. The string is a description that will be helpful to you when reading a report. it('should be a test', function () { - var foo = 0 + var foo = 0 foo++; }); @@ -122,10 +122,10 @@ Jasmine has several built-in matchers. Here are a few: A Matcher has a method name, takes an expected value as it's only parameter, has access to the actual value in this, and then makes a call to this.report with true/false with a failure message. Here's the definition of `toEqual()`: - jasmine.Matchers.prototype.toEqual = function (expected) { - return this.report((this.actual === expected), - 'Expected ' + expected + ' but got ' + this.actual + '.'); - }; + jasmine.Matchers.prototype.toEqual = function (expected) { + return this.report((this.actual === expected), + 'Expected ' + expected + ' but got ' + this.actual + '.'); + }; Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests. @@ -199,7 +199,7 @@ multiple `runs()` blocks in a spec will run serially. For example, `runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example: - it('should be a test', function () { + it('should be a test', function () { runs(function () { this.foo = 0; var that = this; @@ -217,7 +217,7 @@ timeout before the next block is run. You supply a time to wait before the next runs(function () { this.expects(this.foo).toEqual(1); }); - }); + }); What's happening here? @@ -231,33 +231,33 @@ What's happening here? Specs are grouped in Suites. Suites are defined using the global `describe()` function: - describe('One suite', function () { - it('has a test', function () { - ... - }); + describe('One suite', function () { + it('has a test', function () { + ... + }); - it('has another test', function () { - ... - }); - }); + it('has another test', function () { + ... + }); + }); The Suite name is so that reporting is more descriptive. Suites are executed in the order in which `describe()` calls are made, usually in the order in which their script files are included. Additionally, specs within a suite share a functional scope. So you may declare variables inside a describe block and they are accessible from within your specs. For example: - describe('A suite with some variables', function () { + describe('A suite with some variables', function () { var bar = 0 - - it('has a test', function () { - bar++; - expect(bar).toEqual(1); - }); - it('has another test', function () { - bar++; + it('has a test', function () { + bar++; + expect(bar).toEqual(1); + }); + + it('has another test', function () { + bar++; expect(bar).toEqual(2); - }); - }); + }); + }); #### beforeEach @@ -353,13 +353,13 @@ Jasmine supports nested describes. An example: var nestedSuiteBar; beforeEach(function() { nestedSuiteBar=1; - }); + }); it('nested expectation', function () { expect(suiteWideFoo).toEqual(0); expect(nestedSuiteBar).toEqual(1); }); - + }); it('top-level describe', function () { @@ -384,7 +384,7 @@ Here are a few examples: var Klass.prototype.methodWithCallback = function (callback) { return callback('foo'); }; - + ... it('should spy on Klass#method') { From 535d9abce008669eccf3be2630cf7c92dad9ea96 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Sat, 20 Feb 2010 14:44:58 -0500 Subject: [PATCH 17/29] Update docs about Matchers to use addMatcher(). --- README.markdown | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/README.markdown b/README.markdown index b3640c8..832647e 100644 --- a/README.markdown +++ b/README.markdown @@ -98,36 +98,33 @@ Results of the expectations are logged for later for reporting. Jasmine has several built-in matchers. Here are a few: -`toEqual()` compares objects or primitives and returns true if they are equal - -`toNotEqual()` compares objects or primitives and returns true if they are not equal - -`toMatch()` takes a regex or a string and returns true if it matches - -`toNotMatch()` takes a regex or a string and returns true if it does not match - -`toBeDefined()` returns true if the object or primitive is not `undefined` - -`toBeNull()` returns true if the object or primitive is not `null` - -`toBeTruthy()` returns true if the object or primitive evaluates to true - -`toBeFalsy()` returns true if the object or primitive evaluates to false - -`toContain()` returns true if an array or string contains the passed variable. - -`toNotContain()` returns true if an array or string does not contain the passed variable. +>`expect(x).toEqual(y);` compares objects or primitives `x` and `y` and passes if they are equivalent +>`expect(x).toMatch(pattern);` compares `x` to string or regular expression `pattern` and passes if they match +>`expect(x).toBeDefined();` passes if `x` is not `undefined` +>`expect(x).toBeNull();` passes if `x` is not `null` +>`expect(x).toBeTruthy();` passes if `x` evaluates to true +>`expect(x).toBeFalsy();` passes if `x` evaluates to false +>`expect(x).toContain(y);` passes if array or string `x` contains `y` #### Writing New Matchers -A Matcher has a method name, takes an expected value as it's only parameter, has access to the actual value in this, and then makes a call to this.report with true/false with a failure message. Here's the definition of `toEqual()`: +We've provided a small set of matchers that cover many common situations. However, we recommend that you write custom matchers when you want to assert a more specific sort of expectation. Custom matchers help to document the intent of your specs, and can help to remove code duplication in your specs. - jasmine.Matchers.prototype.toEqual = function (expected) { - return this.report((this.actual === expected), - 'Expected ' + expected + ' but got ' + this.actual + '.'); +It's extremely easy to create new matchers for your app. A matcher function receives the actual value as `this.actual`, and zero or more arguments may be passed in the function call. The function should return `true` if the actual value passes the matcher's requirements, and `false` if it does not. + +Here's the definition of `toBeLessThan()`: + + toBeLessThan: function(expected) { + return this.actual < expected; }; -Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests. +To add the matcher to your suite, call `this.addMatchers()` from within a `before` or `it` block. Call it with an object mapping matcher name to function: + + beforeEach(function() { + this.addMatchers({ + toBeVisible: function() { return this.actual.isVisible(); } + }); + }); ### Asynchronous Specs From f1f5d8de7de18ef46f3b6d5065ea7919b3be3a99 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Sat, 20 Feb 2010 14:45:40 -0500 Subject: [PATCH 18/29] GitHub's markdown previewer LIES! --- README.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.markdown b/README.markdown index 832647e..812f979 100644 --- a/README.markdown +++ b/README.markdown @@ -99,11 +99,17 @@ Results of the expectations are logged for later for reporting. Jasmine has several built-in matchers. Here are a few: >`expect(x).toEqual(y);` compares objects or primitives `x` and `y` and passes if they are equivalent +> >`expect(x).toMatch(pattern);` compares `x` to string or regular expression `pattern` and passes if they match +> >`expect(x).toBeDefined();` passes if `x` is not `undefined` +> >`expect(x).toBeNull();` passes if `x` is not `null` +> >`expect(x).toBeTruthy();` passes if `x` evaluates to true +> >`expect(x).toBeFalsy();` passes if `x` evaluates to false +> >`expect(x).toContain(y);` passes if array or string `x` contains `y` #### Writing New Matchers From aef78b1ef1c05dcfb93373f12c56f72c7216d5f9 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Sat, 20 Feb 2010 14:46:26 -0500 Subject: [PATCH 19/29] MORE MARKDOWN LIES!!! --- README.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index 812f979..7086021 100644 --- a/README.markdown +++ b/README.markdown @@ -120,17 +120,17 @@ It's extremely easy to create new matchers for your app. A matcher function rece Here's the definition of `toBeLessThan()`: - toBeLessThan: function(expected) { - return this.actual < expected; - }; + toBeLessThan: function(expected) { + return this.actual < expected; + }; To add the matcher to your suite, call `this.addMatchers()` from within a `before` or `it` block. Call it with an object mapping matcher name to function: - beforeEach(function() { - this.addMatchers({ - toBeVisible: function() { return this.actual.isVisible(); } + beforeEach(function() { + this.addMatchers({ + toBeVisible: function() { return this.actual.isVisible(); } + }); }); - }); ### Asynchronous Specs From 5e3eb884ca82749abd058e03da644df487589d15 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Wed, 24 Feb 2010 19:27:43 -0800 Subject: [PATCH 20/29] Fix message bug with wasCalledWith. Throw on bad arguments to createSpyObj --- geminstaller.yml | 4 +-- lib/jasmine-0.10.0.js | 24 ++++++++++------- spec/suites/MatchersSpec.js | 52 +++++++++++++++++++++++++++++++++++-- spec/suites/SpySpec.js | 24 +++++++++++++---- src/Matchers.js | 15 ++++++----- src/base.js | 7 +++-- 6 files changed, 98 insertions(+), 28 deletions(-) diff --git a/geminstaller.yml b/geminstaller.yml index 56267f2..d343360 100644 --- a/geminstaller.yml +++ b/geminstaller.yml @@ -7,7 +7,7 @@ gems: - name: json version: 1.1.9 - name: selenium-rc - version: 2.1.0 + version: 2.2.0 - name: rack version: 1.0.0 - name: thin @@ -17,7 +17,7 @@ gems: - name: rspec version: 1.2.9 - name: selenium-client - version: 1.2.17 + version: 1.2.18 - name: rest-client version: 1.0.3 - name: saucelabs-adapter diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 31e25e4..165446d 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -15,7 +15,7 @@ jasmine.unimplementedMethod_ = function() { /** * Use jasmine.undefined instead of undefined, since undefinedjasmine.undefined instead of undefined, since undefined Date: Wed, 24 Feb 2010 19:35:32 -0800 Subject: [PATCH 21/29] Update isArray_ function and add test coverage --- lib/jasmine-0.10.0.js | 8 ++------ spec/suites/UtilSpec.js | 17 +++++++++++++++++ src/base.js | 6 +----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index 165446d..99178a9 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -89,11 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return value && - typeof value === 'object' && - typeof value.length === 'number' && - typeof value.splice === 'function' && - !(value.propertyIsEnumerable('length')); + return Object.prototype.toString.apply(value) === '[object Array]'; }; /** @@ -2261,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1267068340 + "revision": 1267068885 }; diff --git a/spec/suites/UtilSpec.js b/spec/suites/UtilSpec.js index 6731034..93f503a 100644 --- a/spec/suites/UtilSpec.js +++ b/spec/suites/UtilSpec.js @@ -20,4 +20,21 @@ describe("jasmine.util", function() { expect(destination).toEqual({foo: null}); }); }); + + describe("isArray_", function() { + it("should return true if the argument is an array", function() { + expect(jasmine.isArray_([])).toBe(true); + expect(jasmine.isArray_(['a'])).toBe(true); + expect(jasmine.isArray_(new Array())).toBe(true); + }); + + it("should return false if the argument is not an array", function() { + expect(jasmine.isArray_(undefined)).toBe(false); + expect(jasmine.isArray_({})).toBe(false); + expect(jasmine.isArray_(function() {})).toBe(false); + expect(jasmine.isArray_('foo')).toBe(false); + expect(jasmine.isArray_(5)).toBe(false); + expect(jasmine.isArray_(null)).toBe(false); + }); + }); }); diff --git a/src/base.js b/src/base.js index a13a676..fc4837b 100755 --- a/src/base.js +++ b/src/base.js @@ -89,11 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return value && - typeof value === 'object' && - typeof value.length === 'number' && - typeof value.splice === 'function' && - !(value.propertyIsEnumerable('length')); + return Object.prototype.toString.apply(value) === '[object Array]'; }; /** From 80d67d49a0a93a3de53c92f6264b7313aafeb3b8 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Wed, 24 Feb 2010 19:45:30 -0800 Subject: [PATCH 22/29] Bump version to 0.10.1 --- examples/html/example_runner.html | 2 +- lib/{jasmine-0.10.0.js => jasmine-0.10.1.js} | 4 ++-- src/version.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename lib/{jasmine-0.10.0.js => jasmine-0.10.1.js} (99%) diff --git a/examples/html/example_runner.html b/examples/html/example_runner.html index 825ec2c..e400768 100644 --- a/examples/html/example_runner.html +++ b/examples/html/example_runner.html @@ -4,7 +4,7 @@ Jasmine Test Runner - + diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.1.js similarity index 99% rename from lib/jasmine-0.10.0.js rename to lib/jasmine-0.10.1.js index 99178a9..0f6c015 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.1.js @@ -2256,6 +2256,6 @@ window.clearInterval = function(timeoutKey) { jasmine.version_= { "major": 0, "minor": 10, - "build": 0, - "revision": 1267068885 + "build": 1, + "revision": 1267069453 }; diff --git a/src/version.json b/src/version.json index 13dde9c..a0d438c 100644 --- a/src/version.json +++ b/src/version.json @@ -1,5 +1,5 @@ { "major": 0, "minor": 10, - "build": 0 + "build": 1 } \ No newline at end of file From da49a0ce406b454d328a35c61788166fbeefb5f2 Mon Sep 17 00:00:00 2001 From: Rajan Agaskar Date: Wed, 24 Feb 2010 19:58:56 -0800 Subject: [PATCH 23/29] README update --- README.markdown | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index 7086021..ae49727 100644 --- a/README.markdown +++ b/README.markdown @@ -7,13 +7,7 @@ Quick Start ### Ruby Suite Running - sudo gem sources -a http://gems.github.com - sudo gem install geminstaller - git clone git://github.com/pivotal/jasmine.git - cd jasmine - sudo geminstaller - cd examples/ruby - rake jasmine_server + Please use the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby) to run suites in a ruby environment. open `http://localhost:8888/` in your favorite browser. From 0bb7f4bd6a64bbad6d5a751fbe827e7d0fb65b16 Mon Sep 17 00:00:00 2001 From: Rajan Agaskar Date: Wed, 24 Feb 2010 19:59:39 -0800 Subject: [PATCH 24/29] README update --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index ae49727..bd2dd4c 100644 --- a/README.markdown +++ b/README.markdown @@ -7,7 +7,7 @@ Quick Start ### Ruby Suite Running - Please use the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby) to run suites in a ruby environment. +Please use the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby) to run suites in a ruby environment. open `http://localhost:8888/` in your favorite browser. From f9426a008e255ba486cc9b2d13994168e2af40ae Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 25 Feb 2010 21:56:42 -0500 Subject: [PATCH 25/29] Update why-did-we-write-it sections. --- README.markdown | 247 +++++++++++++++++++++++++----------------------- 1 file changed, 127 insertions(+), 120 deletions(-) diff --git a/README.markdown b/README.markdown index bd2dd4c..f7699f6 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,6 @@ Jasmine ======= -**YET ANOTHER JavaScript testing framework** +**A JavaScript Testing Framework** Quick Start ---------- @@ -9,12 +9,10 @@ Quick Start Please use the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby) to run suites in a ruby environment. -open `http://localhost:8888/` in your favorite browser. - ### HTML Suite Running [Get the latest release from the downloads page](http://github.com/pivotal/jasmine/downloads) -open `example/example_runner.html` in your favorite browser +Open `example/example_runner.html` in your favorite browser. ### Automatic Suite Running (w/ Selenium) @@ -43,47 +41,57 @@ Pull Requests We welcome your contributions! Jasmine is currently maintained by Davis Frank ([infews](http://github.com/infews)), Rajan Agaskar ([ragaskar](http://github.com/ragaskar)), and Christian Williams ([Xian](http://github.com/Xian)). You can help us by removing all other recipients from your pull request. -Why Another Frickin' JS TDD/BDD Framework? +Why Another JavaScript TDD/BDD Framework? ----------- -There are some situations when you want to test-drive JavaScript, but you don't want to be bothered with or even have an explicit document. You have no DOM to work with and thus lack HTML elements on which to hang event handlers. You may need to make asynchronous calls (say, to an AJAX API) and cannot mock/stub them. +There are some great JavaScript testing frameworks out there already, so why did we write another? -But you still need to write tests. +None of the existing frameworks quite worked the way we wanted. Many only work from within a browser. Most don't support testing asynchronous code like event callbacks. Some have syntax that's hard for JS developers or IDEs to understand. -What's an Agile Engineer to do? +So we decided to start from scratch. Enter Jasmine ------------ -Jasmine is yet another JavaScript testing framework. It's *heavily* influenced by JSSpec, ScrewUnit & [JSpec](http://github.com/visionmedia/jspec/tree/master), which are all influenced by RSpec. But each of those was lacking in some way: JSSpec & ScrewUnit require a DOM. JSpec's DOM-less assumption was a great start, but it needed asynchronous support. +Jasmine is our dream JavaScript testing framework. It's heavily influenced by, and borrows the best parts of, JSSpec, ScrewUnit & [JSpec](http://github.com/visionmedia/jspec/tree/master), and of course RSpec. -So we started over. And TDD'd a whole new framework. Enjoy. +Jasmine was designed with a few principles in mind. We believe that a good JavaScript testing framework: +* should not be tied to any browser, framework, platform, or host language. +* should have idiomatic and unsurprising syntax. +* should work anywhere JavaScript can run, including browsers, servers, phones, etc. +* shouldn't intrude in your application's territory (e.g. by cluttering the global namespace). +* should play well with IDEs (e.g. test code should pass static analysis). + +Some of our goals while writing Jasmine: +* it should encourage good testing practices. +* it should integrate easily with continuous build systems. +* it should be simple to get started with. + +The result is Jasmine, and we love test-driving our code with it. Enjoy. How To ------ -There is a nice example of how to use Jasmine in the /example directory. But here's more information. - -Exciting changes are afoot and many syntax changes have been made to make Jasmine more usable. Please read the examples below for updates. +There is a simple example of how to use Jasmine in the /example directory. But here's more information. ### Specs Each spec is, naturally, a JavaScript function. You tell Jasmine about this spec with a call to `it()` with a string and the function. The string is a description that will be helpful to you when reading a report. it('should be a test', function () { - var foo = 0 + var foo = 0; foo++; }); ### Expectations -Within your spec you will want/need to make expectations. These are made with the `expect()` funciton and expectation matchers. like this: +Within your spec you will want to express expectations about the behavior of your application code. These are made with the `expect()` function and expectation matchers, like this: it('should be a test', function () { - var foo = 0 - foo++; + var foo = 0; // set up the world + foo++; // call your application code - expect(foo).toEqual(1); + expect(foo).toEqual(1); // passes because foo == 1 }); Results of the expectations are logged for later for reporting. @@ -126,104 +134,6 @@ To add the matcher to your suite, call `this.addMatchers()` from within a `befor }); }); -### Asynchronous Specs - -You may be thinking, "That's all well and good, but you mentioned something about asynchronous tests." - -Well, say you need to make a call that is asynchronous - an AJAX API, or some other JavaScript library. That is, the call returns immediately, yet you want to make expectations 'at some point in the future' after some magic happens in the background. - -Jasmine allows you to do this with `runs()` and `waits()` blocks. - -`runs()` blocks by themselves simply run as if they were called directly. The following snippets of code should provide similar results: - - it('should be a test', function () { - var foo = 0 - foo++; - - expect(foo).toEqual(1); - }); - -and - - it('should be a test', function () { - runs( function () { - var foo = 0 - foo++; - - expect(foo).toEqual(1); - }); - }); - -multiple `runs()` blocks in a spec will run serially. For example, - - it('should be a test', function () { - runs( function () { - var foo = 0 - foo++; - - expect(foo).toEqual(1); - }); - runs( function () { - var bar = 0 - bar++; - - expect(bar).toEqual(1); - }); - }); - -`runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not! - - it('should be a test', function () { - runs( function () { - this.foo = 0 - this.foo++; - var bar = 0; - bar++; - - expect(this.foo).toEqual(1); - expect(bar).toEqual(1); - }); - runs( function () { - this.foo++; - var bar = 0 - bar++; - - expect(foo).toEqual(2); - expect(bar).toEqual(1); - }); - }); - -`runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive -timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example: - - it('should be a test', function () { - runs(function () { - this.foo = 0; - var that = this; - setTimeout(function () { - that.foo++; - }, 250); - }); - - runs(function () { - this.expects(this.foo).toEqual(0); - }); - - waits(500); - - runs(function () { - this.expects(this.foo).toEqual(1); - }); - }); - -What's happening here? - -* The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`. -* The second `runs()` is executed immediately and then verifies that `this.foo` was indeed initialized to zero in the previous `runs()`. -* Then we wait for half a second. -* Then the last call to `runs()` expects that `this.foo` was incremented by the `setTimeout`. - - ### Suites Specs are grouped in Suites. Suites are defined using the global `describe()` function: @@ -425,13 +335,13 @@ Spies can be very useful for testing AJAX or other asynchronous behaviors that t There are spy-specfic matchers that are very handy. -`wasCalled()` returns true if the object is a spy and was called +`wasCalled()` passes if the object is a spy and was called -`wasCalledWith(arguments)` returns true if the object is a spy and was called with the passed arguments +`wasCalledWith(arguments)` passes if the object is a spy and was called with the passed arguments -`wasNotCalled()` returns true if the object is a spy and was not called +`wasNotCalled()` passes if the object is a spy and was not called -`wasNotCalledWith(arguments)` returns true if the object is a spy and was not called with the passed arguments +`wasNotCalledWith(arguments)` passes if the object is a spy and was not called with the passed arguments Spies can be trained to respond in a variety of ways when invoked: @@ -457,6 +367,103 @@ Spies are automatically removed after each spec. They may be set in the beforeEa Specs may be disabled by calling `xit()` instead of `it()`. Suites may be disabled by calling `xdescribe()` instead of `describe()`. A simple find/replace in your editor of choice will allow you to run a subset of your specs. +### Asynchronous Specs + +You may be thinking, "That's all very nice, but what's this about asynchronous tests?" + +Well, say you need to make a call that is asynchronous - an AJAX API, event callback, or some other JavaScript library. That is, the call returns immediately, yet you want to make expectations 'at some point in the future' after some magic happens in the background. + +Jasmine allows you to do this with `runs()` and `waits()` blocks. + +`runs()` blocks by themselves simply run as if they were called directly. The following snippets of code should provide similar results: + + it('should be a test', function () { + var foo = 0 + foo++; + + expect(foo).toEqual(1); + }); + +and + + it('should be a test', function () { + runs( function () { + var foo = 0 + foo++; + + expect(foo).toEqual(1); + }); + }); + +multiple `runs()` blocks in a spec will run serially. For example, + + it('should be a test', function () { + runs( function () { + var foo = 0 + foo++; + + expect(foo).toEqual(1); + }); + runs( function () { + var bar = 0 + bar++; + + expect(bar).toEqual(1); + }); + }); + +`runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not! + + it('should be a test', function () { + runs( function () { + this.foo = 0 + this.foo++; + var bar = 0; + bar++; + + expect(this.foo).toEqual(1); + expect(bar).toEqual(1); + }); + runs( function () { + this.foo++; + var bar = 0 + bar++; + + expect(foo).toEqual(2); + expect(bar).toEqual(1); + }); + }); + +`runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive +timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example: + + it('should be a test', function () { + runs(function () { + this.foo = 0; + var that = this; + setTimeout(function () { + that.foo++; + }, 250); + }); + + runs(function () { + this.expects(this.foo).toEqual(0); + }); + + waits(500); + + runs(function () { + this.expects(this.foo).toEqual(1); + }); + }); + +What's happening here? + +* The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`. +* The second `runs()` is executed immediately and then verifies that `this.foo` was indeed initialized to zero in the previous `runs()`. +* Then we wait for half a second. +* Then the last call to `runs()` expects that `this.foo` was incremented by the `setTimeout`. + ## Support We now have a Google Group for support & discussion. From 5a7eea53b16f28f775864b0fec09ed3469b50ce8 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 25 Feb 2010 21:58:08 -0500 Subject: [PATCH 26/29] Update why-did-we-write-it sections. --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f7699f6..bade429 100644 --- a/README.markdown +++ b/README.markdown @@ -53,7 +53,7 @@ So we decided to start from scratch. Enter Jasmine ------------ -Jasmine is our dream JavaScript testing framework. It's heavily influenced by, and borrows the best parts of, JSSpec, ScrewUnit & [JSpec](http://github.com/visionmedia/jspec/tree/master), and of course RSpec. +Jasmine is our dream JavaScript testing framework. It's heavily influenced by, and borrows the best parts of, ScrewUnit, JSSpec, [JSpec](http://github.com/visionmedia/jspec/tree/master), and of course RSpec. Jasmine was designed with a few principles in mind. We believe that a good JavaScript testing framework: * should not be tied to any browser, framework, platform, or host language. From e1b3ca4066b3728836b4be07c8dbe18bc8ccb3d5 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 25 Feb 2010 22:01:25 -0500 Subject: [PATCH 27/29] Update spy expectation docs. --- README.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index bade429..11bb14f 100644 --- a/README.markdown +++ b/README.markdown @@ -335,23 +335,23 @@ Spies can be very useful for testing AJAX or other asynchronous behaviors that t There are spy-specfic matchers that are very handy. -`wasCalled()` passes if the object is a spy and was called +`expect(x).wasCalled()` passes if `x` is a spy and was called -`wasCalledWith(arguments)` passes if the object is a spy and was called with the passed arguments +`expect(x).wasCalledWith(arguments)` passes if `x` is a spy and was called with the specified arguments -`wasNotCalled()` passes if the object is a spy and was not called +`expect(x).wasNotCalled()` passes if `x` is a spy and was not called -`wasNotCalledWith(arguments)` passes if the object is a spy and was not called with the passed arguments +`expect(x).wasNotCalledWith(arguments)` passes if `x` is a spy and was not called with the specified arguments Spies can be trained to respond in a variety of ways when invoked: -`andCallThrough()`: spies on AND calls the original function spied on +`spyOn(x, 'method').andCallThrough()`: spies on AND calls the original function spied on -`andReturn(arguments)`: returns passed arguments when spy is called +`spyOn(x, 'method').andReturn(arguments)`: returns passed arguments when spy is called -`andThrow(exception)`: throws passed exception when spy is called +`spyOn(x, 'method').andThrow(exception)`: throws passed exception when spy is called -`andCallFake(function)`: calls passed function when spy is called +`spyOn(x, 'method').andCallFake(function)`: calls passed function when spy is called Spies have some useful properties: From fcfe23d51691ac354f87d48f490c356e725bda66 Mon Sep 17 00:00:00 2001 From: Erik Hanson Date: Fri, 26 Feb 2010 11:42:38 -0800 Subject: [PATCH 28/29] fixed a couple Markdown formatting issues --- README.markdown | 92 +++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/README.markdown b/README.markdown index 11bb14f..bdc4943 100644 --- a/README.markdown +++ b/README.markdown @@ -56,6 +56,7 @@ Enter Jasmine Jasmine is our dream JavaScript testing framework. It's heavily influenced by, and borrows the best parts of, ScrewUnit, JSSpec, [JSpec](http://github.com/visionmedia/jspec/tree/master), and of course RSpec. Jasmine was designed with a few principles in mind. We believe that a good JavaScript testing framework: + * should not be tied to any browser, framework, platform, or host language. * should have idiomatic and unsurprising syntax. * should work anywhere JavaScript can run, including browsers, servers, phones, etc. @@ -63,6 +64,7 @@ Jasmine was designed with a few principles in mind. We believe that a good JavaS * should play well with IDEs (e.g. test code should pass static analysis). Some of our goals while writing Jasmine: + * it should encourage good testing practices. * it should integrate easily with continuous build systems. * it should be simple to get started with. @@ -138,34 +140,34 @@ To add the matcher to your suite, call `this.addMatchers()` from within a `befor Specs are grouped in Suites. Suites are defined using the global `describe()` function: - describe('One suite', function () { - it('has a test', function () { - ... + describe('One suite', function () { + it('has a test', function () { + ... + }); + + it('has another test', function () { + ... + }); }); - it('has another test', function () { - ... - }); - }); - The Suite name is so that reporting is more descriptive. Suites are executed in the order in which `describe()` calls are made, usually in the order in which their script files are included. Additionally, specs within a suite share a functional scope. So you may declare variables inside a describe block and they are accessible from within your specs. For example: - describe('A suite with some variables', function () { - var bar = 0 - - it('has a test', function () { - bar++; - expect(bar).toEqual(1); + describe('A suite with some variables', function () { + var bar = 0 + + it('has a test', function () { + bar++; + expect(bar).toEqual(1); + }); + + it('has another test', function () { + bar++; + expect(bar).toEqual(2); + }); }); - it('has another test', function () { - bar++; - expect(bar).toEqual(2); - }); - }); - #### beforeEach A suite can have a beforeEach declaration. It takes a function that is run before each spec. For example: @@ -249,26 +251,26 @@ A runner can also have an afterEach declarations. Runner afterEach functions are Jasmine supports nested describes. An example: describe('some suite', function () { - + var suiteWideFoo; - + beforeEach(function () { suiteWideFoo = 0; }); - + describe('some nested suite', function() { var nestedSuiteBar; beforeEach(function() { nestedSuiteBar=1; }); - + it('nested expectation', function () { expect(suiteWideFoo).toEqual(0); expect(nestedSuiteBar).toEqual(1); }); - + }); - + it('top-level describe', function () { expect(suiteWideFoo).toEqual(0); expect(nestedSuiteBar).toEqual(undefined); @@ -414,7 +416,7 @@ multiple `runs()` blocks in a spec will run serially. For example, `runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not! - it('should be a test', function () { + it('should be a test', function () { runs( function () { this.foo = 0 this.foo++; @@ -437,26 +439,26 @@ multiple `runs()` blocks in a spec will run serially. For example, `runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example: - it('should be a test', function () { - runs(function () { - this.foo = 0; - var that = this; - setTimeout(function () { - that.foo++; - }, 250); + it('should be a test', function () { + runs(function () { + this.foo = 0; + var that = this; + setTimeout(function () { + that.foo++; + }, 250); + }); + + runs(function () { + this.expects(this.foo).toEqual(0); + }); + + waits(500); + + runs(function () { + this.expects(this.foo).toEqual(1); + }); }); - runs(function () { - this.expects(this.foo).toEqual(0); - }); - - waits(500); - - runs(function () { - this.expects(this.foo).toEqual(1); - }); - }); - What's happening here? * The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`. From 99bcfdcd0d24538afc4597507518092ad290bacb Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Sat, 27 Feb 2010 11:37:53 -0500 Subject: [PATCH 29/29] Spec cleanup. --- spec/suites/EnvSpec.js | 5 +---- spec/suites/RunnerSpec.js | 6 ------ 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/spec/suites/EnvSpec.js b/spec/suites/EnvSpec.js index a0f2032..7da6ee0 100644 --- a/spec/suites/EnvSpec.js +++ b/spec/suites/EnvSpec.js @@ -6,14 +6,13 @@ describe("jasmine.Env", function() { }); describe('ids', function () { - it('nextSpecId should return consecutive integers, starting at 0', function () { expect(env.nextSpecId()).toEqual(0); expect(env.nextSpecId()).toEqual(1); expect(env.nextSpecId()).toEqual(2); }); - }); + describe("reporting", function() { var fakeReporter; @@ -42,7 +41,6 @@ describe("jasmine.Env", function() { exception = e; } expect(exception.message).toEqual('Version not set'); - }); it("version should return the current version as an int", function() { @@ -58,7 +56,6 @@ describe("jasmine.Env", function() { "build": 7, "revision": 8 }); - }); }); diff --git a/spec/suites/RunnerSpec.js b/spec/suites/RunnerSpec.js index 1d28ad2..59b1b56 100644 --- a/spec/suites/RunnerSpec.js +++ b/spec/suites/RunnerSpec.js @@ -217,8 +217,6 @@ describe('RunnerTest', function() { expect(fakeReporter.reportRunnerResults).wasCalled(); expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner().results()); }); - - }); it("should report when the tests start running", function() { @@ -235,7 +233,6 @@ describe('RunnerTest', function() { var reportedRunner = fakeReporter.reportRunnerStarting.mostRecentCall.args[0]; expect(reportedRunner.arbitraryVariable).toEqual('foo'); expect(runner.queue.start).wasCalled(); - }); it("should return a flat array of all suites, including nested suites", function() { @@ -245,8 +242,6 @@ describe('RunnerTest', function() { }); }); - document.runner = env.currentRunner(); - var suites = env.currentRunner().suites(); var suiteDescriptions = []; for (var i = 0; i < suites.length; i++) { @@ -254,5 +249,4 @@ describe('RunnerTest', function() { } expect(suiteDescriptions).toEqual([suite1.getFullName(), suite2.getFullName()]); }); - }); \ No newline at end of file