Documentation and example fixes

This commit is contained in:
bigfix 2010-04-20 07:26:04 -07:00 committed by ragaskar
parent 9f8d18b6b7
commit 5cfb019b6b
10 changed files with 205 additions and 361 deletions

View File

@ -5,24 +5,11 @@ Jasmine
Quick Start 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. For running within a Ruby environment, including automated execution with Selenium, please use
the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby).
### 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
Releases Releases
---------- ----------

View File

@ -0,0 +1,24 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
</head>
<script type="text/javascript" src="../lib/jasmine-0.10.3.js"></script>
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
<script type="text/javascript" src="../lib/consolex.js"></script>
<script type="text/javascript" src="spec/example_suite.js"></script>
<link rel="stylesheet" type="text/css" href="../lib/jasmine.css">
<body>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
jasmineEnv.reporter = new jasmine.TrivialReporter();
jasmineEnv.execute();
</script>
</body>
</html>

View File

@ -1,27 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
</head>
<script type="text/javascript" src="../../lib/jasmine-0.10.1.js"></script>
<script type="text/javascript" src="../../lib/TrivialReporter.js"></script>
<script type="text/javascript" src="../../lib/consolex.js"></script>
<link rel="stylesheet" type="text/css" href="../../lib/jasmine.css">
<script type="text/javascript">
jasmine.include('spec/example_suite.js', true);
</script>
<body>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
jasmineEnv.reporter = new jasmine.TrivialReporter();
jasmineEnv.execute();
</script>
</body>
</html>

View File

@ -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

View File

