diff --git a/README.markdown b/README.markdown index 5ecd15d..04ef80a 100644 --- a/README.markdown +++ b/README.markdown @@ -5,24 +5,11 @@ Jasmine Quick Start ---------- -### Ruby Suite Running +1. Get the latest release from the [downloads page](http://github.com/pivotal/jasmine/downloads). +2. Open `example/example_runner.html` 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) - -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 - git clone git://github.com/pivotal/jasmine.git - cd jasmine - sudo geminstaller - cd examples/ruby - rake test:ci +For running within a Ruby environment, including automated execution with Selenium, please use +the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby). Releases ---------- diff --git a/example/example_runner.html b/example/example_runner.html new file mode 100644 index 0000000..5525c29 --- /dev/null +++ b/example/example_runner.html @@ -0,0 +1,24 @@ + + + + Jasmine Test Runner + + + + + + + + + + + + + + + diff --git a/examples/html/spec/example_suite.js b/example/spec/example_suite.js similarity index 100% rename from examples/html/spec/example_suite.js rename to example/spec/example_suite.js diff --git a/examples/html/example_runner.html b/examples/html/example_runner.html deleted file mode 100644 index e400768..0000000 --- a/examples/html/example_runner.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - Jasmine Test Runner - - - - - - - - - - - - - - - - diff --git a/examples/ruby/Rakefile b/examples/ruby/Rakefile deleted file mode 100644 index 4196c32..0000000 --- a/examples/ruby/Rakefile +++ /dev/null @@ -1,33 +0,0 @@ -require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper.rb")) - -namespace :test do - desc "Run continuous integration tests" - task :ci => :'ci:local' - namespace :ci do - require "spec" - require 'spec/rake/spectask' - - 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 - -desc "Run specs via server" -task :jasmine_server do - require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) - - puts "your tests are here:" - puts " http://localhost:8888/run.html" - - Jasmine::SimpleServer.start(8888, - lambda { JasmineHelper.specs }, - JasmineHelper.dir_mappings) -end diff --git a/examples/ruby/spec/example/example_spec.js b/examples/ruby/spec/example/example_spec.js deleted file mode 100644 index 494539e..0000000 --- a/examples/ruby/spec/example/example_spec.js +++ /dev/null @@ -1,11 +0,0 @@ -describe('ExampleSuite', function () { - it('should have a passing test', function() { - expect(true).toEqual(true); - }); - - describe('Nested Describe', function () { - it('should also have a passing test', function () { - expect(true).toEqual(true); - }); - }); -}); \ No newline at end of file diff --git a/examples/ruby/spec/jasmine_helper.rb b/examples/ruby/spec/jasmine_helper.rb deleted file mode 100644 index b19cd3a..0000000 --- a/examples/ruby/spec/jasmine_helper.rb +++ /dev/null @@ -1,41 +0,0 @@ -class JasmineHelper - def self.jasmine_lib_dir - File.expand_path(File.join(jasmine_root, 'lib')) - end - - def self.jasmine_root - File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..')) - end - - def self.jasmine - ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] + - ['/lib/json2.js', - '/lib/TrivialReporter.js', - '/lib/consolex.js' - ] - end - - def self.jasmine_src_dir - File.expand_path(File.join(jasmine_root, 'src')) - end - - def self.jasmine_spec_dir - File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec')) - end - - def self.raw_spec_files - Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js")) - end - - def self.specs - raw_spec_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")} - end - - def self.dir_mappings - { - "/src" => jasmine_src_dir, - "/spec" => jasmine_spec_dir, - "/lib" => jasmine_lib_dir - } - end -end diff --git a/examples/ruby/spec/jasmine_spec.rb b/examples/ruby/spec/jasmine_spec.rb deleted file mode 100644 index de4f09f..0000000 --- a/examples/ruby/spec/jasmine_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'rubygems' -require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb")) -require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) - -jasmine_runner = if ENV['SAUCELABS'] == 'true' - require 'sauce_tunnel' - require 'selenium_config' - Jasmine::SauceLabsRunner.new(JasmineHelper.specs, - JasmineHelper.dir_mappings, - :saucelabs_config => 'saucelabs', - :saucelabs_config_file => File.expand_path(File.join(File.dirname(__FILE__), "saucelabs.yml"))) -else - require "selenium_rc" - Jasmine::Runner.new(SeleniumRC::Server.new('localhost').jar_path, - JasmineHelper.specs, - JasmineHelper.dir_mappings) -end - -spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner) - -should_stop = false - -Spec::Runner.configure do |config| - config.after(:suite) do - spec_builder.stop if should_stop - end -end - -spec_builder.start -should_stop = true -spec_builder.declare_suites diff --git a/examples/ruby/spec/saucelabs.yml b/examples/ruby/spec/saucelabs.yml deleted file mode 100644 index 8a46d1c..0000000 --- a/examples/ruby/spec/saucelabs.yml +++ /dev/null @@ -1,24 +0,0 @@ -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/src/mock-timeout.js b/src/mock-timeout.js index 73b1720..f3e39cb 100755 --- a/src/mock-timeout.js +++ b/src/mock-timeout.js @@ -1,177 +1,177 @@ -// Mock setTimeout, clearTimeout -// Contributed by Pivotal Computer Systems, www.pivotalsf.com - -jasmine.FakeTimer = function() { - this.reset(); - - var self = this; - self.setTimeout = function(funcToCall, millis) { - self.timeoutsMade++; - self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); - return self.timeoutsMade; - }; - - self.setInterval = function(funcToCall, millis) { - self.timeoutsMade++; - self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); - return self.timeoutsMade; - }; - - self.clearTimeout = function(timeoutKey) { - self.scheduledFunctions[timeoutKey] = jasmine.undefined; - }; - - self.clearInterval = function(timeoutKey) { - self.scheduledFunctions[timeoutKey] = jasmine.undefined; - }; - -}; - -jasmine.FakeTimer.prototype.reset = function() { - this.timeoutsMade = 0; - this.scheduledFunctions = {}; - this.nowMillis = 0; -}; - -jasmine.FakeTimer.prototype.tick = function(millis) { - var oldMillis = this.nowMillis; - var newMillis = oldMillis + millis; - this.runFunctionsWithinRange(oldMillis, newMillis); - this.nowMillis = newMillis; -}; - -jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { - var scheduledFunc; - var funcsToRun = []; - for (var timeoutKey in this.scheduledFunctions) { - scheduledFunc = this.scheduledFunctions[timeoutKey]; - if (scheduledFunc != jasmine.undefined && - scheduledFunc.runAtMillis >= oldMillis && - scheduledFunc.runAtMillis <= nowMillis) { - funcsToRun.push(scheduledFunc); - this.scheduledFunctions[timeoutKey] = jasmine.undefined; - } - } - - if (funcsToRun.length > 0) { - funcsToRun.sort(function(a, b) { - return a.runAtMillis - b.runAtMillis; - }); - for (var i = 0; i < funcsToRun.length; ++i) { - try { - var funcToRun = funcsToRun[i]; - this.nowMillis = funcToRun.runAtMillis; - funcToRun.funcToCall(); - if (funcToRun.recurring) { - this.scheduleFunction(funcToRun.timeoutKey, - funcToRun.funcToCall, - funcToRun.millis, - true); - } - } catch(e) { - } - } - this.runFunctionsWithinRange(oldMillis, nowMillis); - } -}; - -jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { - this.scheduledFunctions[timeoutKey] = { - runAtMillis: this.nowMillis + millis, - funcToCall: funcToCall, - recurring: recurring, - timeoutKey: timeoutKey, - millis: millis - }; -}; - -/** - * @namespace - */ -jasmine.Clock = { - defaultFakeTimer: new jasmine.FakeTimer(), - - reset: function() { - jasmine.Clock.assertInstalled(); - jasmine.Clock.defaultFakeTimer.reset(); - }, - - tick: function(millis) { - jasmine.Clock.assertInstalled(); - jasmine.Clock.defaultFakeTimer.tick(millis); - }, - - runFunctionsWithinRange: function(oldMillis, nowMillis) { - jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); - }, - - scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { - jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); - }, - - useMock: function() { - var spec = jasmine.getEnv().currentSpec; - spec.after(jasmine.Clock.uninstallMock); - - jasmine.Clock.installMock(); - }, - - installMock: function() { - jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; - }, - - uninstallMock: function() { - jasmine.Clock.assertInstalled(); - jasmine.Clock.installed = jasmine.Clock.real; - }, - - real: { - setTimeout: window.setTimeout, - clearTimeout: window.clearTimeout, - setInterval: window.setInterval, - clearInterval: window.clearInterval - }, - - assertInstalled: function() { - if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { - throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); - } - }, - - installed: null -}; -jasmine.Clock.installed = jasmine.Clock.real; - -//else for IE support -window.setTimeout = function(funcToCall, millis) { - if (jasmine.Clock.installed.setTimeout.apply) { - return jasmine.Clock.installed.setTimeout.apply(this, arguments); - } else { - return jasmine.Clock.installed.setTimeout(funcToCall, millis); - } -}; - -window.setInterval = function(funcToCall, millis) { - if (jasmine.Clock.installed.setInterval.apply) { - return jasmine.Clock.installed.setInterval.apply(this, arguments); - } else { - return jasmine.Clock.installed.setInterval(funcToCall, millis); - } -}; - -window.clearTimeout = function(timeoutKey) { - if (jasmine.Clock.installed.clearTimeout.apply) { - return jasmine.Clock.installed.clearTimeout.apply(this, arguments); - } else { - return jasmine.Clock.installed.clearTimeout(timeoutKey); - } -}; - -window.clearInterval = function(timeoutKey) { - if (jasmine.Clock.installed.clearTimeout.apply) { - return jasmine.Clock.installed.clearInterval.apply(this, arguments); - } else { - return jasmine.Clock.installed.clearInterval(timeoutKey); - } -}; - +// Mock setTimeout, clearTimeout +// Contributed by Pivotal Computer Systems, www.pivotalsf.com + +jasmine.FakeTimer = function() { + this.reset(); + + var self = this; + self.setTimeout = function(funcToCall, millis) { + self.timeoutsMade++; + self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); + return self.timeoutsMade; + }; + + self.setInterval = function(funcToCall, millis) { + self.timeoutsMade++; + self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); + return self.timeoutsMade; + }; + + self.clearTimeout = function(timeoutKey) { + self.scheduledFunctions[timeoutKey] = jasmine.undefined; + }; + + self.clearInterval = function(timeoutKey) { + self.scheduledFunctions[timeoutKey] = jasmine.undefined; + }; + +}; + +jasmine.FakeTimer.prototype.reset = function() { + this.timeoutsMade = 0; + this.scheduledFunctions = {}; + this.nowMillis = 0; +}; + +jasmine.FakeTimer.prototype.tick = function(millis) { + var oldMillis = this.nowMillis; + var newMillis = oldMillis + millis; + this.runFunctionsWithinRange(oldMillis, newMillis); + this.nowMillis = newMillis; +}; + +jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { + var scheduledFunc; + var funcsToRun = []; + for (var timeoutKey in this.scheduledFunctions) { + scheduledFunc = this.scheduledFunctions[timeoutKey]; + if (scheduledFunc != jasmine.undefined && + scheduledFunc.runAtMillis >= oldMillis && + scheduledFunc.runAtMillis <= nowMillis) { + funcsToRun.push(scheduledFunc); + this.scheduledFunctions[timeoutKey] = jasmine.undefined; + } + } + + if (funcsToRun.length > 0) { + funcsToRun.sort(function(a, b) { + return a.runAtMillis - b.runAtMillis; + }); + for (var i = 0; i < funcsToRun.length; ++i) { + try { + var funcToRun = funcsToRun[i]; + this.nowMillis = funcToRun.runAtMillis; + funcToRun.funcToCall(); + if (funcToRun.recurring) { + this.scheduleFunction(funcToRun.timeoutKey, + funcToRun.funcToCall, + funcToRun.millis, + true); + } + } catch(e) { + } + } + this.runFunctionsWithinRange(oldMillis, nowMillis); + } +}; + +jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { + this.scheduledFunctions[timeoutKey] = { + runAtMillis: this.nowMillis + millis, + funcToCall: funcToCall, + recurring: recurring, + timeoutKey: timeoutKey, + millis: millis + }; +}; + +/** + * @namespace + */ +jasmine.Clock = { + defaultFakeTimer: new jasmine.FakeTimer(), + + reset: function() { + jasmine.Clock.assertInstalled(); + jasmine.Clock.defaultFakeTimer.reset(); + }, + + tick: function(millis) { + jasmine.Clock.assertInstalled(); + jasmine.Clock.defaultFakeTimer.tick(millis); + }, + + runFunctionsWithinRange: function(oldMillis, nowMillis) { + jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); + }, + + scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { + jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); + }, + + useMock: function() { + var spec = jasmine.getEnv().currentSpec; + spec.after(jasmine.Clock.uninstallMock); + + jasmine.Clock.installMock(); + }, + + installMock: function() { + jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; + }, + + uninstallMock: function() { + jasmine.Clock.assertInstalled(); + jasmine.Clock.installed = jasmine.Clock.real; + }, + + real: { + setTimeout: window.setTimeout, + clearTimeout: window.clearTimeout, + setInterval: window.setInterval, + clearInterval: window.clearInterval + }, + + assertInstalled: function() { + if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { + throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); + } + }, + + installed: null +}; +jasmine.Clock.installed = jasmine.Clock.real; + +//else for IE support +window.setTimeout = function(funcToCall, millis) { + if (jasmine.Clock.installed.setTimeout.apply) { + return jasmine.Clock.installed.setTimeout.apply(this, arguments); + } else { + return jasmine.Clock.installed.setTimeout(funcToCall, millis); + } +}; + +window.setInterval = function(funcToCall, millis) { + if (jasmine.Clock.installed.setInterval.apply) { + return jasmine.Clock.installed.setInterval.apply(this, arguments); + } else { + return jasmine.Clock.installed.setInterval(funcToCall, millis); + } +}; + +window.clearTimeout = function(timeoutKey) { + if (jasmine.Clock.installed.clearTimeout.apply) { + return jasmine.Clock.installed.clearTimeout.apply(this, arguments); + } else { + return jasmine.Clock.installed.clearTimeout(timeoutKey); + } +}; + +window.clearInterval = function(timeoutKey) { + if (jasmine.Clock.installed.clearTimeout.apply) { + return jasmine.Clock.installed.clearInterval.apply(this, arguments); + } else { + return jasmine.Clock.installed.clearInterval(timeoutKey); + } +}; +