diff --git a/README.markdown b/README.markdown index 5977992..bdc4943 100644 --- a/README.markdown +++ b/README.markdown @@ -1,32 +1,23 @@ Jasmine ======= -**YET ANOTHER JavaScript testing framework** +**A JavaScript Testing Framework** 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 - -open `http://localhost:8888/` in your favorite browser. +Please use the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby) to run suites in a ruby environment. ### 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) 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 @@ -35,8 +26,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) @@ -51,47 +41,59 @@ 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, ScrewUnit, JSSpec, [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. @@ -100,166 +102,71 @@ 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. -Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests. +Here's the definition of `toBeLessThan()`: -### Asynchronous Specs + toBeLessThan: function(expected) { + return this.actual < expected; + }; -You may be thinking, "That's all well and good, but you mentioned something about asynchronous 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: -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); + beforeEach(function() { + this.addMatchers({ + toBeVisible: function() { return this.actual.isVisible(); } }); }); -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: - describe('One suite', function () { - it('has a test', function () { - ... - }); - - it('has another test', function () { - ... - }); - }); + describe('One suite', function () { + it('has a 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); - }); - - it('has another test', function () { - bar++; - expect(bar).toEqual(2); - }); - }); + 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); + }); + }); #### beforeEach @@ -344,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); @@ -386,7 +293,7 @@ Here are a few examples: var Klass.prototype.methodWithCallback = function (callback) { return callback('foo'); }; - + ... it('should spy on Klass#method') { @@ -430,23 +337,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()` returns true if the object is a spy and was called +`expect(x).wasCalled()` passes if `x` is a spy and was called -`wasCalledWith(arguments)` returns true 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()` returns true 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)` returns true 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: @@ -462,18 +369,117 @@ 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. * 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 * [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/Rakefile b/Rakefile index 4ce8838..7a88614 100644 --- a/Rakefile +++ b/Rakefile @@ -56,10 +56,10 @@ 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' - + sources = jasmine_sources version = version_hash @@ -119,17 +119,37 @@ 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: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 + desc "Run geminstaller." + task :geminstaller do + `geminstaller --sudo` + end end \ No newline at end of file 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/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/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 diff --git a/doc/files.html b/doc/files.html index bce9c40..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 Tue Nov 10 2009 17:31:30 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 2f8b49a..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 Tue Nov 10 2009 17:31:30 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 2b25eed..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 Tue Nov 10 2009 17:31:29 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 f50be43..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 Tue Nov 10 2009 17:31:29 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 dbe6f6a..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 Tue Nov 10 2009 17:31:29 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 ac69aa9..44245e8 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -382,6 +382,15 @@ ul.inheritsList + +   + +
matchersClass() +
+
+ + +   @@ -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 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 38ea39f..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 Tue Nov 10 2009 17:31:30 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 6aa15b3..f176252 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()
@@ -497,6 +328,195 @@ ul.inheritsList + +   + +
toBe(expected) +
+
toBe: compares the actual to the expected using ===
+ + + + +   + +
toBeDefined() +
+
Matcher that compares the actual to jasmine.undefined.
+ + + + +   + +
toBeFalsy() +
+
Matcher that boolean nots the actual.
+ + + + +   + +
toBeGreaterThan(expected) +
+
+ + + + +   + +
toBeLessThan(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(expected) +
+
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(expected) +
+
Matcher that compares the actual to the expected using a regular expression.
+ + + + +   + +
toNotBe(expected) +
+
toNotBe: compares the actual to the expected using !==
+ + + + +   + +
toNotContain(expected) +
+
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(expected) +
+
Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
+ + + + +   + +
toThrow(expected) +
+
Matcher that checks that the expected exception was thrown by the actual.
+ + + + +   + +
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() +
+
+ + + + + <static>   + +
jasmine.Matchers.wrapInto_(prototype, matchersClass) +
+
+ + + @@ -561,364 +581,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 +628,7 @@ a pattern or a String.
<static> - jasmine.Matchers.matcherFn_(matcherName, options) + jasmine.Matchers.matcherFn_(matcherName, matcherFunction)
@@ -988,7 +650,7 @@ a pattern or a String.
- options + matcherFunction
@@ -1002,6 +664,31 @@ a pattern or a String. +
+ + +
+ + + message() + +
+
+ + + +
+ + + + + + + + + + +
@@ -1086,6 +773,674 @@ 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(expected) + +
+
+ Matcher that checks that the expected item is an element in the actual Array. + + +
+ + + + +
+
Parameters:
+ +
+ {Object} expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toEqual(expected) + +
+
+ toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toMatch(expected) + +
+
+ Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +a pattern or a String. + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotBe(expected) + +
+
+ toNotBe: compares the actual to the expected using !== + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotContain(expected) + +
+
+ Matcher that checks that the expected item is NOT an element in the actual Array. + + +
+ + + + +
+
Parameters:
+ +
+ {Object} expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotEqual(expected) + +
+
+ toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toNotMatch(expected) + +
+
+ Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch + + +
+ + + + +
+
Parameters:
+ +
+ expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + toThrow(expected) + +
+
+ Matcher that checks that the expected exception was thrown by the actual. + + +
+ + + + +
+
Parameters:
+ +
+ {String} expected + +
+
+ +
+ + + + + + + + +
+ + +
+ + + 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() + +
+
+ + + +
+ + + + + + + + + + + +
+ + +
<static> + + + jasmine.Matchers.wrapInto_(prototype, matchersClass) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ prototype + +
+
+ +
+ matchersClass + +
+
+ +
+ + + + + + + + @@ -1100,7 +1455,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 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 b2ead53..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 Tue Nov 10 2009 17:31:30 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 69283a6..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 Tue Nov 10 2009 17:31:30 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 d035c63..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 Tue Nov 10 2009 17:31:30 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 c726687..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 Tue Nov 10 2009 17:31:30 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 bc5e538..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 Tue Nov 10 2009 17:31:30 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 a7f98a6..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 Tue Nov 10 2009 17:31:30 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 898ace0..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 Tue Nov 10 2009 17:31:30 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 14b52e6..2904d8a 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 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 905d878..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 Tue Nov 10 2009 17:31:30 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/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..9c858a7 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,215 @@ 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 }; - 40 - 41 /** - 42 * @returns a sequential integer starting at 0 - 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. + 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 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.addReporter = function(reporter) { - 60 this.reporter.addReporter(reporter); + 59 jasmine.Env.prototype.nextSuiteId = function () { + 60 return this.nextSuiteId_++; 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); - 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 } + 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 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 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 } -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 }; + 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 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; +134 jasmine.Env.prototype.xit = function(desc, func) { +135 return { +136 id: this.nextSpecId(), +137 runs: function() { +138 } +139 }; +140 }; 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."); -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; -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 } +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 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 instanceof Date && b instanceof Date) { -187 return a.getTime() == b.getTime(); +186 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { +187 return (a == jasmine.undefined && b == jasmine.undefined); 188 } 189 -190 if (a instanceof jasmine.Matchers.Any) { -191 return a.matches(b); +190 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +191 return a === b; 192 } 193 -194 if (b instanceof jasmine.Matchers.Any) { -195 return b.matches(a); +194 if (a instanceof Date && b instanceof Date) { +195 return a.getTime() == b.getTime(); 196 } 197 -198 if (typeof a === "object" && typeof b === "object") { -199 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +198 if (a instanceof jasmine.Matchers.Any) { +199 return a.matches(b); 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 +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_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..20f9391 100644 --- a/doc/symbols/src/src_Matchers.js.html +++ b/doc/symbols/src/src_Matchers.js.html @@ -15,385 +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, 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 }); - 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 = 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 + 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.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 }); -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 }); -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 }); -135 -136 /** -137 * Matcher that compares the acutal to undefined. -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 }); + 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 compares the acutal to undefined. +150 * Matcher that boolean not-nots the actual. 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 }); -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 }); -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); -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 }); +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 /** +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; +270 if (typeof this.actual != 'function') { +271 throw new Error('Actual is not a function'); +272 } +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 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.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 if (this.expectedClass == Object) { +311 return typeof other == 'object'; +312 } +313 +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_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..8b69c25 100644 --- a/doc/symbols/src/src_Spec.js.html +++ b/doc/symbols/src/src_Spec.js.html @@ -17,199 +17,195 @@ 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; + 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 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.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 }; -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 + '...'); +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 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.addBeforesAndAftersToQueue(); 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 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 } +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.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 + "()"; +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] === undefined) { -181 throw methodName + '() method does not exist'; +180 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +181 throw new Error(methodName + ' has already been spied upon'); 182 } 183 -184 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -185 throw new Error(methodName + ' has already been spied upon'); -186 } -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]; -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 +184 var spyObj = jasmine.createSpy(methodName); +185 +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 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/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/html/example_suite.html b/examples/html/example_runner.html similarity index 91% rename from examples/html/example_suite.html rename to examples/html/example_runner.html index 825ec2c..e400768 100644 --- a/examples/html/example_suite.html +++ b/examples/html/example_runner.html @@ -4,7 +4,7 @@ Jasmine Test Runner - + 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..de4f09f 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('localhost').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..d343360 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.2.0 - name: rack version: 1.0.0 - name: thin @@ -17,4 +17,9 @@ 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 + 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.1.js similarity index 95% rename from lib/jasmine-0.10.0.js rename to lib/jasmine-0.10.1.js index f7f621b..0f6c015 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.1.js @@ -15,7 +15,7 @@ jasmine.unimplementedMethod_ = function() { /** * Use jasmine.undefined instead of undefined, since undefined'); } else if (jasmine.isArray_(value) || typeof value == 'object') { @@ -1833,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; }; @@ -2240,6 +2256,6 @@ window.clearInterval = function(timeoutKey) { jasmine.version_= { "major": 0, "minor": 10, - "build": 0, - "revision": 1259251766 + "build": 1, + "revision": 1267069453 }; 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%; } diff --git a/spec/jasmine_spec.rb b/spec/jasmine_spec.rb index ce15f00..de4f09f 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('localhost').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" 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/MatchersSpec.js b/spec/suites/MatchersSpec.js index e1d8c10..a2f8079 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -589,6 +589,18 @@ describe("jasmine.Matchers", function() { expect(result.passed()).toEqual(false); expect(result.expected).toEqual(['c', 'b', 'a']); expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']); + expect(result.message).toContain(jasmine.pp(result.expected)); + expect(result.message).toContain(jasmine.pp(result.actual.mostRecentCall.args)); + }); + + it('should return false if it was not called', function() { + var expected = match(TestClass.spyFunction); + expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false); + var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; + expect(result.passed()).toEqual(false); + expect(result.expected).toEqual(['c', 'b', 'a']); + expect(result.actual.argsForCall).toEqual([]); + expect(result.message).toContain(jasmine.pp(result.expected)); }); it('should allow matches across multiple calls', function() { @@ -622,12 +634,48 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("wasCalledWith"); expect(result.passed()).toEqual(false); - expect(result.message).toMatch("['a', 'b']"); - expect(result.message).toMatch("['a', 'c']"); + expect(result.message).toContain(jasmine.pp(['a', 'b'])); + expect(result.message).toContain(jasmine.pp(['a', 'c'])); expect(result.actual).toEqual(TestClass.someFunction); expect(result.expected).toEqual(['a','b']); }); }); }); + + describe("wasNotCalledWith", function() { + it('should return true if the spy was NOT called with the expected args', function() { + TestClass.spyFunction('a', 'b', 'c'); + expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toEqual(true); + }); + + it('should return false if it WAS called with the expected args', function() { + TestClass.spyFunction('a', 'b', 'c'); + var expected = match(TestClass.spyFunction); + expect(expected.wasNotCalledWith('a', 'b', 'c')).toEqual(false); + var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; + expect(result.passed()).toEqual(false); + expect(result.expected).toEqual(['a', 'b', 'c']); + expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']); + expect(result.message).toContain(jasmine.pp(result.expected)); + }); + + it('should return true if it was not called', function() { + var expected = match(TestClass.spyFunction); + expect(expected.wasNotCalledWith('c', 'b', 'a')).toEqual(true); + }); + + it('should allow matches across multiple calls', function() { + var expected = match(TestClass.spyFunction); + TestClass.spyFunction('a', 'b', 'c'); + TestClass.spyFunction('d', 'e', 'f'); + expect(expected.wasNotCalledWith('a', 'b', 'c')).toEqual(false); + expect(expected.wasNotCalledWith('d', 'e', 'f')).toEqual(false); + expect(expected.wasNotCalledWith('x', 'y', 'z')).toEqual(true); + }); + + it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalledWith')); + + }); + }); }); 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 diff --git a/spec/suites/SpySpec.js b/spec/suites/SpySpec.js index 1e782fb..60d7c25 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']); }); @@ -177,11 +177,25 @@ describe('Spies', function () { expect(TestClass.someFunction.callCount).toEqual(0); }); - it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() { - var spyObj = jasmine.createSpyObj('BaseName', ['method1', 'method2']); - expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)}); - expect(spyObj.method1.identity).toEqual('BaseName.method1'); - expect(spyObj.method2.identity).toEqual('BaseName.method2'); + describe("createSpyObj", function() { + it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() { + var spyObj = jasmine.createSpyObj('BaseName', ['method1', 'method2']); + expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)}); + expect(spyObj.method1.identity).toEqual('BaseName.method1'); + expect(spyObj.method2.identity).toEqual('BaseName.method2'); + }); + + it("should throw if you do not pass an array argument", function() { + expect(function() { + jasmine.createSpyObj('BaseName'); + }).toThrow('createSpyObj requires a non-empty array of method names to create spies for'); + }); + + it("should throw if you pass an empty array argument", function() { + expect(function() { + jasmine.createSpyObj('BaseName'); + }).toThrow('createSpyObj requires a non-empty array of method names to create spies for'); + }); }); -}); \ No newline at end of file +}); 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/Matchers.js b/src/Matchers.js index fddb267..d387d52 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -48,7 +48,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { } if (this.reportWasCalled_) return result; - + var message; if (!result) { if (this.message) { @@ -215,15 +215,32 @@ jasmine.Matchers.prototype.wasNotCalled = function() { * */ jasmine.Matchers.prototype.wasCalledWith = function() { + var expectedArgs = jasmine.util.argsToArray(arguments); + if (!jasmine.isSpy(this.actual)) { + throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); + } + this.message = function() { + if (this.actual.callCount == 0) { + return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; + } else { + return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); + } + }; + + return this.env.contains_(this.actual.argsForCall, expectedArgs); +}; + +jasmine.Matchers.prototype.wasNotCalledWith = function() { + var expectedArgs = jasmine.util.argsToArray(arguments); if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); } this.message = function() { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; }; - return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); + return !this.env.contains_(this.actual.argsForCall, expectedArgs); }; /** diff --git a/src/base.js b/src/base.js index 8850f28..fc4837b 100755 --- a/src/base.js +++ b/src/base.js @@ -15,7 +15,7 @@ jasmine.unimplementedMethod_ = function() { /** * Use jasmine.undefined instead of undefined, since undefined