From c533b67aa55ccf1211c9337ae6d2c4c39dc3c6f2 Mon Sep 17 00:00:00 2001 From: Lee Byrd & Christian Williams Date: Fri, 25 Jun 2010 15:16:43 -0700 Subject: [PATCH] Remove vestiges of ruby ci code from jasmine core. Add missing lib/jasmine-html.js. --- .gitignore | 4 +- Rakefile | 64 +- doc/files.html | 26 +- 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 | 114 ++- doc/symbols/jasmine.MultiReporter.html | 2 +- doc/symbols/jasmine.NestedResults.html | 2 +- doc/symbols/jasmine.Reporter.html | 47 +- doc/symbols/jasmine.Runner.html | 2 +- doc/symbols/jasmine.Spec.html | 2 +- doc/symbols/jasmine.Spy.html | 9 +- doc/symbols/jasmine.Suite.html | 2 +- doc/symbols/jasmine.html | 6 +- doc/symbols/jasmine.util.html | 2 +- doc/symbols/src/src_Matchers.js.html | 322 +++---- doc/symbols/src/src_MultiReporter.js.html | 39 +- doc/symbols/src/src_Reporter.js.html | 10 +- doc/symbols/src/src_Reporters.js.html | 51 -- doc/symbols/src/src_Spec.js.html | 149 ++-- doc/symbols/src/src_base.js.html | 787 +++++++++--------- ....html => src_html_TrivialReporter.js.html} | 351 ++++---- doc/symbols/src/src_mock-timeout.js.html | 119 ++- lib/jasmine-html.js | 182 ++++ lib/jasmine.js | 2 +- spec/jasmine_helper.rb | 44 - spec/jasmine_spec.rb | 31 - 31 files changed, 1276 insertions(+), 1105 deletions(-) delete mode 100644 doc/symbols/src/src_Reporters.js.html rename doc/symbols/src/{lib_TrivialReporter.js.html => src_html_TrivialReporter.js.html} (84%) create mode 100644 lib/jasmine-html.js delete mode 100755 spec/jasmine_helper.rb delete mode 100644 spec/jasmine_spec.rb diff --git a/.gitignore b/.gitignore index 35f4062..0345637 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea/ .svn/ -lib/jasmine-*.js -dist/ \ No newline at end of file +dist/ +.DS_Store diff --git a/Rakefile b/Rakefile index f29053e..b902ece 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,3 @@ -require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper.rb")) - def jasmine_sources sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"] sources += Dir.glob('src/*.js').reject { |f| f == 'src/base.js' || sources.include?(f) }.sort @@ -10,10 +8,6 @@ def jasmine_html_sources ["src/html/TrivialReporter.js"] end -def jasmine_filename - "jasmine-#{jasmine_version}.js" -end - def jasmine_version "#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}" end @@ -23,19 +17,6 @@ def version_hash @version ||= JSON.parse(File.new("src/version.json").read); end -def start_jasmine_server(jasmine_includes = nil) - require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) - - puts "your tests are here:" - puts " http://localhost:8888/run.html" - - Jasmine::SimpleServer.start( - 8888, - lambda { JasmineHelper.specs }, - JasmineHelper.dir_mappings, - :jasmine_files => jasmine_includes) -end - task :default => 'jasmine:dist' def substitute_jasmine_version(filename) @@ -133,7 +114,7 @@ jasmine.version_= { FileUtils.rm_r temp_dir if File.exists?(temp_dir) Dir.mkdir(temp_dir) - root = JasmineHelper.jasmine_root + root = File.expand_path(File.dirname(__FILE__)) FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir) substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html")) @@ -154,47 +135,6 @@ jasmine.version_= { Dir.mkdir(dist_dir) exec "cd #{temp_dir} && zip -r #{zip_file_name} . -x .[a-zA-Z0-9]*" end - - - task :server do - files = jasmine_sources + jasmine_html_sources - jasmine_includes = lambda { - raw_jasmine_includes = files.collect { |f| File.expand_path(File.join(JasmineHelper.jasmine_root, f)) } - Jasmine.cachebust(raw_jasmine_includes).collect { |f| f.sub(JasmineHelper.jasmine_src_dir, "/src").sub(JasmineHelper.jasmine_lib_dir, "/lib") } - } - start_jasmine_server(jasmine_includes) - end - - task :server_build => 'jasmine:build' do - - start_jasmine_server - end - - namespace :test do - 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 - - 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 -task :jasmine => ['jasmine:server'] +task :jasmine => ['jasmine:dist'] diff --git a/doc/files.html b/doc/files.html index 7bb4757..52d1559 100644 --- a/doc/files.html +++ b/doc/files.html @@ -222,18 +222,6 @@ ul.inheritsList

File Index

-
-

lib/TrivialReporter.js

- -
- - - - -
-
-
-

src/base.js

@@ -266,6 +254,18 @@ ul.inheritsList + +
+
+ +
+

src/html/TrivialReporter.js

+ +
+ + + +

@@ -442,7 +442,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:45 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:14 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index bfa48e6..d50e8f8 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 Jun 23 2010 11:30:45 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:14 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index e060d47..4aff986 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -1116,7 +1116,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:12 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 6aac00a..a71e7cc 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 Jun 23 2010 11:30:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:12 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Clock.html b/doc/symbols/jasmine.Clock.html index 19cccaf..ce0fdf9 100644 --- a/doc/symbols/jasmine.Clock.html +++ b/doc/symbols/jasmine.Clock.html @@ -706,7 +706,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:12 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index ed1f914..25ccf3b 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -1204,7 +1204,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 4faebf4..b28efa9 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 Jun 23 2010 11:30:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Matchers.html b/doc/symbols/jasmine.Matchers.html index a8adefd..ba37f7f 100644 --- a/doc/symbols/jasmine.Matchers.html +++ b/doc/symbols/jasmine.Matchers.html @@ -418,6 +418,24 @@ ul.inheritsList + +   + +
toHaveBeenCalled() +
+
Matcher that checks to see if the actual, a Jasmine spy, was called.
+ + + + +   + +
toHaveBeenCalledWith() +
+
Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
+ + +   @@ -477,7 +495,7 @@ ul.inheritsList
wasCalled()
-
Matcher that checks to see if the actual, a Jasmine spy, was called.
+
@@ -486,7 +504,7 @@ ul.inheritsList
wasCalledWith()
-
Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
+
@@ -1084,6 +1102,60 @@ ul.inheritsList +
+ + +
+ + + toHaveBeenCalled() + +
+
+ Matcher that checks to see if the actual, a Jasmine spy, was called. + + +
+ + + + + + + + + + + +
+ + +
+ + + toHaveBeenCalledWith() + +
+
+ Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. + + +
+ + + +

+					
+					
+					
+						
+						
+						
+						
+						
+						
+						
+
 					
@@ -1311,7 +1383,7 @@ a pattern or a String.
- Matcher that checks to see if the actual, a Jasmine spy, was called. +
@@ -1320,6 +1392,13 @@ a pattern or a String. +
+
Deprecated:
+
+ Use expect(xxx).toHaveBeenCalled() instead +
+
+ @@ -1336,19 +1415,22 @@ a pattern or a String.
- Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. +
-

