New example project.

Generate jasmine-standalone-x.x.x.zip.
This commit is contained in:
Lee Byrd & Christian Williams 2010-06-24 17:15:06 -07:00
parent 22065fafad
commit 1057596665
9 changed files with 174 additions and 45 deletions

View File

@ -6,7 +6,7 @@ Quick Start
----------
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.
2. Open `SpecRunner.html` in your favorite browser.
For running within a Ruby environment, including automated execution with Selenium, please use
the [jasmine gem](http://github.com/pivotal/jasmine-gem).

View File

@ -6,12 +6,17 @@ def jasmine_sources
sources
end
def jasmine_filename(version)
"jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js"
def jasmine_filename
"jasmine-#{jasmine_version}.js"
end
def jasmine_version
"#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
end
def version_hash
JSON.parse(File.new("src/version.json").read);
require 'json'
@version ||= JSON.parse(File.new("src/version.json").read);
end
def start_jasmine_server(jasmine_includes = nil)
@ -29,10 +34,16 @@ end
task :default => 'jasmine:dist'
def substitute_jasmine_version(filename)
contents = File.read(filename)
contents = contents.gsub(/##JASMINE_VERSION##/, (jasmine_version))
File.open(filename, 'w') { |f| f.write(contents) }
end
namespace :jasmine do
desc 'Prepares for distribution'
task :dist => ['jasmine:build', 'jasmine:doc']
task :dist => ['jasmine:build', 'jasmine:doc', 'jasmine:build_example_project']
desc 'Check jasmine sources for coding problems'
task :lint do
@ -63,7 +74,6 @@ namespace :jasmine do
desc 'Builds lib/jasmine from source'
task :build => :lint do
puts 'Building Jasmine from source'
require 'json'
sources = jasmine_sources
version = version_hash
@ -106,6 +116,35 @@ jasmine.version_= {
Rake::Task[:lambda_jsdoc].invoke
end
desc "Build example project"
task :build_example_project do
require 'tmpdir'
temp_dir = File.join(Dir.tmpdir, 'jasmine-standalone-project')
puts "Building Example Project in #{temp_dir}"
FileUtils.rm_r temp_dir if File.exists?(temp_dir)
Dir.mkdir(temp_dir)
root = JasmineHelper.jasmine_root
FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir)
substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html"))
lib_dir = File.join(temp_dir, "lib/jasmine-#{jasmine_version}")
FileUtils.mkdir_p(lib_dir)
[
"jasmine.js",
"TrivialReporter.js",
"jasmine.css"
].each do |f|
FileUtils.cp(File.join(root, 'lib', f), File.join(lib_dir, f))
end
dist = File.join(root, 'dist')
FileUtils.rm_r dist if File.exists?(dist)
Dir.mkdir(dist)
exec "cd #{temp_dir} && zip -r #{File.join(dist, "jasmine-standalone-#{jasmine_version}.zip")} ."
end
task :server do
files = jasmine_sources + ['lib/TrivialReporter.js', 'lib/consolex.js']

27
example/SpecRunner.html Normal file
View File

@ -0,0 +1,27 @@
<!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>
<link rel="stylesheet" type="text/css" href="lib/jasmine-##JASMINE_VERSION##/jasmine.css">
<script type="text/javascript" src="lib/jasmine-##JASMINE_VERSION##/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-##JASMINE_VERSION##/TrivialReporter.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="src/Player.js"></script>
<script type="text/javascript" src="src/Song.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@ -1,22 +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>
<link rel="stylesheet" type="text/css" href="../lib/jasmine.css">
<script type="text/javascript" src="../lib/jasmine.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>
</head>
<body>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
jasmineEnv.reporter = new jasmine.TrivialReporter();
jasmineEnv.execute();
</script>
</body>
</html>

View File

@ -0,0 +1,58 @@
describe("Player", function() {
var player;
var song;
beforeEach(function() {
player = new Player();
song = new Song();
});
it("should be able to play a Song", function() {
player.play(song);
expect(player.currentlyPlayingSong).toEqual(song);
//demonstrates use of custom matcher
expect(player).toBePlaying(song);
});
describe("when song has been paused", function() {
beforeEach(function() {
player.play(song);
player.pause();
});
it("should indicate that the song is currently paused", function() {
expect(player.isPlaying).toBeFalsy();
// demonstrates use of 'not' with a custom matcher
expect(player).not.toBePlaying(song);
});
it("should be possible to resume", function() {
player.resume();
expect(player.isPlaying).toBeTruthy();
expect(player.currentlyPlayingSong).toEqual(song);
});
});
// demonstrates use of spies to intercept and test method calls
it("tells the current song if the user has made it a favorite", function() {
spyOn(song, 'persistFavoriteStatus');
player.play(song);
player.makeFavorite();
expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
});
//demonstrates use of expected exceptions
describe("#resume", function() {
it("should throw an exception if song is already playing", function() {
player.play(song);
expect(function() {
player.resume();
}).toThrow("song is already playing");
});
});
});

View File

@ -0,0 +1,9 @@
beforeEach(function() {
this.addMatchers({
toBePlaying: function(expectedSong) {
var player = this.actual;
return player.currentlyPlayingSong === expectedSong
&& player.isPlaying;
}
})
});

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

22
example/src/Player.js Normal file
View File

@ -0,0 +1,22 @@
function Player() {
}
Player.prototype.play = function(song) {
this.currentlyPlayingSong = song;
this.isPlaying = true;
};
Player.prototype.pause = function() {
this.isPlaying = false;
};
Player.prototype.resume = function() {
if (this.isPlaying) {
throw new Error("song is already playing");
}
this.isPlaying = true;
};
Player.prototype.makeFavorite = function() {
this.currentlyPlayingSong.persistFavoriteStatus(true);
};

7
example/src/Song.js Normal file
View File

@ -0,0 +1,7 @@
function Song() {
}
Song.prototype.persistFavoriteStatus = function(value) {
// something complicated
throw new Error("not yet implemented");
};