@ -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);
});
});
});

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -1,177 +1,177 @@
// Mock setTimeout, clearTimeout // Mock setTimeout, clearTimeout
// Contributed by Pivotal Computer Systems, www.pivotalsf.com // Contributed by Pivotal Computer Systems, www.pivotalsf.com
jasmine.FakeTimer = function() { jasmine.FakeTimer = function() {
this.reset(); this.reset();
var self = this; var self = this;
self.setTimeout = function(funcToCall, millis) { self.setTimeout = function(funcToCall, millis) {
self.timeoutsMade++; self.timeoutsMade++;
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
return self.timeoutsMade; return self.timeoutsMade;
}; };
self.setInterval = function(funcToCall, millis) { self.setInterval = function(funcToCall, millis) {
self.timeoutsMade++; self.timeoutsMade++;
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
return self.timeoutsMade; return self.timeoutsMade;
}; };
self.clearTimeout = function(timeoutKey) { self.clearTimeout = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = jasmine.undefined; self.scheduledFunctions[timeoutKey] = jasmine.undefined;
}; };
self.clearInterval = function(timeoutKey) { self.clearInterval = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = jasmine.undefined; self.scheduledFunctions[timeoutKey] = jasmine.undefined;
}; };
}; };
jasmine.FakeTimer.prototype.reset = function() { jasmine.FakeTimer.prototype.reset = function() {
this.timeoutsMade = 0; this.timeoutsMade = 0;
this.scheduledFunctions = {}; this.scheduledFunctions = {};
this.nowMillis = 0; this.nowMillis = 0;
}; };
jasmine.FakeTimer.prototype.tick = function(millis) { jasmine.FakeTimer.prototype.tick = function(millis) {
var oldMillis = this.nowMillis; var oldMillis = this.nowMillis;
var newMillis = oldMillis + millis; var newMillis = oldMillis + millis;
this.runFunctionsWithinRange(oldMillis, newMillis); this.runFunctionsWithinRange(oldMillis, newMillis);
this.nowMillis = newMillis; this.nowMillis = newMillis;
}; };
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
var scheduledFunc; var scheduledFunc;
var funcsToRun = []; var funcsToRun = [];
for (var timeoutKey in this.scheduledFunctions) { for (var timeoutKey in this.scheduledFunctions) {
scheduledFunc = this.scheduledFunctions[timeoutKey]; scheduledFunc = this.scheduledFunctions[timeoutKey];
if (scheduledFunc != jasmine.undefined && if (scheduledFunc != jasmine.undefined &&
scheduledFunc.runAtMillis >= oldMillis && scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) { scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc); funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = jasmine.undefined; this.scheduledFunctions[timeoutKey] = jasmine.undefined;
} }
} }
if (funcsToRun.length > 0) { if (funcsToRun.length > 0) {
funcsToRun.sort(function(a, b) { funcsToRun.sort(function(a, b) {
return a.runAtMillis - b.runAtMillis; return a.runAtMillis - b.runAtMillis;
}); });
for (var i = 0; i < funcsToRun.length; ++i) { for (var i = 0; i < funcsToRun.length; ++i) {
try { try {
var funcToRun = funcsToRun[i]; var funcToRun = funcsToRun[i];
this.nowMillis = funcToRun.runAtMillis; this.nowMillis = funcToRun.runAtMillis;
funcToRun.funcToCall(); funcToRun.funcToCall();
if (funcToRun.recurring) { if (funcToRun.recurring) {
this.scheduleFunction(funcToRun.timeoutKey, this.scheduleFunction(funcToRun.timeoutKey,
funcToRun.funcToCall, funcToRun.funcToCall,
funcToRun.millis, funcToRun.millis,
true); true);
} }
} catch(e) { } catch(e) {
} }
} }
this.runFunctionsWithinRange(oldMillis, nowMillis); this.runFunctionsWithinRange(oldMillis, nowMillis);
} }
}; };
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
this.scheduledFunctions[timeoutKey] = { this.scheduledFunctions[timeoutKey] = {
runAtMillis: this.nowMillis + millis, runAtMillis: this.nowMillis + millis,
funcToCall: funcToCall, funcToCall: funcToCall,
recurring: recurring, recurring: recurring,
timeoutKey: timeoutKey, timeoutKey: timeoutKey,
millis: millis millis: millis
}; };
}; };
/** /**
* @namespace * @namespace
*/ */
jasmine.Clock = { jasmine.Clock = {
defaultFakeTimer: new jasmine.FakeTimer(), defaultFakeTimer: new jasmine.FakeTimer(),
reset: function() { reset: function() {
jasmine.Clock.assertInstalled(); jasmine.Clock.assertInstalled();
jasmine.Clock.defaultFakeTimer.reset(); jasmine.Clock.defaultFakeTimer.reset();
}, },
tick: function(millis) { tick: function(millis) {
jasmine.Clock.assertInstalled(); jasmine.Clock.assertInstalled();
jasmine.Clock.defaultFakeTimer.tick(millis); jasmine.Clock.defaultFakeTimer.tick(millis);
}, },
runFunctionsWithinRange: function(oldMillis, nowMillis) { runFunctionsWithinRange: function(oldMillis, nowMillis) {
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
}, },
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
}, },
useMock: function() { useMock: function() {
var spec = jasmine.getEnv().currentSpec; var spec = jasmine.getEnv().currentSpec;
spec.after(jasmine.Clock.uninstallMock); spec.after(jasmine.Clock.uninstallMock);
jasmine.Clock.installMock(); jasmine.Clock.installMock();
}, },
installMock: function() { installMock: function() {
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
}, },
uninstallMock: function() { uninstallMock: function() {
jasmine.Clock.assertInstalled(); jasmine.Clock.assertInstalled();
jasmine.Clock.installed = jasmine.Clock.real; jasmine.Clock.installed = jasmine.Clock.real;
}, },
real: { real: {
setTimeout: window.setTimeout, setTimeout: window.setTimeout,
clearTimeout: window.clearTimeout, clearTimeout: window.clearTimeout,
setInterval: window.setInterval, setInterval: window.setInterval,
clearInterval: window.clearInterval clearInterval: window.clearInterval
}, },
assertInstalled: function() { assertInstalled: function() {
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
} }
}, },
installed: null installed: null
}; };
jasmine.Clock.installed = jasmine.Clock.real; jasmine.Clock.installed = jasmine.Clock.real;
//else for IE support //else for IE support
window.setTimeout = function(funcToCall, millis) { window.setTimeout = function(funcToCall, millis) {
if (jasmine.Clock.installed.setTimeout.apply) { if (jasmine.Clock.installed.setTimeout.apply) {
return jasmine.Clock.installed.setTimeout.apply(this, arguments); return jasmine.Clock.installed.setTimeout.apply(this, arguments);
} else { } else {
return jasmine.Clock.installed.setTimeout(funcToCall, millis); return jasmine.Clock.installed.setTimeout(funcToCall, millis);
} }
}; };
window.setInterval = function(funcToCall, millis) { window.setInterval = function(funcToCall, millis) {
if (jasmine.Clock.installed.setInterval.apply) { if (jasmine.Clock.installed.setInterval.apply) {
return jasmine.Clock.installed.setInterval.apply(this, arguments); return jasmine.Clock.installed.setInterval.apply(this, arguments);
} else { } else {
return jasmine.Clock.installed.setInterval(funcToCall, millis); return jasmine.Clock.installed.setInterval(funcToCall, millis);
} }
}; };
window.clearTimeout = function(timeoutKey) { window.clearTimeout = function(timeoutKey) {
if (jasmine.Clock.installed.clearTimeout.apply) { if (jasmine.Clock.installed.clearTimeout.apply) {
return jasmine.Clock.installed.clearTimeout.apply(this, arguments); return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
} else { } else {
return jasmine.Clock.installed.clearTimeout(timeoutKey); return jasmine.Clock.installed.clearTimeout(timeoutKey);
} }
}; };
window.clearInterval = function(timeoutKey) { window.clearInterval = function(timeoutKey) {
if (jasmine.Clock.installed.clearTimeout.apply) { if (jasmine.Clock.installed.clearTimeout.apply) {
return jasmine.Clock.installed.clearInterval.apply(this, arguments); return jasmine.Clock.installed.clearInterval.apply(this, arguments);
} else { } else {
return jasmine.Clock.installed.clearInterval(timeoutKey); return jasmine.Clock.installed.clearInterval(timeoutKey);
} }
}; };