-					
-					
-					
 						
 						
+							
+
Deprecated:
+
+ Use expect(xxx).toHaveBeenCalledWith() instead +
+
+ @@ -1374,6 +1456,13 @@ a pattern or a String. +
+
Deprecated:
+
+ Use expect(xxx).not.toHaveBeenCalled() instead +
+
+ @@ -1399,6 +1488,13 @@ a pattern or a String. +
+
Deprecated:
+
+ Use expect(xxx).not.toHaveBeenCalledWith() instead +
+
+ @@ -1461,7 +1557,7 @@ a pattern or a String.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 6a7fa1c..79ff846 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 Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index 6a5e543..1f464d5 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 Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 7bb601b..fe7470b 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -319,6 +319,15 @@ ul.inheritsList + +   + +
reportSpecStarting(spec) +
+
+ + +   @@ -518,6 +527,42 @@ ul.inheritsList +
+ + +
+ + + reportSpecStarting(spec) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ spec + +
+
+ +
+ + + + + + + +
@@ -568,7 +613,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index 01c3fa5..5070e76 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -738,7 +738,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:13 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index f4c5f43..0a87f3a 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -1204,7 +1204,7 @@ Be careful not to leave calls to jasmine.log in production code.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:14 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index e377cbe..66e158c 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -421,7 +421,8 @@ ul.inheritsList Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine expectation syntax. Spies can be checked if they were called or not and what the calling params were. -A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) +A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). + Spies are torn down at the end of every spec. Note: Do not call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. @@ -454,8 +455,8 @@ spyOn(foo, 'not').andCallFake(function(value) {return value;}); // mock example foo.not(7 == 7); -expect(foo.not).wasCalled(); -expect(foo.not).wasCalledWith(true); +expect(foo.not).toHaveBeenCalled(); +expect(foo.not).toHaveBeenCalledWith(true); @@ -849,7 +850,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:14 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index 958809b..18104b3 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -767,7 +767,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:45 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:14 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index b711d5a..2ff70be 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -564,7 +564,7 @@ ul.inheritsList
// don't care about which function is passed in, as long as it's a function
-expect(mySpy).wasCalledWith(jasmine.any(Function));
+expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); @@ -1087,7 +1087,7 @@ Be careful not to leave calls to jasmine.log in production code.
- Defined in: TrivialReporter.js. + Defined in: TrivialReporter.js. @@ -1241,7 +1241,7 @@ Be careful not to leave calls to jasmine.log in production code.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Jun 23 2010 11:30:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:12 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index 38ea3a8..07ac66a 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 Jun 23 2010 11:30:45 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 15:15:14 GMT-0700 (PDT)
diff --git a/doc/symbols/src/src_Matchers.js.html b/doc/symbols/src/src_Matchers.js.html index 9d5d958..62d2fd7 100644 --- a/doc/symbols/src/src_Matchers.js.html +++ b/doc/symbols/src/src_Matchers.js.html @@ -169,162 +169,176 @@ 162 return !this.actual; 163 }; 164 -165 /** -166 * Matcher that checks to see if the actual, a Jasmine spy, was called. -167 */ -168 jasmine.Matchers.prototype.wasCalled = function() { -169 if (arguments.length > 0) { -170 throw new Error('wasCalled does not take arguments, use wasCalledWith'); -171 } -172 -173 if (!jasmine.isSpy(this.actual)) { -174 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -175 } -176 -177 this.message = function() { -178 return "Expected spy " + this.actual.identity + " to have been called."; -179 }; -180 -181 return this.actual.wasCalled; -182 }; -183 -184 /** -185 * Matcher that checks to see if the actual, a Jasmine spy, was not called. -186 */ -187 jasmine.Matchers.prototype.wasNotCalled = function() { -188 if (arguments.length > 0) { -189 throw new Error('wasNotCalled does not take arguments'); -190 } -191 -192 if (!jasmine.isSpy(this.actual)) { -193 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -194 } -195 -196 this.message = function() { -197 return "Expected spy " + this.actual.identity + " to not have been called."; -198 }; +165 +166 /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */ +167 jasmine.Matchers.prototype.wasCalled = function() { +168 return this.toHaveBeenCalled(); +169 }; +170 +171 /** +172 * Matcher that checks to see if the actual, a Jasmine spy, was called. +173 */ +174 jasmine.Matchers.prototype.toHaveBeenCalled = function() { +175 if (arguments.length > 0) { +176 throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); +177 } +178 +179 if (!jasmine.isSpy(this.actual)) { +180 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +181 } +182 +183 this.message = function() { +184 return "Expected spy " + this.actual.identity + " to have been called."; +185 }; +186 +187 return this.actual.wasCalled; +188 }; +189 +190 /** +191 * Matcher that checks to see if the actual, a Jasmine spy, was not called. +192 * +193 * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead +194 */ +195 jasmine.Matchers.prototype.wasNotCalled = function() { +196 if (arguments.length > 0) { +197 throw new Error('wasNotCalled does not take arguments'); +198 } 199 -200 return !this.actual.wasCalled; -201 }; -202 -203 /** -204 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. -205 * -206 * @example -207 * -208 */ -209 jasmine.Matchers.prototype.wasCalledWith = function() { -210 var expectedArgs = jasmine.util.argsToArray(arguments); -211 if (!jasmine.isSpy(this.actual)) { -212 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -213 } -214 this.message = function() { -215 if (this.actual.callCount == 0) { -216 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; -217 } else { -218 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); -219 } -220 }; -221 -222 return this.env.contains_(this.actual.argsForCall, expectedArgs); -223 }; -224 -225 jasmine.Matchers.prototype.wasNotCalledWith = function() { -226 var expectedArgs = jasmine.util.argsToArray(arguments); -227 if (!jasmine.isSpy(this.actual)) { -228 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -229 } -230 -231 this.message = function() { -232 return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; +200 if (!jasmine.isSpy(this.actual)) { +201 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +202 } +203 +204 this.message = function() { +205 return "Expected spy " + this.actual.identity + " to not have been called."; +206 }; +207 +208 return !this.actual.wasCalled; +209 }; +210 +211 /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */ +212 jasmine.Matchers.prototype.wasCalledWith = function() { +213 return this.toHaveBeenCalledWith.apply(this, arguments); +214 }; +215 +216 /** +217 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. +218 * +219 * @example +220 * +221 */ +222 jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { +223 var expectedArgs = jasmine.util.argsToArray(arguments); +224 if (!jasmine.isSpy(this.actual)) { +225 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +226 } +227 this.message = function() { +228 if (this.actual.callCount == 0) { +229 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; +230 } else { +231 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); +232 } 233 }; 234 -235 return !this.env.contains_(this.actual.argsForCall, expectedArgs); +235 return this.env.contains_(this.actual.argsForCall, expectedArgs); 236 }; 237 -238 /** -239 * Matcher that checks that the expected item is an element in the actual Array. -240 * -241 * @param {Object} expected -242 */ -243 jasmine.Matchers.prototype.toContain = function(expected) { -244 return this.env.contains_(this.actual, expected); -245 }; -246 -247 /** -248 * Matcher that checks that the expected item is NOT an element in the actual Array. -249 * -250 * @param {Object} expected -251 */ -252 jasmine.Matchers.prototype.toNotContain = function(expected) { -253 return !this.env.contains_(this.actual, expected); -254 }; -255 -256 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -257 return this.actual < expected; -258 }; -259 -260 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -261 return this.actual > expected; -262 }; -263 -264 /** -265 * Matcher that checks that the expected exception was thrown by the actual. -266 * -267 * @param {String} expected -268 */ -269 jasmine.Matchers.prototype.toThrow = function(expected) { -270 var result = false; -271 var exception; -272 if (typeof this.actual != 'function') { -273 throw new Error('Actual is not a function'); -274 } -275 try { -276 this.actual(); -277 } catch (e) { -278 exception = e; -279 } -280 if (exception) { -281 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); -282 } -283 -284 this.message = function() { -285 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -286 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); -287 } else { -288 return "Expected function to throw an exception."; -289 } -290 }; -291 -292 return result; -293 }; -294 -295 jasmine.Matchers.Any = function(expectedClass) { -296 this.expectedClass = expectedClass; -297 }; -298 -299 jasmine.Matchers.Any.prototype.matches = function(other) { -300 if (this.expectedClass == String) { -301 return typeof other == 'string' || other instanceof String; -302 } -303 -304 if (this.expectedClass == Number) { -305 return typeof other == 'number' || other instanceof Number; -306 } -307 -308 if (this.expectedClass == Function) { -309 return typeof other == 'function' || other instanceof Function; -310 } -311 -312 if (this.expectedClass == Object) { -313 return typeof other == 'object'; -314 } -315 -316 return other instanceof this.expectedClass; -317 }; -318 -319 jasmine.Matchers.Any.prototype.toString = function() { -320 return '<jasmine.any(' + this.expectedClass + ')>'; -321 }; -322 -323 \ No newline at end of file +238 /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */ +239 jasmine.Matchers.prototype.wasNotCalledWith = function() { +240 var expectedArgs = jasmine.util.argsToArray(arguments); +241 if (!jasmine.isSpy(this.actual)) { +242 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +243 } +244 +245 this.message = function() { +246 return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; +247 }; +248 +249 return !this.env.contains_(this.actual.argsForCall, expectedArgs); +250 }; +251 +252 /** +253 * Matcher that checks that the expected item is an element in the actual Array. +254 * +255 * @param {Object} expected +256 */ +257 jasmine.Matchers.prototype.toContain = function(expected) { +258 return this.env.contains_(this.actual, expected); +259 }; +260 +261 /** +262 * Matcher that checks that the expected item is NOT an element in the actual Array. +263 * +264 * @param {Object} expected +265 */ +266 jasmine.Matchers.prototype.toNotContain = function(expected) { +267 return !this.env.contains_(this.actual, expected); +268 }; +269 +270 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +271 return this.actual < expected; +272 }; +273 +274 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +275 return this.actual > expected; +276 }; +277 +278 /** +279 * Matcher that checks that the expected exception was thrown by the actual. +280 * +281 * @param {String} expected +282 */ +283 jasmine.Matchers.prototype.toThrow = function(expected) { +284 var result = false; +285 var exception; +286 if (typeof this.actual != 'function') { +287 throw new Error('Actual is not a function'); +288 } +289 try { +290 this.actual(); +291 } catch (e) { +292 exception = e; +293 } +294 if (exception) { +295 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +296 } +297 +298 this.message = function() { +299 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { +300 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); +301 } else { +302 return "Expected function to throw an exception."; +303 } +304 }; +305 +306 return result; +307 }; +308 +309 jasmine.Matchers.Any = function(expectedClass) { +310 this.expectedClass = expectedClass; +311 }; +312 +313 jasmine.Matchers.Any.prototype.matches = function(other) { +314 if (this.expectedClass == String) { +315 return typeof other == 'string' || other instanceof String; +316 } +317 +318 if (this.expectedClass == Number) { +319 return typeof other == 'number' || other instanceof Number; +320 } +321 +322 if (this.expectedClass == Function) { +323 return typeof other == 'function' || other instanceof Function; +324 } +325 +326 if (this.expectedClass == Object) { +327 return typeof other == 'object'; +328 } +329 +330 return other instanceof this.expectedClass; +331 }; +332 +333 jasmine.Matchers.Any.prototype.toString = function() { +334 return '<jasmine.any(' + this.expectedClass + ')>'; +335 }; +336 +337 \ No newline at end of file diff --git a/doc/symbols/src/src_MultiReporter.js.html b/doc/symbols/src/src_MultiReporter.js.html index ddae087..2316cea 100644 --- a/doc/symbols/src/src_MultiReporter.js.html +++ b/doc/symbols/src/src_MultiReporter.js.html @@ -18,19 +18,26 @@ 11 }; 12 13 (function() { - 14 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; - 15 for (var i = 0; i < functionNames.length; i++) { - 16 var functionName = functionNames[i]; - 17 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { - 18 return function() { - 19 for (var j = 0; j < this.subReporters_.length; j++) { - 20 var subReporter = this.subReporters_[j]; - 21 if (subReporter[functionName]) { - 22 subReporter[functionName].apply(subReporter, arguments); - 23 } - 24 } - 25 }; - 26 })(functionName); - 27 } - 28 })(); - 29 \ No newline at end of file + 14 var functionNames = [ + 15 "reportRunnerStarting", + 16 "reportRunnerResults", + 17 "reportSuiteResults", + 18 "reportSpecStarting", + 19 "reportSpecResults", + 20 "log" + 21 ]; + 22 for (var i = 0; i < functionNames.length; i++) { + 23 var functionName = functionNames[i]; + 24 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { + 25 return function() { + 26 for (var j = 0; j < this.subReporters_.length; j++) { + 27 var subReporter = this.subReporters_[j]; + 28 if (subReporter[functionName]) { + 29 subReporter[functionName].apply(subReporter, arguments); + 30 } + 31 } + 32 }; + 33 })(functionName); + 34 } + 35 })(); + 36 \ No newline at end of file diff --git a/doc/symbols/src/src_Reporter.js.html b/doc/symbols/src/src_Reporter.js.html index 590a568..f5a65df 100644 --- a/doc/symbols/src/src_Reporter.js.html +++ b/doc/symbols/src/src_Reporter.js.html @@ -25,11 +25,15 @@ 18 }; 19 20 //noinspection JSUnusedLocalSymbols - 21 jasmine.Reporter.prototype.reportSpecResults = function(spec) { + 21 jasmine.Reporter.prototype.reportSpecStarting = function(spec) { 22 }; 23 24 //noinspection JSUnusedLocalSymbols - 25 jasmine.Reporter.prototype.log = function(str) { + 25 jasmine.Reporter.prototype.reportSpecResults = function(spec) { 26 }; 27 - 28 \ No newline at end of file + 28 //noinspection JSUnusedLocalSymbols + 29 jasmine.Reporter.prototype.log = function(str) { + 30 }; + 31 + 32 \ No newline at end of file diff --git a/doc/symbols/src/src_Reporters.js.html b/doc/symbols/src/src_Reporters.js.html deleted file mode 100644 index 9ed413c..0000000 --- a/doc/symbols/src/src_Reporters.js.html +++ /dev/null @@ -1,51 +0,0 @@ -
  1 /** JasmineReporters.reporter
-  2  *    Base object that will get called whenever a Spec, Suite, or Runner is done.  It is up to
-  3  *    descendants of this object to do something with the results (see json_reporter.js)
-  4  *
-  5  * @deprecated
-  6  */
-  7 jasmine.Reporters = {};
-  8 
-  9 /**
- 10  * @deprecated
- 11  * @param callbacks
- 12  */
- 13 jasmine.Reporters.reporter = function(callbacks) {
- 14   /**
- 15    * @deprecated
- 16    * @param callbacks
- 17    */
- 18   var that = {
- 19     callbacks: callbacks || {},
- 20 
- 21     doCallback: function(callback, results) {
- 22       if (callback) {
- 23         callback(results);
- 24       }
- 25     },
- 26 
- 27     reportRunnerResults: function(runner) {
- 28       that.doCallback(that.callbacks.runnerCallback, runner);
- 29     },
- 30     reportSuiteResults:  function(suite) {
- 31       that.doCallback(that.callbacks.suiteCallback, suite);
- 32     },
- 33     reportSpecResults:   function(spec) {
- 34       that.doCallback(that.callbacks.specCallback, spec);
- 35     },
- 36     log: function (str) {
- 37       if (console && console.log) console.log(str);
- 38     }
- 39   };
- 40 
- 41   return that;
- 42 };
- 43 
- 44 
\ 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 72f3a5c..bc8ef25 100644 --- a/doc/symbols/src/src_Spec.js.html +++ b/doc/symbols/src/src_Spec.js.html @@ -141,77 +141,78 @@ 134 spec.finish(onComplete); 135 return; 136 } -137 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); -138 -139 spec.env.currentSpec = spec; -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 var i; -151 -152 for (var suite = this.suite; suite; suite = suite.parentSuite) { -153 for (i = 0; i < suite.before_.length; i++) { -154 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -155 } -156 } -157 for (i = 0; i < runner.before_.length; i++) { -158 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -159 } -160 for (i = 0; i < this.afterCallbacks.length; i++) { -161 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -162 } -163 for (suite = this.suite; suite; suite = suite.parentSuite) { -164 for (i = 0; i < suite.after_.length; i++) { -165 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -166 } -167 } -168 for (i = 0; i < runner.after_.length; i++) { -169 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -170 } -171 }; -172 -173 jasmine.Spec.prototype.explodes = function() { -174 throw 'explodes function should not have been called'; -175 }; -176 -177 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -178 if (obj == jasmine.undefined) { -179 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -180 } -181 -182 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { -183 throw methodName + '() method does not exist'; -184 } -185 -186 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -187 throw new Error(methodName + ' has already been spied upon'); -188 } -189 -190 var spyObj = jasmine.createSpy(methodName); -191 -192 this.spies_.push(spyObj); -193 spyObj.baseObj = obj; -194 spyObj.methodName = methodName; -195 spyObj.originalValue = obj[methodName]; -196 -197 obj[methodName] = spyObj; -198 -199 return spyObj; -200 }; -201 -202 jasmine.Spec.prototype.removeAllSpies = function() { -203 for (var i = 0; i < this.spies_.length; i++) { -204 var spy = this.spies_[i]; -205 spy.baseObj[spy.methodName] = spy.originalValue; -206 } -207 this.spies_ = []; -208 }; -209 -210 \ No newline at end of file +137 +138 this.env.reporter.reportSpecStarting(this); +139 +140 spec.env.currentSpec = spec; +141 +142 spec.addBeforesAndAftersToQueue(); +143 +144 spec.queue.start(function () { +145 spec.finish(onComplete); +146 }); +147 }; +148 +149 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +150 var runner = this.env.currentRunner(); +151 var i; +152 +153 for (var suite = this.suite; suite; suite = suite.parentSuite) { +154 for (i = 0; i < suite.before_.length; i++) { +155 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +156 } +157 } +158 for (i = 0; i < runner.before_.length; i++) { +159 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +160 } +161 for (i = 0; i < this.afterCallbacks.length; i++) { +162 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +163 } +164 for (suite = this.suite; suite; suite = suite.parentSuite) { +165 for (i = 0; i < suite.after_.length; i++) { +166 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +167 } +168 } +169 for (i = 0; i < runner.after_.length; i++) { +170 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +171 } +172 }; +173 +174 jasmine.Spec.prototype.explodes = function() { +175 throw 'explodes function should not have been called'; +176 }; +177 +178 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +179 if (obj == jasmine.undefined) { +180 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +181 } +182 +183 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { +184 throw methodName + '() method does not exist'; +185 } +186 +187 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +188 throw new Error(methodName + ' has already been spied upon'); +189 } +190 +191 var spyObj = jasmine.createSpy(methodName); +192 +193 this.spies_.push(spyObj); +194 spyObj.baseObj = obj; +195 spyObj.methodName = methodName; +196 spyObj.originalValue = obj[methodName]; +197 +198 obj[methodName] = spyObj; +199 +200 return spyObj; +201 }; +202 +203 jasmine.Spec.prototype.removeAllSpies = function() { +204 for (var i = 0; i < this.spies_.length; i++) { +205 var spy = this.spies_[i]; +206 spy.baseObj[spy.methodName] = spy.originalValue; +207 } +208 this.spies_ = []; +209 }; +210 +211 \ 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 75ddeb5..83bd46b 100644 --- a/doc/symbols/src/src_base.js.html +++ b/doc/symbols/src/src_base.js.html @@ -179,7 +179,7 @@ 172 * 173 * @example 174 * // don't care about which function is passed in, as long as it's a function -175 * expect(mySpy).wasCalledWith(jasmine.any(Function)); +175 * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); 176 * 177 * @param {Class} clazz 178 * @returns matchable object of the type clazz @@ -194,396 +194,397 @@ 187 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine 188 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. 189 * -190 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) -191 * Spies are torn down at the end of every spec. -192 * -193 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. -194 * -195 * @example -196 * // a stub -197 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere -198 * -199 * // spy example -200 * var foo = { -201 * not: function(bool) { return !bool; } -202 * } -203 * -204 * // actual foo.not will not be called, execution stops -205 * spyOn(foo, 'not'); -206 -207 // foo.not spied upon, execution will continue to implementation -208 * spyOn(foo, 'not').andCallThrough(); -209 * -210 * // fake example -211 * var foo = { -212 * not: function(bool) { return !bool; } -213 * } -214 * -215 * // foo.not(val) will return val -216 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); -217 * -218 * // mock example -219 * foo.not(7 == 7); -220 * expect(foo.not).wasCalled(); -221 * expect(foo.not).wasCalledWith(true); -222 * -223 * @constructor -224 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj -225 * @param {String} name -226 */ -227 jasmine.Spy = function(name) { -228 /** -229 * The name of the spy, if provided. -230 */ -231 this.identity = name || 'unknown'; -232 /** -233 * Is this Object a spy? -234 */ -235 this.isSpy = true; -236 /** -237 * The actual function this spy stubs. -238 */ -239 this.plan = function() { -240 }; -241 /** -242 * Tracking of the most recent call to the spy. -243 * @example -244 * var mySpy = jasmine.createSpy('foo'); -245 * mySpy(1, 2); -246 * mySpy.mostRecentCall.args = [1, 2]; -247 */ -248 this.mostRecentCall = {}; -249 -250 /** -251 * Holds arguments for each call to the spy, indexed by call count -252 * @example -253 * var mySpy = jasmine.createSpy('foo'); -254 * mySpy(1, 2); -255 * mySpy(7, 8); -256 * mySpy.mostRecentCall.args = [7, 8]; -257 * mySpy.argsForCall[0] = [1, 2]; -258 * mySpy.argsForCall[1] = [7, 8]; -259 */ -260 this.argsForCall = []; -261 this.calls = []; -262 }; -263 -264 /** -265 * Tells a spy to call through to the actual implemenatation. -266 * -267 * @example -268 * var foo = { -269 * bar: function() { // do some stuff } -270 * } -271 * -272 * // defining a spy on an existing property: foo.bar -273 * spyOn(foo, 'bar').andCallThrough(); -274 */ -275 jasmine.Spy.prototype.andCallThrough = function() { -276 this.plan = this.originalValue; -277 return this; -278 }; -279 -280 /** -281 * For setting the return value of a spy. -282 * -283 * @example -284 * // defining a spy from scratch: foo() returns 'baz' -285 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); -286 * -287 * // defining a spy on an existing property: foo.bar() returns 'baz' -288 * spyOn(foo, 'bar').andReturn('baz'); -289 * -290 * @param {Object} value -291 */ -292 jasmine.Spy.prototype.andReturn = function(value) { -293 this.plan = function() { -294 return value; -295 }; -296 return this; -297 }; -298 -299 /** -300 * For throwing an exception when a spy is called. -301 * -302 * @example -303 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' -304 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); -305 * -306 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' -307 * spyOn(foo, 'bar').andThrow('baz'); -308 * -309 * @param {String} exceptionMsg -310 */ -311 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { -312 this.plan = function() { -313 throw exceptionMsg; -314 }; -315 return this; -316 }; -317 -318 /** -319 * Calls an alternate implementation when a spy is called. -320 * -321 * @example -322 * var baz = function() { -323 * // do some stuff, return something -324 * } -325 * // defining a spy from scratch: foo() calls the function baz -326 * var foo = jasmine.createSpy('spy on foo').andCall(baz); -327 * -328 * // defining a spy on an existing property: foo.bar() calls an anonymnous function -329 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); -330 * -331 * @param {Function} fakeFunc -332 */ -333 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { -334 this.plan = fakeFunc; -335 return this; -336 }; -337 -338 /** -339 * Resets all of a spy's the tracking variables so that it can be used again. -340 * -341 * @example -342 * spyOn(foo, 'bar'); -343 * -344 * foo.bar(); -345 * -346 * expect(foo.bar.callCount).toEqual(1); -347 * -348 * foo.bar.reset(); -349 * -350 * expect(foo.bar.callCount).toEqual(0); -351 */ -352 jasmine.Spy.prototype.reset = function() { -353 this.wasCalled = false; -354 this.callCount = 0; -355 this.argsForCall = []; -356 this.calls = []; -357 this.mostRecentCall = {}; -358 }; -359 -360 jasmine.createSpy = function(name) { -361 -362 var spyObj = function() { -363 spyObj.wasCalled = true; -364 spyObj.callCount++; -365 var args = jasmine.util.argsToArray(arguments); -366 spyObj.mostRecentCall.object = this; -367 spyObj.mostRecentCall.args = args; -368 spyObj.argsForCall.push(args); -369 spyObj.calls.push({object: this, args: args}); -370 return spyObj.plan.apply(this, arguments); -371 }; -372 -373 var spy = new jasmine.Spy(name); -374 -375 for (var prop in spy) { -376 spyObj[prop] = spy[prop]; -377 } -378 -379 spyObj.reset(); -380 -381 return spyObj; -382 }; -383 -384 /** -385 * Determines whether an object is a spy. -386 * -387 * @param {jasmine.Spy|Object} putativeSpy -388 * @returns {Boolean} -389 */ -390 jasmine.isSpy = function(putativeSpy) { -391 return putativeSpy && putativeSpy.isSpy; -392 }; -393 -394 /** -395 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something -396 * large in one call. -397 * -398 * @param {String} baseName name of spy class -399 * @param {Array} methodNames array of names of methods to make spies -400 */ -401 jasmine.createSpyObj = function(baseName, methodNames) { -402 if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { -403 throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); -404 } -405 var obj = {}; -406 for (var i = 0; i < methodNames.length; i++) { -407 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); -408 } -409 return obj; -410 }; -411 -412 /** -413 * All parameters are pretty-printed and concatenated together, then written to the current spec's output. -414 * -415 * Be careful not to leave calls to <code>jasmine.log</code> in production code. -416 */ -417 jasmine.log = function() { -418 var spec = jasmine.getEnv().currentSpec; -419 spec.log.apply(spec, arguments); -420 }; -421 -422 /** -423 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. -424 * -425 * @example -426 * // spy example -427 * var foo = { -428 * not: function(bool) { return !bool; } -429 * } -430 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops -431 * -432 * @see jasmine.createSpy -433 * @param obj -434 * @param methodName -435 * @returns a Jasmine spy that can be chained with all spy methods -436 */ -437 var spyOn = function(obj, methodName) { -438 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -439 }; -440 -441 /** -442 * Creates a Jasmine spec that will be added to the current suite. -443 * -444 * // TODO: pending tests -445 * -446 * @example -447 * it('should be true', function() { -448 * expect(true).toEqual(true); -449 * }); -450 * -451 * @param {String} desc description of this specification -452 * @param {Function} func defines the preconditions and expectations of the spec -453 */ -454 var it = function(desc, func) { -455 return jasmine.getEnv().it(desc, func); -456 }; -457 -458 /** -459 * Creates a <em>disabled</em> Jasmine spec. -460 * -461 * A convenience method that allows existing specs to be disabled temporarily during development. -462 * -463 * @param {String} desc description of this specification -464 * @param {Function} func defines the preconditions and expectations of the spec -465 */ -466 var xit = function(desc, func) { -467 return jasmine.getEnv().xit(desc, func); -468 }; -469 -470 /** -471 * Starts a chain for a Jasmine expectation. -472 * -473 * It is passed an Object that is the actual value and should chain to one of the many -474 * jasmine.Matchers functions. -475 * -476 * @param {Object} actual Actual value to test against and expected value -477 */ -478 var expect = function(actual) { -479 return jasmine.getEnv().currentSpec.expect(actual); -480 }; -481 -482 /** -483 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. -484 * -485 * @param {Function} func Function that defines part of a jasmine spec. -486 */ -487 var runs = function(func) { -488 jasmine.getEnv().currentSpec.runs(func); -489 }; -490 -491 /** -492 * Waits for a timeout before moving to the next runs()-defined block. -493 * @param {Number} timeout -494 */ -495 var waits = function(timeout) { -496 jasmine.getEnv().currentSpec.waits(timeout); -497 }; -498 -499 /** -500 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. -501 * -502 * @param {Number} timeout -503 * @param {Function} latchFunction -504 * @param {String} message -505 */ -506 var waitsFor = function(timeout, latchFunction, message) { -507 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); -508 }; -509 -510 /** -511 * A function that is called before each spec in a suite. -512 * -513 * Used for spec setup, including validating assumptions. -514 * -515 * @param {Function} beforeEachFunction -516 */ -517 var beforeEach = function(beforeEachFunction) { -518 jasmine.getEnv().beforeEach(beforeEachFunction); -519 }; -520 -521 /** -522 * A function that is called after each spec in a suite. -523 * -524 * Used for restoring any state that is hijacked during spec execution. -525 * -526 * @param {Function} afterEachFunction -527 */ -528 var afterEach = function(afterEachFunction) { -529 jasmine.getEnv().afterEach(afterEachFunction); -530 }; -531 -532 /** -533 * Defines a suite of specifications. -534 * -535 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared -536 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization -537 * of setup in some tests. -538 * -539 * @example -540 * // TODO: a simple suite -541 * -542 * // TODO: a simple suite with a nested describe block -543 * -544 * @param {String} description A string, usually the class under test. -545 * @param {Function} specDefinitions function that defines several specs. -546 */ -547 var describe = function(description, specDefinitions) { -548 return jasmine.getEnv().describe(description, specDefinitions); -549 }; -550 -551 /** -552 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. -553 * -554 * @param {String} description A string, usually the class under test. -555 * @param {Function} specDefinitions function that defines several specs. -556 */ -557 var xdescribe = function(description, specDefinitions) { -558 return jasmine.getEnv().xdescribe(description, specDefinitions); -559 }; -560 +190 * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). +191 * +192 * Spies are torn down at the end of every spec. +193 * +194 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. +195 * +196 * @example +197 * // a stub +198 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere +199 * +200 * // spy example +201 * var foo = { +202 * not: function(bool) { return !bool; } +203 * } +204 * +205 * // actual foo.not will not be called, execution stops +206 * spyOn(foo, 'not'); +207 +208 // foo.not spied upon, execution will continue to implementation +209 * spyOn(foo, 'not').andCallThrough(); +210 * +211 * // fake example +212 * var foo = { +213 * not: function(bool) { return !bool; } +214 * } +215 * +216 * // foo.not(val) will return val +217 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); +218 * +219 * // mock example +220 * foo.not(7 == 7); +221 * expect(foo.not).toHaveBeenCalled(); +222 * expect(foo.not).toHaveBeenCalledWith(true); +223 * +224 * @constructor +225 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj +226 * @param {String} name +227 */ +228 jasmine.Spy = function(name) { +229 /** +230 * The name of the spy, if provided. +231 */ +232 this.identity = name || 'unknown'; +233 /** +234 * Is this Object a spy? +235 */ +236 this.isSpy = true; +237 /** +238 * The actual function this spy stubs. +239 */ +240 this.plan = function() { +241 }; +242 /** +243 * Tracking of the most recent call to the spy. +244 * @example +245 * var mySpy = jasmine.createSpy('foo'); +246 * mySpy(1, 2); +247 * mySpy.mostRecentCall.args = [1, 2]; +248 */ +249 this.mostRecentCall = {}; +250 +251 /** +252 * Holds arguments for each call to the spy, indexed by call count +253 * @example +254 * var mySpy = jasmine.createSpy('foo'); +255 * mySpy(1, 2); +256 * mySpy(7, 8); +257 * mySpy.mostRecentCall.args = [7, 8]; +258 * mySpy.argsForCall[0] = [1, 2]; +259 * mySpy.argsForCall[1] = [7, 8]; +260 */ +261 this.argsForCall = []; +262 this.calls = []; +263 }; +264 +265 /** +266 * Tells a spy to call through to the actual implemenatation. +267 * +268 * @example +269 * var foo = { +270 * bar: function() { // do some stuff } +271 * } +272 * +273 * // defining a spy on an existing property: foo.bar +274 * spyOn(foo, 'bar').andCallThrough(); +275 */ +276 jasmine.Spy.prototype.andCallThrough = function() { +277 this.plan = this.originalValue; +278 return this; +279 }; +280 +281 /** +282 * For setting the return value of a spy. +283 * +284 * @example +285 * // defining a spy from scratch: foo() returns 'baz' +286 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); +287 * +288 * // defining a spy on an existing property: foo.bar() returns 'baz' +289 * spyOn(foo, 'bar').andReturn('baz'); +290 * +291 * @param {Object} value +292 */ +293 jasmine.Spy.prototype.andReturn = function(value) { +294 this.plan = function() { +295 return value; +296 }; +297 return this; +298 }; +299 +300 /** +301 * For throwing an exception when a spy is called. +302 * +303 * @example +304 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' +305 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); +306 * +307 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' +308 * spyOn(foo, 'bar').andThrow('baz'); +309 * +310 * @param {String} exceptionMsg +311 */ +312 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { +313 this.plan = function() { +314 throw exceptionMsg; +315 }; +316 return this; +317 }; +318 +319 /** +320 * Calls an alternate implementation when a spy is called. +321 * +322 * @example +323 * var baz = function() { +324 * // do some stuff, return something +325 * } +326 * // defining a spy from scratch: foo() calls the function baz +327 * var foo = jasmine.createSpy('spy on foo').andCall(baz); +328 * +329 * // defining a spy on an existing property: foo.bar() calls an anonymnous function +330 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); +331 * +332 * @param {Function} fakeFunc +333 */ +334 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { +335 this.plan = fakeFunc; +336 return this; +337 }; +338 +339 /** +340 * Resets all of a spy's the tracking variables so that it can be used again. +341 * +342 * @example +343 * spyOn(foo, 'bar'); +344 * +345 * foo.bar(); +346 * +347 * expect(foo.bar.callCount).toEqual(1); +348 * +349 * foo.bar.reset(); +350 * +351 * expect(foo.bar.callCount).toEqual(0); +352 */ +353 jasmine.Spy.prototype.reset = function() { +354 this.wasCalled = false; +355 this.callCount = 0; +356 this.argsForCall = []; +357 this.calls = []; +358 this.mostRecentCall = {}; +359 }; +360 +361 jasmine.createSpy = function(name) { +362 +363 var spyObj = function() { +364 spyObj.wasCalled = true; +365 spyObj.callCount++; +366 var args = jasmine.util.argsToArray(arguments); +367 spyObj.mostRecentCall.object = this; +368 spyObj.mostRecentCall.args = args; +369 spyObj.argsForCall.push(args); +370 spyObj.calls.push({object: this, args: args}); +371 return spyObj.plan.apply(this, arguments); +372 }; +373 +374 var spy = new jasmine.Spy(name); +375 +376 for (var prop in spy) { +377 spyObj[prop] = spy[prop]; +378 } +379 +380 spyObj.reset(); +381 +382 return spyObj; +383 }; +384 +385 /** +386 * Determines whether an object is a spy. +387 * +388 * @param {jasmine.Spy|Object} putativeSpy +389 * @returns {Boolean} +390 */ +391 jasmine.isSpy = function(putativeSpy) { +392 return putativeSpy && putativeSpy.isSpy; +393 }; +394 +395 /** +396 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something +397 * large in one call. +398 * +399 * @param {String} baseName name of spy class +400 * @param {Array} methodNames array of names of methods to make spies +401 */ +402 jasmine.createSpyObj = function(baseName, methodNames) { +403 if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { +404 throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); +405 } +406 var obj = {}; +407 for (var i = 0; i < methodNames.length; i++) { +408 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); +409 } +410 return obj; +411 }; +412 +413 /** +414 * All parameters are pretty-printed and concatenated together, then written to the current spec's output. +415 * +416 * Be careful not to leave calls to <code>jasmine.log</code> in production code. +417 */ +418 jasmine.log = function() { +419 var spec = jasmine.getEnv().currentSpec; +420 spec.log.apply(spec, arguments); +421 }; +422 +423 /** +424 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. +425 * +426 * @example +427 * // spy example +428 * var foo = { +429 * not: function(bool) { return !bool; } +430 * } +431 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops +432 * +433 * @see jasmine.createSpy +434 * @param obj +435 * @param methodName +436 * @returns a Jasmine spy that can be chained with all spy methods +437 */ +438 var spyOn = function(obj, methodName) { +439 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +440 }; +441 +442 /** +443 * Creates a Jasmine spec that will be added to the current suite. +444 * +445 * // TODO: pending tests +446 * +447 * @example +448 * it('should be true', function() { +449 * expect(true).toEqual(true); +450 * }); +451 * +452 * @param {String} desc description of this specification +453 * @param {Function} func defines the preconditions and expectations of the spec +454 */ +455 var it = function(desc, func) { +456 return jasmine.getEnv().it(desc, func); +457 }; +458 +459 /** +460 * Creates a <em>disabled</em> Jasmine spec. +461 * +462 * A convenience method that allows existing specs to be disabled temporarily during development. +463 * +464 * @param {String} desc description of this specification +465 * @param {Function} func defines the preconditions and expectations of the spec +466 */ +467 var xit = function(desc, func) { +468 return jasmine.getEnv().xit(desc, func); +469 }; +470 +471 /** +472 * Starts a chain for a Jasmine expectation. +473 * +474 * It is passed an Object that is the actual value and should chain to one of the many +475 * jasmine.Matchers functions. +476 * +477 * @param {Object} actual Actual value to test against and expected value +478 */ +479 var expect = function(actual) { +480 return jasmine.getEnv().currentSpec.expect(actual); +481 }; +482 +483 /** +484 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. +485 * +486 * @param {Function} func Function that defines part of a jasmine spec. +487 */ +488 var runs = function(func) { +489 jasmine.getEnv().currentSpec.runs(func); +490 }; +491 +492 /** +493 * Waits for a timeout before moving to the next runs()-defined block. +494 * @param {Number} timeout +495 */ +496 var waits = function(timeout) { +497 jasmine.getEnv().currentSpec.waits(timeout); +498 }; +499 +500 /** +501 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. +502 * +503 * @param {Number} timeout +504 * @param {Function} latchFunction +505 * @param {String} message +506 */ +507 var waitsFor = function(timeout, latchFunction, message) { +508 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +509 }; +510 +511 /** +512 * A function that is called before each spec in a suite. +513 * +514 * Used for spec setup, including validating assumptions. +515 * +516 * @param {Function} beforeEachFunction +517 */ +518 var beforeEach = function(beforeEachFunction) { +519 jasmine.getEnv().beforeEach(beforeEachFunction); +520 }; +521 +522 /** +523 * A function that is called after each spec in a suite. +524 * +525 * Used for restoring any state that is hijacked during spec execution. +526 * +527 * @param {Function} afterEachFunction +528 */ +529 var afterEach = function(afterEachFunction) { +530 jasmine.getEnv().afterEach(afterEachFunction); +531 }; +532 +533 /** +534 * Defines a suite of specifications. +535 * +536 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared +537 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization +538 * of setup in some tests. +539 * +540 * @example +541 * // TODO: a simple suite +542 * +543 * // TODO: a simple suite with a nested describe block +544 * +545 * @param {String} description A string, usually the class under test. +546 * @param {Function} specDefinitions function that defines several specs. +547 */ +548 var describe = function(description, specDefinitions) { +549 return jasmine.getEnv().describe(description, specDefinitions); +550 }; +551 +552 /** +553 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. +554 * +555 * @param {String} description A string, usually the class under test. +556 * @param {Function} specDefinitions function that defines several specs. +557 */ +558 var xdescribe = function(description, specDefinitions) { +559 return jasmine.getEnv().xdescribe(description, specDefinitions); +560 }; 561 -562 // Provide the XMLHttpRequest class for IE 5.x-6.x: -563 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { -564 try { -565 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); -566 } catch(e) { -567 } -568 try { -569 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); -570 } catch(e) { -571 } -572 try { -573 return new ActiveXObject("Msxml2.XMLHTTP"); -574 } catch(e) { -575 } -576 try { -577 return new ActiveXObject("Microsoft.XMLHTTP"); -578 } catch(e) { -579 } -580 throw new Error("This browser does not support XMLHttpRequest."); -581 } : XMLHttpRequest; -582 \ No newline at end of file +562 +563 // Provide the XMLHttpRequest class for IE 5.x-6.x: +564 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { +565 try { +566 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); +567 } catch(e) { +568 } +569 try { +570 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); +571 } catch(e) { +572 } +573 try { +574 return new ActiveXObject("Msxml2.XMLHTTP"); +575 } catch(e) { +576 } +577 try { +578 return new ActiveXObject("Microsoft.XMLHTTP"); +579 } catch(e) { +580 } +581 throw new Error("This browser does not support XMLHttpRequest."); +582 } : XMLHttpRequest; +583 \ No newline at end of file diff --git a/doc/symbols/src/lib_TrivialReporter.js.html b/doc/symbols/src/src_html_TrivialReporter.js.html similarity index 84% rename from doc/symbols/src/lib_TrivialReporter.js.html rename to doc/symbols/src/src_html_TrivialReporter.js.html index 8afab28..e9cb7b4 100644 --- a/doc/symbols/src/lib_TrivialReporter.js.html +++ b/doc/symbols/src/src_html_TrivialReporter.js.html @@ -8,176 +8,183 @@
  1 jasmine.TrivialReporter = function(doc) {
   2   this.document = doc || document;
   3   this.suiteDivs = {};
-  4 };
-  5 
-  6 jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
-  7   var el = document.createElement(type);
-  8 
-  9   for (var i = 2; i < arguments.length; i++) {
- 10     var child = arguments[i];
- 11 
- 12     if (typeof child === 'string') {
- 13       el.appendChild(document.createTextNode(child));
- 14     } else {
- 15       if (child) { el.appendChild(child); }
- 16     }
- 17   }
- 18 
- 19   for (var attr in attrs) {
- 20     if (attr == "className") {
- 21       el[attr] = attrs[attr];
- 22     } else {
- 23       el.setAttribute(attr, attrs[attr]);
- 24     }
- 25   }
- 26 
- 27   return el;
- 28 };
- 29 
- 30 jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
- 31   var showPassed, showSkipped;
- 32 
- 33   this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
- 34       this.createDom('div', { className: 'banner' },
- 35         this.createDom('div', { className: 'logo' },
- 36             "Jasmine",
- 37             this.createDom('span', { className: 'version' }, runner.env.versionString())),
- 38         this.createDom('div', { className: 'options' },
- 39             "Show ",
- 40             showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
- 41             this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
- 42             showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
- 43             this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
- 44             )
- 45           ),
- 46 
- 47       this.runnerDiv = this.createDom('div', { className: 'runner running' },
- 48           this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
- 49           this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
- 50           this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
- 51       );
- 52 
- 53   this.document.body.appendChild(this.outerDiv);
- 54 
- 55   var suites = runner.suites();
- 56   for (var i = 0; i < suites.length; i++) {
- 57     var suite = suites[i];
- 58     var suiteDiv = this.createDom('div', { className: 'suite' },
- 59         this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
- 60         this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
- 61     this.suiteDivs[suite.id] = suiteDiv;
- 62     var parentDiv = this.outerDiv;
- 63     if (suite.parentSuite) {
- 64       parentDiv = this.suiteDivs[suite.parentSuite.id];
- 65     }
- 66     parentDiv.appendChild(suiteDiv);
- 67   }
- 68 
- 69   this.startedAt = new Date();
- 70 
- 71   var self = this;
- 72   showPassed.onchange = function(evt) {
- 73     if (evt.target.checked) {
- 74       self.outerDiv.className += ' show-passed';
- 75     } else {
- 76       self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
- 77     }
- 78   };
- 79 
- 80   showSkipped.onchange = function(evt) {
- 81     if (evt.target.checked) {
- 82       self.outerDiv.className += ' show-skipped';
- 83     } else {
- 84       self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
- 85     }
- 86   };
- 87 };
- 88 
- 89 jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
- 90   var results = runner.results();
- 91   var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
- 92   this.runnerDiv.setAttribute("class", className);
- 93   //do it twice for IE
- 94   this.runnerDiv.setAttribute("className", className);
- 95   var specs = runner.specs();
- 96   var specCount = 0;
- 97   for (var i = 0; i < specs.length; i++) {
- 98     if (this.specFilter(specs[i])) {
- 99       specCount++;
-100     }
-101   }
-102   var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
-103   message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
-104   this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
-105 
-106   this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
-107 };
-108 
-109 jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
-110   var results = suite.results();
-111   var status = results.passed() ? 'passed' : 'failed';
-112   if (results.totalCount == 0) { // todo: change this to check results.skipped
-113     status = 'skipped';
-114   }
-115   this.suiteDivs[suite.id].className += " " + status;
-116 };
-117 
-118 jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
-119   var results = spec.results();
-120   var status = results.passed() ? 'passed' : 'failed';
-121   if (results.skipped) {
-122     status = 'skipped';
-123   }
-124   var specDiv = this.createDom('div', { className: 'spec '  + status },
-125       this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
-126       this.createDom('a', {
-127         className: 'description',
-128         href: '?spec=' + encodeURIComponent(spec.getFullName()),
-129         title: spec.getFullName()
-130       }, spec.description));
-131 
-132 
-133   var resultItems = results.getItems();
-134   var messagesDiv = this.createDom('div', { className: 'messages' });
-135   for (var i = 0; i < resultItems.length; i++) {
-136     var result = resultItems[i];
-137 
-138     if (result.type == 'log') {
-139       messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
-140     } else if (result.type == 'expect' && result.passed && !result.passed()) {
-141       messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
-142 
-143       if (result.trace.stack) {
-144         messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
-145       }
-146     }
-147   }
-148 
-149   if (messagesDiv.childNodes.length > 0) {
-150     specDiv.appendChild(messagesDiv);
-151   }
-152 
-153   this.suiteDivs[spec.suite.id].appendChild(specDiv);
-154 };
+  4   this.logRunningSpecs = false;
+  5 };
+  6 
+  7 jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
+  8   var el = document.createElement(type);
+  9 
+ 10   for (var i = 2; i < arguments.length; i++) {
+ 11     var child = arguments[i];
+ 12 
+ 13     if (typeof child === 'string') {
+ 14       el.appendChild(document.createTextNode(child));
+ 15     } else {
+ 16       if (child) { el.appendChild(child); }
+ 17     }
+ 18   }
+ 19 
+ 20   for (var attr in attrs) {
+ 21     if (attr == "className") {
+ 22       el[attr] = attrs[attr];
+ 23     } else {
+ 24       el.setAttribute(attr, attrs[attr]);
+ 25     }
+ 26   }
+ 27 
+ 28   return el;
+ 29 };
+ 30 
+ 31 jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
+ 32   var showPassed, showSkipped;
+ 33 
+ 34   this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
+ 35       this.createDom('div', { className: 'banner' },
+ 36         this.createDom('div', { className: 'logo' },
+ 37             "Jasmine",
+ 38             this.createDom('span', { className: 'version' }, runner.env.versionString())),
+ 39         this.createDom('div', { className: 'options' },
+ 40             "Show ",
+ 41             showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
+ 42             this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
+ 43             showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
+ 44             this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
+ 45             )
+ 46           ),
+ 47 
+ 48       this.runnerDiv = this.createDom('div', { className: 'runner running' },
+ 49           this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
+ 50           this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
+ 51           this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
+ 52       );
+ 53 
+ 54   this.document.body.appendChild(this.outerDiv);
+ 55 
+ 56   var suites = runner.suites();
+ 57   for (var i = 0; i < suites.length; i++) {
+ 58     var suite = suites[i];
+ 59     var suiteDiv = this.createDom('div', { className: 'suite' },
+ 60         this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
+ 61         this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
+ 62     this.suiteDivs[suite.id] = suiteDiv;
+ 63     var parentDiv = this.outerDiv;
+ 64     if (suite.parentSuite) {
+ 65       parentDiv = this.suiteDivs[suite.parentSuite.id];
+ 66     }
+ 67     parentDiv.appendChild(suiteDiv);
+ 68   }
+ 69 
+ 70   this.startedAt = new Date();
+ 71 
+ 72   var self = this;
+ 73   showPassed.onchange = function(evt) {
+ 74     if (evt.target.checked) {
+ 75       self.outerDiv.className += ' show-passed';
+ 76     } else {
+ 77       self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
+ 78     }
+ 79   };
+ 80 
+ 81   showSkipped.onchange = function(evt) {
+ 82     if (evt.target.checked) {
+ 83       self.outerDiv.className += ' show-skipped';
+ 84     } else {
+ 85       self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
+ 86     }
+ 87   };
+ 88 };
+ 89 
+ 90 jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
+ 91   var results = runner.results();
+ 92   var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
+ 93   this.runnerDiv.setAttribute("class", className);
+ 94   //do it twice for IE
+ 95   this.runnerDiv.setAttribute("className", className);
+ 96   var specs = runner.specs();
+ 97   var specCount = 0;
+ 98   for (var i = 0; i < specs.length; i++) {
+ 99     if (this.specFilter(specs[i])) {
+100       specCount++;
+101     }
+102   }
+103   var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
+104   message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
+105   this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
+106 
+107   this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
+108 };
+109 
+110 jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
+111   var results = suite.results();
+112   var status = results.passed() ? 'passed' : 'failed';
+113   if (results.totalCount == 0) { // todo: change this to check results.skipped
+114     status = 'skipped';
+115   }
+116   this.suiteDivs[suite.id].className += " " + status;
+117 };
+118 
+119 jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
+120   if (this.logRunningSpecs) {
+121     this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
+122   }
+123 };
+124 
+125 jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
+126   var results = spec.results();
+127   var status = results.passed() ? 'passed' : 'failed';
+128   if (results.skipped) {
+129     status = 'skipped';
+130   }
+131   var specDiv = this.createDom('div', { className: 'spec '  + status },
+132       this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
+133       this.createDom('a', {
+134         className: 'description',
+135         href: '?spec=' + encodeURIComponent(spec.getFullName()),
+136         title: spec.getFullName()
+137       }, spec.description));
+138 
+139 
+140   var resultItems = results.getItems();
+141   var messagesDiv = this.createDom('div', { className: 'messages' });
+142   for (var i = 0; i < resultItems.length; i++) {
+143     var result = resultItems[i];
+144 
+145     if (result.type == 'log') {
+146       messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
+147     } else if (result.type == 'expect' && result.passed && !result.passed()) {
+148       messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
+149 
+150       if (result.trace.stack) {
+151         messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
+152       }
+153     }
+154   }
 155 
-156 jasmine.TrivialReporter.prototype.log = function() {
-157   var console = jasmine.getGlobal().console;
-158   if (console && console.log) console.log.apply(console, arguments);
-159 };
-160 
-161 jasmine.TrivialReporter.prototype.getLocation = function() {
-162   return this.document.location;
-163 };
-164 
-165 jasmine.TrivialReporter.prototype.specFilter = function(spec) {
-166   var paramMap = {};
-167   var params = this.getLocation().search.substring(1).split('&');
-168   for (var i = 0; i < params.length; i++) {
-169     var p = params[i].split('=');
-170     paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
-171   }
-172 
-173   if (!paramMap["spec"]) return true;
-174   return spec.getFullName().indexOf(paramMap["spec"]) == 0;
-175 };
-176 
\ No newline at end of file +156 if (messagesDiv.childNodes.length > 0) { +157 specDiv.appendChild(messagesDiv); +158 } +159 +160 this.suiteDivs[spec.suite.id].appendChild(specDiv); +161 }; +162 +163 jasmine.TrivialReporter.prototype.log = function() { +164 var console = jasmine.getGlobal().console; +165 if (console && console.log) console.log.apply(console, arguments); +166 }; +167 +168 jasmine.TrivialReporter.prototype.getLocation = function() { +169 return this.document.location; +170 }; +171 +172 jasmine.TrivialReporter.prototype.specFilter = function(spec) { +173 var paramMap = {}; +174 var params = this.getLocation().search.substring(1).split('&'); +175 for (var i = 0; i < params.length; i++) { +176 var p = params[i].split('='); +177 paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); +178 } +179 +180 if (!paramMap["spec"]) return true; +181 return spec.getFullName().indexOf(paramMap["spec"]) == 0; +182 }; +183 \ 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 fa655cb..93f9afc 100644 --- a/doc/symbols/src/src_mock-timeout.js.html +++ b/doc/symbols/src/src_mock-timeout.js.html @@ -130,63 +130,62 @@ 123 }, 124 125 uninstallMock: function() { -126 jasmine.log("uninstall") -127 jasmine.Clock.assertInstalled(); -128 jasmine.Clock.installed = jasmine.Clock.real; -129 }, -130 -131 real: { -132 setTimeout: jasmine.getGlobal().setTimeout, -133 clearTimeout: jasmine.getGlobal().clearTimeout, -134 setInterval: jasmine.getGlobal().setInterval, -135 clearInterval: jasmine.getGlobal().clearInterval -136 }, -137 -138 assertInstalled: function() { -139 if (!jasmine.Clock.isInstalled()) { -140 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -141 } -142 }, -143 -144 isInstalled: function() { -145 return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer; -146 }, -147 -148 installed: null -149 }; -150 jasmine.Clock.installed = jasmine.Clock.real; -151 -152 //else for IE support -153 jasmine.getGlobal().setTimeout = function(funcToCall, millis) { -154 if (jasmine.Clock.installed.setTimeout.apply) { -155 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -156 } else { -157 return jasmine.Clock.installed.setTimeout(funcToCall, millis); -158 } -159 }; -160 -161 jasmine.getGlobal().setInterval = function(funcToCall, millis) { -162 if (jasmine.Clock.installed.setInterval.apply) { -163 return jasmine.Clock.installed.setInterval.apply(this, arguments); -164 } else { -165 return jasmine.Clock.installed.setInterval(funcToCall, millis); -166 } -167 }; -168 -169 jasmine.getGlobal().clearTimeout = function(timeoutKey) { -170 if (jasmine.Clock.installed.clearTimeout.apply) { -171 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -172 } else { -173 return jasmine.Clock.installed.clearTimeout(timeoutKey); -174 } -175 }; -176 -177 jasmine.getGlobal().clearInterval = function(timeoutKey) { -178 if (jasmine.Clock.installed.clearTimeout.apply) { -179 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -180 } else { -181 return jasmine.Clock.installed.clearInterval(timeoutKey); -182 } -183 }; -184 -185 \ No newline at end of file +126 jasmine.Clock.assertInstalled(); +127 jasmine.Clock.installed = jasmine.Clock.real; +128 }, +129 +130 real: { +131 setTimeout: jasmine.getGlobal().setTimeout, +132 clearTimeout: jasmine.getGlobal().clearTimeout, +133 setInterval: jasmine.getGlobal().setInterval, +134 clearInterval: jasmine.getGlobal().clearInterval +135 }, +136 +137 assertInstalled: function() { +138 if (!jasmine.Clock.isInstalled()) { +139 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); +140 } +141 }, +142 +143 isInstalled: function() { +144 return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer; +145 }, +146 +147 installed: null +148 }; +149 jasmine.Clock.installed = jasmine.Clock.real; +150 +151 //else for IE support +152 jasmine.getGlobal().setTimeout = function(funcToCall, millis) { +153 if (jasmine.Clock.installed.setTimeout.apply) { +154 return jasmine.Clock.installed.setTimeout.apply(this, arguments); +155 } else { +156 return jasmine.Clock.installed.setTimeout(funcToCall, millis); +157 } +158 }; +159 +160 jasmine.getGlobal().setInterval = function(funcToCall, millis) { +161 if (jasmine.Clock.installed.setInterval.apply) { +162 return jasmine.Clock.installed.setInterval.apply(this, arguments); +163 } else { +164 return jasmine.Clock.installed.setInterval(funcToCall, millis); +165 } +166 }; +167 +168 jasmine.getGlobal().clearTimeout = function(timeoutKey) { +169 if (jasmine.Clock.installed.clearTimeout.apply) { +170 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +171 } else { +172 return jasmine.Clock.installed.clearTimeout(timeoutKey); +173 } +174 }; +175 +176 jasmine.getGlobal().clearInterval = function(timeoutKey) { +177 if (jasmine.Clock.installed.clearTimeout.apply) { +178 return jasmine.Clock.installed.clearInterval.apply(this, arguments); +179 } else { +180 return jasmine.Clock.installed.clearInterval(timeoutKey); +181 } +182 }; +183 +184 \ No newline at end of file diff --git a/lib/jasmine-html.js b/lib/jasmine-html.js new file mode 100644 index 0000000..b405821 --- /dev/null +++ b/lib/jasmine-html.js @@ -0,0 +1,182 @@ +jasmine.TrivialReporter = function(doc) { + this.document = doc || document; + this.suiteDivs = {}; + this.logRunningSpecs = false; +}; + +jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) { + var el = document.createElement(type); + + for (var i = 2; i < arguments.length; i++) { + var child = arguments[i]; + + if (typeof child === 'string') { + el.appendChild(document.createTextNode(child)); + } else { + if (child) { el.appendChild(child); } + } + } + + for (var attr in attrs) { + if (attr == "className") { + el[attr] = attrs[attr]; + } else { + el.setAttribute(attr, attrs[attr]); + } + } + + return el; +}; + +jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) { + var showPassed, showSkipped; + + this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' }, + this.createDom('div', { className: 'banner' }, + this.createDom('div', { className: 'logo' }, + "Jasmine", + this.createDom('span', { className: 'version' }, runner.env.versionString())), + this.createDom('div', { className: 'options' }, + "Show ", + showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }), + this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "), + showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }), + this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped") + ) + ), + + this.runnerDiv = this.createDom('div', { className: 'runner running' }, + this.createDom('a', { className: 'run_spec', href: '?' }, "run all"), + this.runnerMessageSpan = this.createDom('span', {}, "Running..."), + this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, "")) + ); + + this.document.body.appendChild(this.outerDiv); + + var suites = runner.suites(); + for (var i = 0; i < suites.length; i++) { + var suite = suites[i]; + var suiteDiv = this.createDom('div', { className: 'suite' }, + this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"), + this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description)); + this.suiteDivs[suite.id] = suiteDiv; + var parentDiv = this.outerDiv; + if (suite.parentSuite) { + parentDiv = this.suiteDivs[suite.parentSuite.id]; + } + parentDiv.appendChild(suiteDiv); + } + + this.startedAt = new Date(); + + var self = this; + showPassed.onchange = function(evt) { + if (evt.target.checked) { + self.outerDiv.className += ' show-passed'; + } else { + self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, ''); + } + }; + + showSkipped.onchange = function(evt) { + if (evt.target.checked) { + self.outerDiv.className += ' show-skipped'; + } else { + self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, ''); + } + }; +}; + +jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { + var results = runner.results(); + var className = (results.failedCount > 0) ? "runner failed" : "runner passed"; + this.runnerDiv.setAttribute("class", className); + //do it twice for IE + this.runnerDiv.setAttribute("className", className); + var specs = runner.specs(); + var specCount = 0; + for (var i = 0; i < specs.length; i++) { + if (this.specFilter(specs[i])) { + specCount++; + } + } + var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s"); + message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"; + this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild); + + this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString())); +}; + +jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { + var results = suite.results(); + var status = results.passed() ? 'passed' : 'failed'; + if (results.totalCount == 0) { // todo: change this to check results.skipped + status = 'skipped'; + } + this.suiteDivs[suite.id].className += " " + status; +}; + +jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) { + if (this.logRunningSpecs) { + this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...'); + } +}; + +jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { + var results = spec.results(); + var status = results.passed() ? 'passed' : 'failed'; + if (results.skipped) { + status = 'skipped'; + } + var specDiv = this.createDom('div', { className: 'spec ' + status }, + this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"), + this.createDom('a', { + className: 'description', + href: '?spec=' + encodeURIComponent(spec.getFullName()), + title: spec.getFullName() + }, spec.description)); + + + var resultItems = results.getItems(); + var messagesDiv = this.createDom('div', { className: 'messages' }); + for (var i = 0; i < resultItems.length; i++) { + var result = resultItems[i]; + + if (result.type == 'log') { + messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); + } else if (result.type == 'expect' && result.passed && !result.passed()) { + messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); + + if (result.trace.stack) { + messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); + } + } + } + + if (messagesDiv.childNodes.length > 0) { + specDiv.appendChild(messagesDiv); + } + + this.suiteDivs[spec.suite.id].appendChild(specDiv); +}; + +jasmine.TrivialReporter.prototype.log = function() { + var console = jasmine.getGlobal().console; + if (console && console.log) console.log.apply(console, arguments); +}; + +jasmine.TrivialReporter.prototype.getLocation = function() { + return this.document.location; +}; + +jasmine.TrivialReporter.prototype.specFilter = function(spec) { + var paramMap = {}; + var params = this.getLocation().search.substring(1).split('&'); + for (var i = 0; i < params.length; i++) { + var p = params[i].split('='); + paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); + } + + if (!paramMap["spec"]) return true; + return spec.getFullName().indexOf(paramMap["spec"]) == 0; +}; diff --git a/lib/jasmine.js b/lib/jasmine.js index c8c9dc7..697230f 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -2339,5 +2339,5 @@ jasmine.version_= { "major": 0, "minor": 11, "build": 0, - "revision": 1277425679 + "revision": 1277504104 }; diff --git a/spec/jasmine_helper.rb b/spec/jasmine_helper.rb deleted file mode 100755 index 55b45d3..0000000 --- a/spec/jasmine_helper.rb +++ /dev/null @@ -1,44 +0,0 @@ -class JasmineHelper - def self.jasmine_lib_dir - File.expand_path(File.join(jasmine_root, 'lib')) - end - - def self.jasmine - ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] + - ['/lib/json2.js', - '/lib/TrivialReporter.js'] - end - - def self.jasmine_root - File.expand_path(File.join(File.dirname(__FILE__), '..')) - end - - - def self.jasmine_src_dir - File.expand_path(File.join(jasmine_root, 'src')) - end - - def self.jasmine_lib_dir - File.expand_path(File.join(jasmine_root, 'lib')) - end - - def self.jasmine_spec_dir - File.expand_path(File.join(jasmine_root, 'spec')) - end - - def self.raw_spec_files - Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js")) - end - - def self.specs - Jasmine.cachebust(raw_spec_files).collect {|f| f.sub(jasmine_spec_dir, "/spec")} - end - - def self.dir_mappings - { - "/src" => jasmine_src_dir, - "/spec" => jasmine_spec_dir, - "/lib" => jasmine_lib_dir - } - end -end diff --git a/spec/jasmine_spec.rb b/spec/jasmine_spec.rb deleted file mode 100644 index de4f09f..0000000 --- a/spec/jasmine_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'rubygems' -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 = 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('localhost').jar_path, - JasmineHelper.specs, - JasmineHelper.dir_mappings) -end - -spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner) - -should_stop = false - -Spec::Runner.configure do |config| - config.after(:suite) do - spec_builder.stop if should_stop - end -end - -spec_builder.start -should_stop = true -spec_builder.declare_suites