Compare commits
104 Commits
1.0.1-rele
...
v1.1.0.rc3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a075c75bce | ||
|
|
a617b59e6a | ||
|
|
917b37481e | ||
|
|
67bbc98faa | ||
|
|
620f7b6e4c | ||
|
|
b722f416c7 | ||
|
|
634a7dc402 | ||
|
|
a4522e4dce | ||
|
|
e113c338d0 | ||
|
|
b81f690a25 | ||
|
|
c06e189699 | ||
|
|
67b6cfb828 | ||
|
|
57e622fb2a | ||
|
|
c0664dd6aa | ||
|
|
b640ce6fc0 | ||
|
|
e9af7834f5 | ||
|
|
0d43ae9c38 | ||
|
|
30431a3958 | ||
|
|
3775919c92 | ||
|
|
a692ff8c95 | ||
|
|
e4e9b51544 | ||
|
|
0b97951766 | ||
|
|
75dd391d57 | ||
|
|
ae24e00c0f | ||
|
|
6b2e45eab5 | ||
|
|
e59171935f | ||
|
|
2ba0aa371c | ||
|
|
c2ed71717f | ||
|
|
09e8822107 | ||
|
|
15763c2eb0 | ||
|
|
3f264cde34 | ||
|
|
f83cb7f766 | ||
|
|
9d5470ff55 | ||
|
|
86b095e5a4 | ||
|
|
4c6dafa3f5 | ||
|
|
3f4adf7715 | ||
|
|
af7f1818b0 | ||
|
|
12f56787b0 | ||
|
|
e88d88e427 | ||
|
|
ba10d178b2 | ||
|
|
da297d0f56 | ||
|
|
7ead5388c2 | ||
|
|
a445a62e7c | ||
|
|
1d65d56a92 | ||
|
|
d875d1d997 | ||
|
|
1fae8f0a31 | ||
|
|
c1f8151bcb | ||
|
|
bd8a3baed1 | ||
|
|
118324b451 | ||
|
|
c30f7d1aa7 | ||
|
|
de7be4b316 | ||
|
|
b02aa9840a | ||
|
|
61de2268fe | ||
|
|
dd32048383 | ||
|
|
32e736aa47 | ||
|
|
38e9af8f68 | ||
|
|
e826fbb170 | ||
|
|
0c77662c5b | ||
|
|
75fb19bc49 | ||
|
|
6ec825f62d | ||
|
|
fc994108db | ||
|
|
70aed2d900 | ||
|
|
ccfa17499f | ||
|
|
ab087ef5f8 | ||
|
|
0ef6582f73 | ||
|
|
a1ba43c864 | ||
|
|
88ee377662 | ||
|
|
f5afe18a6b | ||
|
|
2731716ccb | ||
|
|
4e5083d570 | ||
|
|
b9cbd3c5a0 | ||
|
|
e42026ee84 | ||
|
|
a1f58f8be4 | ||
|
|
ac00d765d2 | ||
|
|
b1dceeacd4 | ||
|
|
5018f0d1c2 | ||
|
|
9704550b33 | ||
|
|
882c287191 | ||
|
|
7d2b900b48 | ||
|
|
f701fdc132 | ||
|
|
eb49fab652 | ||
|
|
e8c8a0bdfd | ||
|
|
e6a080039f | ||
|
|
c485c33a3c | ||
|
|
8fbf3ba859 | ||
|
|
dccafe33b0 | ||
|
|
c1d2718bea | ||
|
|
945a9ba638 | ||
|
|
528b5abeda | ||
|
|
d7cced2e7c | ||
|
|
3be0610572 | ||
|
|
5e90115eaf | ||
|
|
148317eb90 | ||
|
|
45b4e1316c | ||
|
|
aee4c5926c | ||
|
|
f41af6c2d0 | ||
|
|
9f90c4eca5 | ||
|
|
545752ae20 | ||
|
|
c04f1b1fa8 | ||
|
|
fa9741dbda | ||
|
|
560cb2edcb | ||
|
|
9a12b32a3a | ||
|
|
bd15ed6a45 | ||
|
|
fa74051071 |
10
.gitignore
vendored
@@ -1,6 +1,12 @@
|
||||
.idea/
|
||||
.svn/
|
||||
.DS_Store
|
||||
_site/
|
||||
site/
|
||||
.bundle/
|
||||
.pairs
|
||||
.pairs
|
||||
.rvmrc
|
||||
*.gem
|
||||
.bundle
|
||||
tags
|
||||
Gemfile.lock
|
||||
pkg/*
|
||||
|
||||
44
Contribute.markdown
Normal file
@@ -0,0 +1,44 @@
|
||||
# Developing for Jasmine Core
|
||||
|
||||
## How to Contribute
|
||||
|
||||
We welcome your contributions - Thanks for helping make Jasmine a better project for everyone. Please review the backlog and discussion lists (the main group - [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js) and the developer's list - [http://groups.google.com/group/jasmine-js-dev](http://groups.google.com/group/jasmine-js-dev)) before starting work - what you're looking for may already have been done. If it hasn't, the community can help make your contribution better.
|
||||
|
||||
## How to write new Jasmine code
|
||||
|
||||
Or, How to make a successful pull request
|
||||
|
||||
* _Do not change the public interface_. Lots of projects depend on Jasmine and if you aren't careful you'll break them
|
||||
* _Be environment agnostic_ - server-side developers are just as important as browser developers
|
||||
* _Be browser agnostic_ - if you must rely on browser-specific functionality, please write it in a way that degrades gracefully
|
||||
* _Write specs_ - Jasmine's a testing framework; don't add functionality without test-driving it
|
||||
* _Ensure the *entire* test suite is green_ in all the big browsers, Node, and JSHint - your contribution shouldn't break Jasmine for other users
|
||||
|
||||
Follow these tips and your pull request, patch, or suggestion is much more likely to be integrated.
|
||||
|
||||
## Environment
|
||||
|
||||
Ruby, RubyGems and Rake are used in order to script the various file interactions. You will need to run on a system that supports Ruby in order to run Jasmine's specs.
|
||||
|
||||
Node.js is used to run most of the specs (the HTML-independent code) and should be present. Additionally, the JS Hint project scrubs the source code as part of the spec process.
|
||||
|
||||
## Development
|
||||
|
||||
All source code belongs in `src/`. The `core/` directory contains the bulk of Jasmine's functionality. This code should remain browser- and environment-agnostic. If your feature or fix cannot be, as mentioned above, please degrade gracefully. Any code that should only be in a non-browser environment should live in `src/console/`. Any code that depends on a browser (specifically, it expects `window` to be the global or `document` is present) should live in `src/html/`.
|
||||
|
||||
Please respect the code patterns as possible. For example, using `jasmine.getGlobal()` to get the global object so as to remain environment agnostic.
|
||||
|
||||
## Running Specs
|
||||
|
||||
As in all good projects, the `spec/` directory mirrors `src/` and follows the same rules. The browser runner will include and attempt to run all specs. The node runner will exclude any html-dependent specs (those in `spec/html/`).
|
||||
|
||||
You will notice that all specs are run against the built `jasmine.js` instead of the component source files. This is intentional as a way to ensure that the concatenation code is working correctly.
|
||||
|
||||
Please ensure all specs are green before committing.
|
||||
|
||||
There are rake tasks to help with getting green:
|
||||
* `rake spec` outputs the expected number of specs that should be run and attempts to run in browser and Node
|
||||
* `rake spec:browser` opens `spec/runner.html` in the default browser on MacOS. Please run this in at least Firefox and Chrome before committing
|
||||
* `rake spec:node` runs all the Jasmine specs in Node.js - it will complain if Node is not installed
|
||||
* `rake hint` runs all the files through JSHint and will complain about potential viable issues with your code. Fix them.
|
||||
|
||||
10
Gemfile
@@ -1,6 +1,4 @@
|
||||
source :gemcutter
|
||||
|
||||
gem "jekyll", "0.6.2"
|
||||
gem "json_pure", "~>1.4.3"
|
||||
gem "ragaskar-jsdoc_helper"
|
||||
gem "rake", "0.8.7"
|
||||
source :rubygems
|
||||
gem "term-ansicolor", :require => "term/ansicolor"
|
||||
gem "rake"
|
||||
gemspec
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2008-2010 Pivotal Labs
|
||||
Copyright (c) 2008-2011 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -2,27 +2,30 @@
|
||||
=======
|
||||
**A JavaScript Testing Framework**
|
||||
|
||||
Want to use Jasmine in a project? Go HERE: [http://pivotal.github.com/jasmine/](http://pivotal.github.com/jasmine/)
|
||||
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
|
||||
|
||||
Documentation & guides live here: [http://pivotal.github.com/jasmine/](http://pivotal.github.com/jasmine/)
|
||||
|
||||
## What's Here?
|
||||
|
||||
*
|
||||
|
||||
|
||||
Want to contribute to Jasmine? Read on...
|
||||
|
||||
<i>(More developer docs to come...)</i>
|
||||
|
||||
## Support
|
||||
We now have a Google Group for support & discussion.
|
||||
|
||||
* Discussion: [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)
|
||||
* Pivotal Tracker project: [http://www.pivotaltracker.com/projects/10606](http://www.pivotaltracker.com/projects/10606)
|
||||
* Twitter: [@JasmineBDD](http://twitter.com/JasmineBDD)
|
||||
* Search past discussions: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js)
|
||||
* Send an email to the list: [jasmine-js@googlegroups.com](jasmine-js@googlegroups.com)
|
||||
* Check the current build status: [ci.pivotallabs.com](http://ci.pivotallabs.com)
|
||||
* View the project backlog at Pivotal Tracker: [http://www.pivotaltracker.com/projects/10606](http://www.pivotaltracker.com/projects/10606)
|
||||
* Follow us on Twitter: [@JasmineBDD](http://twitter.com/JasmineBDD)
|
||||
|
||||
|
||||
## 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
|
||||
* [Christian Williams](mailto:antixian666@gmail.com), Square
|
||||
|
||||
## Developers
|
||||
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.
|
||||
|
||||
Copyright (c) 2008-2010 Pivotal Labs. This software is licensed under the MIT License.
|
||||
Copyright (c) 2008-2011 Pivotal Labs. This software is licensed under the MIT License.
|
||||
|
||||
191
Rakefile
@@ -1,182 +1,33 @@
|
||||
def jasmine_sources
|
||||
sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
|
||||
sources += Dir.glob('src/*.js').reject { |f| f == 'src/base.js' || sources.include?(f) }.sort
|
||||
sources
|
||||
require "bundler"
|
||||
Bundler::GemHelper.install_tasks
|
||||
require "term/ansicolor"
|
||||
require "json"
|
||||
require "tilt"
|
||||
|
||||
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rb"].each do |file|
|
||||
require file
|
||||
end
|
||||
|
||||
def jasmine_html_sources
|
||||
["src/html/TrivialReporter.js"]
|
||||
task :default => :spec
|
||||
|
||||
task :require_pages_submodule do
|
||||
raise "Submodule for Github Pages isn't present. Run git submodule update --init" unless pages_submodule_present
|
||||
end
|
||||
|
||||
def jasmine_version
|
||||
"#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
|
||||
task :require_node do
|
||||
raise "\nNode.js is required to develop code for Jasmine. Please visit http://nodejs.org to install.\n\n" unless node_installed?
|
||||
end
|
||||
|
||||
def version_hash
|
||||
require 'json'
|
||||
@version ||= JSON.parse(File.new("src/version.json").read);
|
||||
def pages_submodule_present
|
||||
File.exist?('pages/download.html')
|
||||
end
|
||||
|
||||
task :default => 'jasmine:dist'
|
||||
|
||||
def substitute_jasmine_version(filename)
|
||||
contents = File.read(filename)
|
||||
contents = contents.gsub(/##JASMINE_VERSION##/, (jasmine_version))
|
||||
contents = contents.gsub(/[^\n]*REMOVE_THIS_LINE_FROM_BUILD[^\n]*/, '')
|
||||
File.open(filename, 'w') { |f| f.write(contents) }
|
||||
def node_installed?
|
||||
`which node` =~ /node/
|
||||
end
|
||||
|
||||
namespace :jasmine do
|
||||
|
||||
desc 'Prepares for distribution'
|
||||
task :dist => ['jasmine:build', 'jasmine:doc', 'jasmine:build_example_project', 'jasmine:fill_index_downloads']
|
||||
|
||||
desc 'Check jasmine sources for coding problems'
|
||||
task :lint do
|
||||
passed = true
|
||||
jasmine_sources.each do |src|
|
||||
lines = File.read(src).split(/\n/)
|
||||
lines.each_index do |i|
|
||||
line = lines[i]
|
||||
undefineds = line.scan(/.?undefined/)
|
||||
if undefineds.include?(" undefined") || undefineds.include?("\tundefined")
|
||||
puts "Dangerous undefined at #{src}:#{i}:\n > #{line}"
|
||||
passed = false
|
||||
end
|
||||
|
||||
if line.scan(/window/).length > 0
|
||||
puts "Dangerous window at #{src}:#{i}:\n > #{line}"
|
||||
passed = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless passed
|
||||
puts "Lint failed!"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Builds lib/jasmine from source'
|
||||
task :build => :lint do
|
||||
puts 'Building Jasmine from source'
|
||||
|
||||
sources = jasmine_sources
|
||||
version = version_hash
|
||||
|
||||
old_jasmine_files = Dir.glob('lib/jasmine*.js')
|
||||
old_jasmine_files.each { |file| File.delete(file) }
|
||||
|
||||
File.open("lib/jasmine.js", 'w') do |jasmine|
|
||||
sources.each do |source_filename|
|
||||
jasmine.puts(File.read(source_filename))
|
||||
end
|
||||
|
||||
jasmine.puts %{
|
||||
jasmine.version_= {
|
||||
"major": #{version['major'].to_json},
|
||||
"minor": #{version['minor'].to_json},
|
||||
"build": #{version['build'].to_json},
|
||||
"revision": #{Time.now.to_i}
|
||||
};
|
||||
}
|
||||
end
|
||||
|
||||
File.open("lib/jasmine-html.js", 'w') do |jasmine_html|
|
||||
jasmine_html_sources.each do |source_filename|
|
||||
jasmine_html.puts(File.read(source_filename))
|
||||
end
|
||||
end
|
||||
|
||||
FileUtils.cp("src/html/jasmine.css", "lib/jasmine.css")
|
||||
end
|
||||
|
||||
downloads_file = 'pages/download.html.md'
|
||||
task :need_pages_submodule do
|
||||
unless File.exists?(downloads_file)
|
||||
raise "Jasmine pages submodule isn't present. Run git submodule update --init"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Build jasmine documentation"
|
||||
task :doc => :need_pages_submodule do
|
||||
puts 'Creating Jasmine Documentation'
|
||||
require 'rubygems'
|
||||
require 'jsdoc_helper'
|
||||
|
||||
FileUtils.rm_r "pages/jsdoc", :force => true
|
||||
|
||||
JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
|
||||
t[:files] = jasmine_sources << jasmine_html_sources
|
||||
t[:options] = "-a"
|
||||
t[:out] = "pages/jsdoc"
|
||||
# JsdocHelper bug: template must be relative to the JsdocHelper gem, ick
|
||||
t[:template] = File.join("../".*(100), Dir::getwd, "jsdoc-template")
|
||||
end
|
||||
Rake::Task[:lambda_jsdoc].invoke
|
||||
end
|
||||
|
||||
desc "Build example project"
|
||||
task :build_example_project => :need_pages_submodule 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 = File.expand_path(File.dirname(__FILE__))
|
||||
FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir)
|
||||
substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html"))
|
||||
|
||||
lib_dir = File.join(temp_dir, "lib/jasmine-#{jasmine_version}")
|
||||
FileUtils.mkdir_p(lib_dir)
|
||||
{
|
||||
"lib/jasmine.js" => "jasmine.js",
|
||||
"lib/jasmine-html.js" => "jasmine-html.js",
|
||||
"src/html/jasmine.css" => "jasmine.css",
|
||||
"MIT.LICENSE" => "MIT.LICENSE"
|
||||
}.each_pair do |src, dest|
|
||||
FileUtils.cp(File.join(root, src), File.join(lib_dir, dest))
|
||||
end
|
||||
|
||||
dist_dir = File.join(root, 'pages/downloads')
|
||||
zip_file_name = File.join(dist_dir, "jasmine-standalone-#{jasmine_version}.zip")
|
||||
puts "Zipping Example Project and moving to #{zip_file_name}"
|
||||
FileUtils.mkdir(dist_dir) unless File.exist?(dist_dir)
|
||||
if File.exist?(zip_file_name)
|
||||
puts "WARNING!!! #{zip_file_name} already exists!"
|
||||
FileUtils.rm(zip_file_name)
|
||||
end
|
||||
exec "cd #{temp_dir} && zip -r #{zip_file_name} . -x .[a-zA-Z0-9]*"
|
||||
end
|
||||
|
||||
task :fill_index_downloads do
|
||||
require 'digest/sha1'
|
||||
|
||||
download_html = "<!-- START_DOWNLOADS -->\n"
|
||||
Dir.glob('pages/downloads/*.zip').sort.reverse.each do |f|
|
||||
sha1 = Digest::SHA1.hexdigest File.read(f)
|
||||
|
||||
fn = f.sub(/^pages\//, '')
|
||||
version = /jasmine-standalone-(.*).zip/.match(f)[1]
|
||||
prerelease = /\.rc/.match(f)
|
||||
download_html += prerelease ? "<tr class=\"rc\">\n" : "<tr>\n"
|
||||
download_html += " <td class=\"link\"><a href=\"#{fn}\">#{fn.sub(/downloads\//, '')}</a></td>\n"
|
||||
download_html += " <td class=\"version\">#{version}</td>\n"
|
||||
download_html += " <td class=\"size\">#{File.size(f) / 1024}k</td>\n"
|
||||
download_html += " <td class=\"date\">#{File.mtime(f).strftime("%Y/%m/%d %H:%M:%S %Z")}</td>\n"
|
||||
download_html += " <td class=\"sha\">#{sha1}</td>\n"
|
||||
download_html += "</tr>\n"
|
||||
end
|
||||
download_html += "<!-- END_DOWNLOADS -->"
|
||||
|
||||
downloads_page = File.read(downloads_file)
|
||||
matcher = /<!-- START_DOWNLOADS -->.*<!-- END_DOWNLOADS -->/m
|
||||
downloads_page = downloads_page.sub(matcher, download_html)
|
||||
File.open(downloads_file, 'w') {|f| f.write(downloads_page)}
|
||||
puts "rewrote that file"
|
||||
end
|
||||
class String
|
||||
include Term::ANSIColor
|
||||
end
|
||||
|
||||
task :jasmine => ['jasmine:dist']
|
||||
Term::ANSIColor.coloring = STDOUT.isatty
|
||||
|
||||
40
Release.markdown
Normal file
@@ -0,0 +1,40 @@
|
||||
# How to work on a Jasmine Release
|
||||
|
||||
## Development
|
||||
___Jasmine Core Maintainers Only___
|
||||
|
||||
Follow the instructions in `Contribute.markdown` during development.
|
||||
|
||||
### Git Commits
|
||||
|
||||
|
||||
### Version
|
||||
|
||||
We attempt to stick to [Semantic Versioning](). Most of the time, development should be against a new minor version - fixing bugs and adding new features that are backwards compatible.
|
||||
|
||||
The current version lives in the file `src/version.json`. This file should be set to the version that is _currently_ under development. That is, if version 1.0.0 is the current release then version should be incremented say, to 1.1.0.
|
||||
|
||||
This version is used by both `jasmine.js` and the `jasmine-core` Ruby gem.
|
||||
|
||||
|
||||
### Update the Github Pages (as needed)
|
||||
|
||||
Github pages have to exist in a branch called gh-pages in order for their app to serve them. This repo adds that branch as a submodule under the `pages` directory. This is a bit of a hack, but it allows us to work with the pages and the source at the same time and with one set of rake tasks.
|
||||
|
||||
If you want to submit changes to this repo and aren't a Pivotal Labs employee, you can fork and work in the `gh-pages` branch. You won't be able to edit the pages in the submodule off of master.
|
||||
|
||||
The pages are built with [Frank](https://github.com/blahed/frank). All the source for these pages live in the `pages/pages_source` directory.
|
||||
|
||||
## Release
|
||||
|
||||
When ready to release - specs are all green and the stories are done:
|
||||
|
||||
1. Update the version in `version.json` to a release candidate - add an `rc` property with a value of 1
|
||||
1. Update any comments on the public interfaces
|
||||
1. `rake doc` - builds the `jsdoc` pages
|
||||
1. Update any links or top-level landing page for the Github Pages
|
||||
1. `rake standalone` - builds the standalone distribution ZIP file
|
||||
1. `rake build_pages` - builds the Github Pages
|
||||
1. `rake release` - tags the repo with the version, builds the `jasmine-core` gem, pushes the gem to Rubygems.org
|
||||
|
||||
There should be a post to Pivotal Labs blog and a tweet to that link.
|
||||
@@ -1,21 +0,0 @@
|
||||
# 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 <em>[cruise data]</em>/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
|
||||
@@ -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>
|
||||
<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##/jasmine-html.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>
|
||||
<div id="REMOVE_THIS_LINE_FROM_BUILD"><p>You must be trying to look at examples in the Jasmine source tree.</p><p>Please download a distribution version of Jasmine at <a href="http://pivotal.github.com/jasmine/">http://pivotal.github.com/jasmine/</a>.</p></div>
|
||||
<script type="text/javascript">
|
||||
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
|
||||
jasmine.getEnv().execute();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 722 B |
BIN
images/fail.png
|
Before Width: | Height: | Size: 2.1 KiB |
BIN
images/go-16.png
|
Before Width: | Height: | Size: 759 B |
BIN
images/go.png
|
Before Width: | Height: | Size: 2.2 KiB |
BIN
images/jasmine_favicon.png
Normal file
|
After Width: | Height: | Size: 905 B |
|
Before Width: | Height: | Size: 802 B |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 768 B |
|
Before Width: | Height: | Size: 1.7 KiB |
22
jasmine-core.gemspec
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
require "jasmine-core/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "jasmine-core"
|
||||
s.version = Jasmine::Core::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["Rajan Agaskar", "Davis Frank", "Christian Williams"]
|
||||
s.summary = %q{JavaScript BDD framework}
|
||||
s.description = %q{Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax.}
|
||||
s.email = %q{jasmine-js@googlegroups.com}
|
||||
s.homepage = "http://pivotal.github.com/jasmine"
|
||||
s.rubyforge_project = "jasmine-core"
|
||||
|
||||
s.files = Dir.glob("./lib/**/*") + Dir.glob("./lib/jasmine-core/spec/**/*.js")
|
||||
s.require_paths = ["lib"]
|
||||
s.add_development_dependency "term-ansicolor"
|
||||
s.add_development_dependency "json_pure", ">= 1.4.3"
|
||||
s.add_development_dependency "frank"
|
||||
s.add_development_dependency "ragaskar-jsdoc_helper"
|
||||
end
|
||||
5919
jshint/jshint.js
Executable file
99
jshint/run.js
Normal file
@@ -0,0 +1,99 @@
|
||||
var fs = require("fs");
|
||||
var sys = require("sys");
|
||||
var path = require("path");
|
||||
var JSHINT = require("./jshint").JSHINT;
|
||||
|
||||
// DWF TODO: Standardize this?
|
||||
function isExcluded(fullPath) {
|
||||
var fileName = path.basename(fullPath);
|
||||
var excludeFiles = ["json2.js", "jshint.js", "publish.js", "node_suite.js", "jasmine.js", "jasmine-html.js"];
|
||||
for (var i = 0; i < excludeFiles.length; i++) {
|
||||
if (fileName == excludeFiles[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// DWF TODO: This function could/should be re-written
|
||||
function allJasmineJsFiles(rootDir) {
|
||||
var files = [];
|
||||
fs.readdirSync(rootDir).filter(function(filename) {
|
||||
|
||||
var fullPath = rootDir + "/" + filename;
|
||||
if (fs.statSync(fullPath).isDirectory() && !fullPath.match(/pages/)) {
|
||||
var subDirFiles = allJasmineJsFiles(fullPath);
|
||||
if (subDirFiles.length > 0) {
|
||||
files = files.concat();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (fullPath.match(/\.js$/) && !isExcluded(fullPath)) {
|
||||
files.push(fullPath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
var jasmineJsFiles = allJasmineJsFiles(".");
|
||||
jasmineJsFiles.reverse(); //cheap way to do the stuff in src stuff first
|
||||
|
||||
var jasmineJsHintConfig = {
|
||||
|
||||
forin:true, //while it's possible that we could be
|
||||
//considering unwanted prototype methods, mostly
|
||||
//we're doing this because the jsobjects are being
|
||||
//used as maps.
|
||||
|
||||
loopfunc:true //we're fine with functions defined inside loops (setTimeout functions, etc)
|
||||
|
||||
};
|
||||
|
||||
var jasmineGlobals = {};
|
||||
|
||||
|
||||
//jasmine.undefined is a jasmine-ism, let's let it go...
|
||||
function removeJasmineUndefinedErrors(errors) {
|
||||
var keepErrors = [];
|
||||
for (var i = 0; i < errors.length; i++) {
|
||||
if (!(errors[i] &&
|
||||
errors[i].raw &&
|
||||
errors[i].evidence &&
|
||||
( errors[i].evidence.match(/jasmine\.undefined/) ||
|
||||
errors[i].evidence.match(/diz be undefined yo/) )
|
||||
)) {
|
||||
keepErrors.push(errors[i]);
|
||||
}
|
||||
}
|
||||
return keepErrors;
|
||||
}
|
||||
|
||||
(function() {
|
||||
var ansi = {
|
||||
green: '\033[32m',
|
||||
red: '\033[31m',
|
||||
yellow: '\033[33m',
|
||||
none: '\033[0m'
|
||||
};
|
||||
|
||||
for (var i = 0; i < jasmineJsFiles.length; i++) {
|
||||
var file = jasmineJsFiles[i];
|
||||
JSHINT(fs.readFileSync(file, "utf8"), jasmineJsHintConfig);
|
||||
var errors = JSHINT.data().errors || [];
|
||||
errors = removeJasmineUndefinedErrors(errors);
|
||||
|
||||
if (errors.length >= 1) {
|
||||
console.log(ansi.red + "Jasmine JSHint failure: " + ansi.none);
|
||||
console.log(file);
|
||||
console.log(errors);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(ansi.green + "Jasmine JSHint PASSED." + ansi.none);
|
||||
})();
|
||||
|
||||
36
lib/jasmine-core.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
module Jasmine
|
||||
module Core
|
||||
class << self
|
||||
def path
|
||||
File.join(File.dirname(__FILE__), "jasmine-core")
|
||||
end
|
||||
|
||||
def js_files
|
||||
(["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq
|
||||
end
|
||||
|
||||
SPEC_TYPES = ["core", "html", "node"]
|
||||
|
||||
def core_spec_files
|
||||
spec_files("core")
|
||||
end
|
||||
|
||||
def html_spec_files
|
||||
spec_files("html")
|
||||
end
|
||||
|
||||
def node_spec_files
|
||||
spec_files("node")
|
||||
end
|
||||
|
||||
def spec_files(type)
|
||||
raise ArgumentError.new("Unrecognized spec type") unless SPEC_TYPES.include?(type)
|
||||
(Dir.glob(File.join(path, "spec", type, "*.js"))).map { |f| File.join("spec", type, File.basename(f)) }.uniq
|
||||
end
|
||||
|
||||
def css_files
|
||||
Dir.glob(File.join(path, "*.css")).map { |f| File.basename(f) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
54
lib/jasmine-core/example/SpecRunner.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Jasmine Spec Runner</title>
|
||||
|
||||
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.1.0.rc1/jasmine_favicon.png">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.1.0.rc1/jasmine.css">
|
||||
<script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine.js"></script>
|
||||
<script type="text/javascript" src="lib/jasmine-1.1.0.rc1/jasmine-html.js"></script>
|
||||
|
||||
<!-- include source files here... -->
|
||||
<script type="text/javascript" src="spec/SpecHelper.js"></script>
|
||||
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script type="text/javascript" src="src/Player.js"></script>
|
||||
<script type="text/javascript" src="src/Song.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.updateInterval = 1000;
|
||||
|
||||
var trivialReporter = new jasmine.TrivialReporter();
|
||||
|
||||
jasmineEnv.addReporter(trivialReporter);
|
||||
|
||||
jasmineEnv.specFilter = function(spec) {
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
execJasmine();
|
||||
};
|
||||
|
||||
function execJasmine() {
|
||||
jasmineEnv.execute();
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,8 +2,8 @@ beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toBePlaying: function(expectedSong) {
|
||||
var player = this.actual;
|
||||
return player.currentlyPlayingSong === expectedSong
|
||||
&& player.isPlaying;
|
||||
return player.currentlyPlayingSong === expectedSong &&
|
||||
player.isPlaying;
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
@@ -34,7 +34,7 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
|
||||
this.createDom('div', { className: 'banner' },
|
||||
this.createDom('div', { className: 'logo' },
|
||||
this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
|
||||
this.createDom('span', { className: 'title' }, "Jasmine"),
|
||||
this.createDom('span', { className: 'version' }, runner.env.versionString())),
|
||||
this.createDom('div', { className: 'options' },
|
||||
"Show ",
|
||||
@@ -110,7 +110,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
||||
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
||||
var results = suite.results();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
||||
if (results.totalCount === 0) { // todo: change this to check results.skipped
|
||||
status = 'skipped';
|
||||
}
|
||||
this.suiteDivs[suite.id].className += " " + status;
|
||||
@@ -183,6 +183,8 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||
}
|
||||
|
||||
if (!paramMap["spec"]) return true;
|
||||
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
||||
if (!paramMap.spec) {
|
||||
return true;
|
||||
}
|
||||
return spec.getFullName().indexOf(paramMap.spec) === 0;
|
||||
};
|
||||
@@ -1,10 +1,12 @@
|
||||
var isCommonJS = typeof window == "undefined";
|
||||
|
||||
/**
|
||||
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
||||
*
|
||||
* @namespace
|
||||
*/
|
||||
var jasmine = {};
|
||||
|
||||
if (isCommonJS) exports.jasmine = jasmine;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -20,6 +22,12 @@ jasmine.unimplementedMethod_ = function() {
|
||||
*/
|
||||
jasmine.undefined = jasmine.___undefined___;
|
||||
|
||||
/**
|
||||
* Show diagnostic messages in the console if set to true
|
||||
*
|
||||
*/
|
||||
jasmine.VERBOSE = false;
|
||||
|
||||
/**
|
||||
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
|
||||
*
|
||||
@@ -72,7 +80,7 @@ jasmine.MessageResult = function(values) {
|
||||
|
||||
jasmine.MessageResult.prototype.toString = function() {
|
||||
var text = "";
|
||||
for(var i = 0; i < this.values.length; i++) {
|
||||
for (var i = 0; i < this.values.length; i++) {
|
||||
if (i > 0) text += " ";
|
||||
if (jasmine.isString_(this.values[i])) {
|
||||
text += this.values[i];
|
||||
@@ -89,9 +97,10 @@ jasmine.ExpectationResult = function(params) {
|
||||
this.passed_ = params.passed;
|
||||
this.expected = params.expected;
|
||||
this.actual = params.actual;
|
||||
|
||||
this.message = this.passed_ ? 'Passed.' : params.message;
|
||||
this.trace = this.passed_ ? '' : new Error(this.message);
|
||||
|
||||
var trace = (params.trace || new Error(this.message));
|
||||
this.trace = this.passed_ ? '' : trace;
|
||||
};
|
||||
|
||||
jasmine.ExpectationResult.prototype.toString = function () {
|
||||
@@ -106,7 +115,8 @@ jasmine.ExpectationResult.prototype.passed = function () {
|
||||
* Getter for the Jasmine environment. Ensures one gets created
|
||||
*/
|
||||
jasmine.getEnv = function() {
|
||||
return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||
return env;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,7 +126,7 @@ jasmine.getEnv = function() {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
jasmine.isArray_ = function(value) {
|
||||
return jasmine.isA_("Array", value);
|
||||
return jasmine.isA_("Array", value);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -169,7 +179,7 @@ jasmine.pp = function(value) {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
jasmine.isDomNode = function(obj) {
|
||||
return obj['nodeType'] > 0;
|
||||
return obj.nodeType > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -405,7 +415,7 @@ jasmine.isSpy = function(putativeSpy) {
|
||||
* @param {Array} methodNames array of names of methods to make spies
|
||||
*/
|
||||
jasmine.createSpyObj = function(baseName, methodNames) {
|
||||
if (!jasmine.isArray_(methodNames) || methodNames.length == 0) {
|
||||
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
|
||||
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
|
||||
}
|
||||
var obj = {};
|
||||
@@ -443,6 +453,7 @@ jasmine.log = function() {
|
||||
var spyOn = function(obj, methodName) {
|
||||
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
||||
};
|
||||
if (isCommonJS) exports.spyOn = spyOn;
|
||||
|
||||
/**
|
||||
* Creates a Jasmine spec that will be added to the current suite.
|
||||
@@ -460,6 +471,7 @@ var spyOn = function(obj, methodName) {
|
||||
var it = function(desc, func) {
|
||||
return jasmine.getEnv().it(desc, func);
|
||||
};
|
||||
if (isCommonJS) exports.it = it;
|
||||
|
||||
/**
|
||||
* Creates a <em>disabled</em> Jasmine spec.
|
||||
@@ -472,6 +484,7 @@ var it = function(desc, func) {
|
||||
var xit = function(desc, func) {
|
||||
return jasmine.getEnv().xit(desc, func);
|
||||
};
|
||||
if (isCommonJS) exports.xit = xit;
|
||||
|
||||
/**
|
||||
* Starts a chain for a Jasmine expectation.
|
||||
@@ -484,6 +497,7 @@ var xit = function(desc, func) {
|
||||
var expect = function(actual) {
|
||||
return jasmine.getEnv().currentSpec.expect(actual);
|
||||
};
|
||||
if (isCommonJS) exports.expect = expect;
|
||||
|
||||
/**
|
||||
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
||||
@@ -493,6 +507,7 @@ var expect = function(actual) {
|
||||
var runs = function(func) {
|
||||
jasmine.getEnv().currentSpec.runs(func);
|
||||
};
|
||||
if (isCommonJS) exports.runs = runs;
|
||||
|
||||
/**
|
||||
* Waits a fixed time period before moving to the next block.
|
||||
@@ -503,6 +518,7 @@ var runs = function(func) {
|
||||
var waits = function(timeout) {
|
||||
jasmine.getEnv().currentSpec.waits(timeout);
|
||||
};
|
||||
if (isCommonJS) exports.waits = waits;
|
||||
|
||||
/**
|
||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||
@@ -514,6 +530,7 @@ var waits = function(timeout) {
|
||||
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
||||
};
|
||||
if (isCommonJS) exports.waitsFor = waitsFor;
|
||||
|
||||
/**
|
||||
* A function that is called before each spec in a suite.
|
||||
@@ -525,6 +542,7 @@ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout
|
||||
var beforeEach = function(beforeEachFunction) {
|
||||
jasmine.getEnv().beforeEach(beforeEachFunction);
|
||||
};
|
||||
if (isCommonJS) exports.beforeEach = beforeEach;
|
||||
|
||||
/**
|
||||
* A function that is called after each spec in a suite.
|
||||
@@ -536,6 +554,7 @@ var beforeEach = function(beforeEachFunction) {
|
||||
var afterEach = function(afterEachFunction) {
|
||||
jasmine.getEnv().afterEach(afterEachFunction);
|
||||
};
|
||||
if (isCommonJS) exports.afterEach = afterEach;
|
||||
|
||||
/**
|
||||
* Defines a suite of specifications.
|
||||
@@ -555,6 +574,7 @@ var afterEach = function(afterEachFunction) {
|
||||
var describe = function(description, specDefinitions) {
|
||||
return jasmine.getEnv().describe(description, specDefinitions);
|
||||
};
|
||||
if (isCommonJS) exports.describe = describe;
|
||||
|
||||
/**
|
||||
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
||||
@@ -565,27 +585,35 @@ var describe = function(description, specDefinitions) {
|
||||
var xdescribe = function(description, specDefinitions) {
|
||||
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
||||
};
|
||||
if (isCommonJS) exports.xdescribe = xdescribe;
|
||||
|
||||
|
||||
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
||||
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
||||
try {
|
||||
function tryIt(f) {
|
||||
try {
|
||||
return f();
|
||||
} catch(e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var xhr = tryIt(function() {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP");
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch(e) {
|
||||
}
|
||||
throw new Error("This browser does not support XMLHttpRequest.");
|
||||
}) ||
|
||||
tryIt(function() {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
||||
}) ||
|
||||
tryIt(function() {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}) ||
|
||||
tryIt(function() {
|
||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||
});
|
||||
|
||||
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
|
||||
|
||||
return xhr;
|
||||
} : XMLHttpRequest;
|
||||
/**
|
||||
* @namespace
|
||||
@@ -606,7 +634,7 @@ jasmine.util.inherit = function(childClass, parentClass) {
|
||||
var subclass = function() {
|
||||
};
|
||||
subclass.prototype = parentClass.prototype;
|
||||
childClass.prototype = new subclass;
|
||||
childClass.prototype = new subclass();
|
||||
};
|
||||
|
||||
jasmine.util.formatException = function(e) {
|
||||
@@ -707,12 +735,17 @@ jasmine.Env.prototype.version = function () {
|
||||
* @returns string containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.versionString = function() {
|
||||
if (jasmine.version_) {
|
||||
var version = this.version();
|
||||
return version.major + "." + version.minor + "." + version.build + " revision " + version.revision;
|
||||
} else {
|
||||
if (!jasmine.version_) {
|
||||
return "version unknown";
|
||||
}
|
||||
|
||||
var version = this.version();
|
||||
var versionString = version.major + "." + version.minor + "." + version.build;
|
||||
if (version.release_candidate) {
|
||||
versionString += ".rc" + version.release_candidate
|
||||
}
|
||||
versionString += " revision " + version.revision;
|
||||
return versionString;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -760,14 +793,14 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
declarationError = e;
|
||||
}
|
||||
|
||||
this.currentSuite = parentSuite;
|
||||
|
||||
if (declarationError) {
|
||||
this.it("encountered a declaration exception", function() {
|
||||
throw declarationError;
|
||||
});
|
||||
}
|
||||
|
||||
this.currentSuite = parentSuite;
|
||||
|
||||
return suite;
|
||||
};
|
||||
|
||||
@@ -828,7 +861,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
||||
b.__Jasmine_been_here_before__ = a;
|
||||
|
||||
var hasKey = function(obj, keyName) {
|
||||
return obj != null && obj[keyName] !== jasmine.undefined;
|
||||
return obj !== null && obj[keyName] !== jasmine.undefined;
|
||||
};
|
||||
|
||||
for (var property in b) {
|
||||
@@ -854,7 +887,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
||||
|
||||
delete a.__Jasmine_been_here_before__;
|
||||
delete b.__Jasmine_been_here_before__;
|
||||
return (mismatchKeys.length == 0 && mismatchValues.length == 0);
|
||||
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
@@ -1302,16 +1335,16 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
|
||||
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
|
||||
}
|
||||
this.message = function() {
|
||||
if (this.actual.callCount == 0) {
|
||||
if (this.actual.callCount === 0) {
|
||||
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
|
||||
return [
|
||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
|
||||
"Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
||||
"Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
|
||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
|
||||
"Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
|
||||
"Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
|
||||
];
|
||||
}
|
||||
};
|
||||
@@ -1333,7 +1366,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
|
||||
return [
|
||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
|
||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
|
||||
]
|
||||
];
|
||||
};
|
||||
|
||||
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
|
||||
@@ -1366,6 +1399,23 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
|
||||
return this.actual > expected;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that checks that the expected item is equal to the actual item
|
||||
* up to a given level of decimal precision (default 2).
|
||||
*
|
||||
* @param {Number} expected
|
||||
* @param {Number} precision
|
||||
*/
|
||||
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
|
||||
if (!(precision === 0)) {
|
||||
precision = precision || 2;
|
||||
}
|
||||
var multiplier = Math.pow(10, precision);
|
||||
var actual = Math.round(this.actual * multiplier);
|
||||
expected = Math.round(expected * multiplier);
|
||||
return expected == actual;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that checks that the expected exception was thrown by the actual.
|
||||
*
|
||||
@@ -1390,7 +1440,7 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
|
||||
|
||||
this.message = function() {
|
||||
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
|
||||
return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
|
||||
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
|
||||
} else {
|
||||
return "Expected function to throw an exception.";
|
||||
}
|
||||
@@ -1602,7 +1652,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
|
||||
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
||||
for (var property in obj) {
|
||||
if (property == '__Jasmine_been_here_before__') continue;
|
||||
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false);
|
||||
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
|
||||
obj.__lookupGetter__(property) !== null) : false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1962,7 +2013,8 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag
|
||||
jasmine.Spec.prototype.fail = function (e) {
|
||||
var expectationResult = new jasmine.ExpectationResult({
|
||||
passed: false,
|
||||
message: e ? jasmine.util.formatException(e) : 'Exception'
|
||||
message: e ? jasmine.util.formatException(e) : 'Exception',
|
||||
trace: { stack: e.stack }
|
||||
});
|
||||
this.results_.addResult(expectationResult);
|
||||
};
|
||||
@@ -2172,7 +2224,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) {
|
||||
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
|
||||
|
||||
jasmine.WaitsBlock.prototype.execute = function (onComplete) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
|
||||
if (jasmine.VERBOSE) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
|
||||
}
|
||||
this.env.setTimeout(function () {
|
||||
onComplete();
|
||||
}, this.timeout);
|
||||
@@ -2200,7 +2254,9 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
|
||||
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
|
||||
|
||||
jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
|
||||
if (jasmine.VERBOSE) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
|
||||
}
|
||||
var latchFunctionResult;
|
||||
try {
|
||||
latchFunctionResult = this.latchFunction.apply(this.spec);
|
||||
@@ -2412,10 +2468,10 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
jasmine.version_= {
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"build": 1,
|
||||
"revision": 1286311016
|
||||
"minor": 1,
|
||||
"build": 0,
|
||||
"revision": 1310556152,
|
||||
"release_candidate": 3
|
||||
};
|
||||
1
lib/jasmine-core/spec
Symbolic link
@@ -0,0 +1 @@
|
||||
../../spec
|
||||
6
lib/jasmine-core/version.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Jasmine
|
||||
module Core
|
||||
VERSION = "1.1.0.rc3"
|
||||
end
|
||||
end
|
||||
|
||||
2
pages
451
spec/console/ConsoleReporterSpec.js
Normal file
@@ -0,0 +1,451 @@
|
||||
describe("ConsoleReporter", function() {
|
||||
//keep these literal. otherwise the test loses value as a test.
|
||||
function green(str) {
|
||||
return '\033[32m' + str + '\033[0m';
|
||||
}
|
||||
|
||||
function red(str) {
|
||||
return '\033[31m' + str + '\033[0m';
|
||||
}
|
||||
|
||||
function yellow(str) {
|
||||
return '\033[33m' + str + '\033[0m';
|
||||
}
|
||||
|
||||
function prefixGreen(str) {
|
||||
return '\033[32m' + str;
|
||||
}
|
||||
|
||||
function prefixRed(str) {
|
||||
return '\033[31m' + str;
|
||||
}
|
||||
|
||||
var newline = "\n";
|
||||
|
||||
var passingSpec = {
|
||||
results: function() {
|
||||
return {
|
||||
passed: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
failingSpec = {
|
||||
results: function() {
|
||||
return {
|
||||
passed: function() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
skippedSpec = {
|
||||
results: function() {
|
||||
return {skipped: true};
|
||||
}
|
||||
},
|
||||
passingRun = {
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results: function() {
|
||||
return {failedCount: 0, items_: [null, null, null]};
|
||||
}
|
||||
},
|
||||
failingRun = {
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results: function() {
|
||||
return {
|
||||
failedCount: 7, items_: [null, null, null]};
|
||||
}
|
||||
};
|
||||
|
||||
function repeatedlyInvoke(f, times) {
|
||||
for (var i = 0; i < times; i++) f(times + 1);
|
||||
}
|
||||
|
||||
function repeat(thing, times) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < times; i++) arr.push(thing);
|
||||
return arr;
|
||||
}
|
||||
|
||||
function simulateRun(reporter, specResults, suiteResults, finalRunner, startTime, endTime) {
|
||||
reporter.reportRunnerStarting();
|
||||
for (var i = 0; i < specResults.length; i++) {
|
||||
reporter.reportSpecResults(specResults[i]);
|
||||
}
|
||||
for (i = 0; i < suiteResults.length; i++) {
|
||||
reporter.reportSuiteResults(suiteResults[i]);
|
||||
}
|
||||
reporter.runnerStartTime = startTime;
|
||||
reporter.now = function() {
|
||||
return endTime;
|
||||
};
|
||||
reporter.reportRunnerResults(finalRunner);
|
||||
}
|
||||
|
||||
var reporter, out, done;
|
||||
|
||||
beforeEach(function() {
|
||||
out = (function() {
|
||||
var output = "";
|
||||
return {
|
||||
print:function(str) {
|
||||
output += str;
|
||||
},
|
||||
getOutput:function() {
|
||||
return output;
|
||||
},
|
||||
clear: function() {
|
||||
output = "";
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
done = false;
|
||||
reporter = new jasmine.ConsoleReporter(out.print, function(runner) {
|
||||
done = true
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Integration', function() {
|
||||
it("prints the proper output under a pass scenario - small numbers.", function() {
|
||||
simulateRun(reporter,
|
||||
repeat(passingSpec, 3),
|
||||
[],
|
||||
{
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {
|
||||
items_: [null, null, null],
|
||||
totalCount: 7,
|
||||
failedCount: 0
|
||||
};
|
||||
}
|
||||
},
|
||||
1000,
|
||||
1777
|
||||
);
|
||||
|
||||
var output = out.getOutput();
|
||||
expect(output).toMatch(/^Started/);
|
||||
expect(output).toMatch(/\.\.\./);
|
||||
expect(output).toMatch(/3 specs, 0 failures/);
|
||||
});
|
||||
|
||||
it("prints the proper output under a pass scenario. large numbers.", function() {
|
||||
simulateRun(reporter,
|
||||
repeat(passingSpec, 57),
|
||||
[],
|
||||
{
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {
|
||||
items_: [null, null, null],
|
||||
totalCount: 7,
|
||||
failedCount: 0
|
||||
};
|
||||
}
|
||||
},
|
||||
1000,
|
||||
1777);
|
||||
|
||||
var output = out.getOutput();
|
||||
expect(output).toMatch(/^Started/);
|
||||
expect(output).toMatch(/\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\./);
|
||||
expect(output).toMatch(/3 specs, 0 failures/);
|
||||
});
|
||||
|
||||
it("prints the proper output under a failure scenario.", function() {
|
||||
simulateRun(reporter,
|
||||
[failingSpec, passingSpec, failingSpec],
|
||||
[
|
||||
{description:"The oven",
|
||||
results:function() {
|
||||
return {
|
||||
items_:[
|
||||
{failedCount:2,
|
||||
description:"heats up",
|
||||
items_:[
|
||||
{trace:{stack:"stack trace one\n second line"}},
|
||||
{trace:{stack:"stack trace two"}}
|
||||
]}
|
||||
]
|
||||
};
|
||||
}},
|
||||
{description:"The washing machine",
|
||||
results:function() {
|
||||
return {
|
||||
items_:[
|
||||
{failedCount:2,
|
||||
description:"washes clothes",
|
||||
items_:[
|
||||
{trace:{stack:"stack trace one"}}
|
||||
]}
|
||||
]
|
||||
};
|
||||
}}
|
||||
],
|
||||
{
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {
|
||||
items_: [null, null, null],
|
||||
totalCount: 7,
|
||||
failedCount: 2
|
||||
};
|
||||
}
|
||||
},
|
||||
1000,
|
||||
1777);
|
||||
|
||||
var output = out.getOutput();
|
||||
expect(output).toMatch(/^Started/);
|
||||
expect(output).toMatch(/F\.F/);
|
||||
expect(output).toMatch(/The oven heats up\n stack trace one\n second line\n stack trace two/);
|
||||
expect(output).toMatch(/The washing machine washes clothes\n stack trace one/);
|
||||
expect(output).toMatch(/3 specs, 2 failures/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When a Jasmine environment executes', function() {
|
||||
beforeEach(function() {
|
||||
reporter.reportRunnerStarting();
|
||||
});
|
||||
|
||||
it("should print 'Started' to the console", function() {
|
||||
expect(out.getOutput()).toEqual("Started" + newline);
|
||||
});
|
||||
|
||||
describe('when a spec reports', function() {
|
||||
beforeEach(function() {
|
||||
out.clear();
|
||||
});
|
||||
|
||||
it("prints a green dot if the spec passes", function() {
|
||||
reporter.reportSpecResults(passingSpec);
|
||||
|
||||
expect(out.getOutput()).toMatch(/\./);
|
||||
});
|
||||
|
||||
it("prints a red dot if the spec fails", function() {
|
||||
reporter.reportSpecResults(failingSpec);
|
||||
|
||||
expect(out.getOutput()).toMatch(/F/);
|
||||
});
|
||||
|
||||
it("prints a yellow star if the spec was skipped", function() {
|
||||
reporter.reportSpecResults(skippedSpec);
|
||||
|
||||
expect(out.getOutput()).toMatch(/\*/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when a suite reports', function() {
|
||||
var emptyResults;
|
||||
beforeEach(function() {
|
||||
emptyResults = function() {
|
||||
return {
|
||||
items_:[]
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
it("remembers suite results", function() {
|
||||
reporter.reportSuiteResults({description: "Oven", results: emptyResults});
|
||||
reporter.reportSuiteResults({description: "Mixer", results: emptyResults});
|
||||
|
||||
expect(reporter.suiteResults[0].description).toEqual('Oven');
|
||||
expect(reporter.suiteResults[1].description).toEqual('Mixer');
|
||||
});
|
||||
|
||||
it("creates a description out of the current suite and any parent suites", function() {
|
||||
var grandparentSuite = {
|
||||
description: "My house",
|
||||
results: emptyResults
|
||||
};
|
||||
var parentSuite = {
|
||||
description: "kitchen",
|
||||
parentSuite: grandparentSuite,
|
||||
results: emptyResults
|
||||
};
|
||||
reporter.reportSuiteResults({ description: "oven", parentSuite: parentSuite, results: emptyResults });
|
||||
|
||||
expect(reporter.suiteResults[0].description).toEqual("My house kitchen oven");
|
||||
});
|
||||
|
||||
it("gathers failing spec results from the suite - the spec must have a description.", function() {
|
||||
reporter.reportSuiteResults({description:"Oven",
|
||||
results: function() {
|
||||
return {
|
||||
items_:[
|
||||
{ failedCount: 0, description: "specOne" },
|
||||
{ failedCount: 99, description: "specTwo" },
|
||||
{ failedCount: 0, description: "specThree" },
|
||||
{ failedCount: 88, description: "specFour" },
|
||||
{ failedCount: 3 }
|
||||
]
|
||||
};
|
||||
}});
|
||||
|
||||
expect(reporter.suiteResults[0].failedSpecResults).
|
||||
toEqual([
|
||||
{ failedCount: 99, description: "specTwo" },
|
||||
{ failedCount: 88, description: "specFour" }
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('and finishes', function() {
|
||||
|
||||
describe('when reporting spec failure information', function() {
|
||||
|
||||
it("prints suite and spec descriptions together as a sentence", function() {
|
||||
reporter.suiteResults = [
|
||||
{description:"The oven", failedSpecResults:[
|
||||
{description:"heats up", items_:[]},
|
||||
{description:"cleans itself", items_:[]}
|
||||
]},
|
||||
{description:"The mixer", failedSpecResults:[
|
||||
{description:"blends things together", items_:[]}
|
||||
]}
|
||||
];
|
||||
|
||||
reporter.reportRunnerResults(failingRun);
|
||||
|
||||
expect(out.getOutput()).toContain("The oven heats up");
|
||||
expect(out.getOutput()).toContain("The oven cleans itself");
|
||||
expect(out.getOutput()).toContain("The mixer blends things together");
|
||||
});
|
||||
|
||||
it("prints stack trace of spec failure", function() {
|
||||
reporter.suiteResults = [
|
||||
{description:"The oven", failedSpecResults:[
|
||||
{description:"heats up",
|
||||
items_:[
|
||||
{trace:{stack:"stack trace one"}},
|
||||
{trace:{stack:"stack trace two"}}
|
||||
]}
|
||||
]}
|
||||
];
|
||||
|
||||
reporter.reportRunnerResults(failingRun);
|
||||
|
||||
expect(out.getOutput()).toContain("The oven heats up");
|
||||
expect(out.getOutput()).toContain("stack trace one");
|
||||
expect(out.getOutput()).toContain("stack trace two");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when reporting the execution time', function() {
|
||||
|
||||
it("prints the full finished message", function() {
|
||||
reporter.now = function() {
|
||||
return 1000;
|
||||
};
|
||||
reporter.reportRunnerStarting();
|
||||
reporter.now = function() {
|
||||
return 1777;
|
||||
};
|
||||
reporter.reportRunnerResults(failingRun);
|
||||
expect(out.getOutput()).toContain("Finished in 0.777 seconds");
|
||||
});
|
||||
|
||||
it("prints round time numbers correctly", function() {
|
||||
function run(startTime, endTime) {
|
||||
out.clear();
|
||||
reporter.runnerStartTime = startTime;
|
||||
reporter.now = function() {
|
||||
return endTime;
|
||||
};
|
||||
reporter.reportRunnerResults(passingRun);
|
||||
}
|
||||
|
||||
run(1000, 11000);
|
||||
expect(out.getOutput()).toContain("10 seconds");
|
||||
|
||||
run(1000, 2000);
|
||||
expect(out.getOutput()).toContain("1 seconds");
|
||||
|
||||
run(1000, 1100);
|
||||
expect(out.getOutput()).toContain("0.1 seconds");
|
||||
|
||||
run(1000, 1010);
|
||||
expect(out.getOutput()).toContain("0.01 seconds");
|
||||
|
||||
run(1000, 1001);
|
||||
expect(out.getOutput()).toContain("0.001 seconds");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when reporting the results summary", function() {
|
||||
it("prints statistics in green if there were no failures", function() {
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null, null, null], totalCount: 7, failedCount: 0};
|
||||
}
|
||||
});
|
||||
expect(out.getOutput()).
|
||||
toContain("3 specs, 0 failures");
|
||||
});
|
||||
|
||||
it("prints statistics in red if there was a failure", function() {
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null, null, null], totalCount: 7, failedCount: 3};
|
||||
}
|
||||
});
|
||||
expect(out.getOutput()).
|
||||
toContain("3 specs, 3 failures");
|
||||
});
|
||||
|
||||
it("handles pluralization with 1's ones appropriately", function() {
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null], totalCount: 1, failedCount: 1};
|
||||
}
|
||||
});
|
||||
expect(out.getOutput()).
|
||||
toContain("1 spec, 1 failure");
|
||||
});
|
||||
});
|
||||
|
||||
describe("done callback", function() {
|
||||
it("calls back when done", function() {
|
||||
expect(done).toBeFalsy();
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null, null, null], totalCount: 7, failedCount: 0};
|
||||
}
|
||||
});
|
||||
expect(done).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -64,9 +64,10 @@ describe("jasmine.Env", function() {
|
||||
"major": 1,
|
||||
"minor": 9,
|
||||
"build": 7,
|
||||
"release_candidate": "1",
|
||||
"revision": 8
|
||||
};
|
||||
expect(env.versionString()).toEqual("1.9.7 revision 8");
|
||||
expect(env.versionString()).toEqual("1.9.7.rc1 revision 8");
|
||||
});
|
||||
|
||||
it("should return a nice string when version is unknown", function() {
|
||||
@@ -108,7 +109,7 @@ describe("jasmine.Env", function() {
|
||||
|
||||
it("should give custom equality testers precedence", function() {
|
||||
expect(env.equals_('abc', 'abc')).toBeFalsy();
|
||||
var o = new Object();
|
||||
var o = {};
|
||||
expect(env.equals_(o, o)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ describe('Exceptions:', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmine.Env();
|
||||
env.updateInterval = 0;
|
||||
env.updateInterval = 0;
|
||||
});
|
||||
|
||||
it('jasmine.formatException formats Firefox exception messages as expected', function() {
|
||||
@@ -89,9 +89,9 @@ describe('Exceptions:', function() {
|
||||
expect(blockResults[0].message).toMatch(/fake error 1/);
|
||||
|
||||
expect(specResults[1].passed()).toEqual(false);
|
||||
var blockResults = specResults[1].getItems();
|
||||
blockResults = specResults[1].getItems();
|
||||
expect(blockResults[0].passed()).toEqual(false);
|
||||
expect(blockResults[0].message).toMatch(/fake error 2/),
|
||||
expect(blockResults[0].message).toMatch(/fake error 2/);
|
||||
expect(blockResults[1].passed()).toEqual(true);
|
||||
|
||||
expect(specResults[2].passed()).toEqual(true);
|
||||
@@ -101,7 +101,49 @@ describe('Exceptions:', function() {
|
||||
expect(blockResults[0].message).toMatch(/fake error 3/);
|
||||
|
||||
expect(specResults[4].passed()).toEqual(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
|
||||
var suite = env.describe("a top level describe block that throws an exception", function () {
|
||||
env.it("is a test that should pass", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
throw new Error("top level error");
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
var suiteResults = suite.results();
|
||||
var specResults = suiteResults.getItems();
|
||||
|
||||
expect(suiteResults.passed()).toEqual(false);
|
||||
expect(specResults.length).toEqual(2);
|
||||
|
||||
expect(specResults[1].description).toMatch(/encountered a declaration exception/);
|
||||
});
|
||||
|
||||
it("should handle exceptions thrown directly in nested describe blocks and continue", function () {
|
||||
var suite = env.describe("a top level describe", function () {
|
||||
env.describe("a mid-level describe that throws an exception", function () {
|
||||
env.it("is a test that should pass", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
throw new Error("a mid-level error");
|
||||
});
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
var suiteResults = suite.results();
|
||||
var specResults = suiteResults.getItems();
|
||||
|
||||
expect(suiteResults.passed()).toEqual(false);
|
||||
expect(specResults.length).toEqual(1);
|
||||
|
||||
var nestedSpecResults = specResults[0].getItems();
|
||||
|
||||
expect(nestedSpecResults.length).toEqual(2);
|
||||
expect(nestedSpecResults[1].description).toMatch(/encountered a declaration exception/);
|
||||
});
|
||||
});
|
||||
@@ -21,7 +21,7 @@ describe('jasmine.jsApiReporter', function() {
|
||||
nestedSuite = env.describe("nested suite", function() {
|
||||
nestedSpec = env.it("nested spec", function() {
|
||||
expect(true).toEqual(true);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
spec3 = env.it("spec 3", function() {
|
||||
@@ -18,7 +18,7 @@ describe("jasmine.Matchers", function() {
|
||||
toFail: function() {
|
||||
return !lastResult().passed();
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
function match(value) {
|
||||
@@ -68,20 +68,13 @@ describe("jasmine.Matchers", function() {
|
||||
expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
|
||||
expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
|
||||
|
||||
expect((match(new String("cat")).toEqual("cat"))).toPass();
|
||||
expect((match(new String("cat")).toNotEqual("cat"))).toFail();
|
||||
expect((match("cat").toEqual("cat"))).toPass();
|
||||
expect((match("cat").toNotEqual("cat"))).toFail();
|
||||
|
||||
expect((match(new Number(5)).toEqual(5))).toPass();
|
||||
expect((match(new Number('5')).toEqual(5))).toPass();
|
||||
expect((match(new Number(5)).toNotEqual(5))).toFail();
|
||||
expect((match(new Number('5')).toNotEqual(5))).toFail();
|
||||
});
|
||||
|
||||
it("toEqual with DOM nodes", function() {
|
||||
var nodeA = document.createElement('div');
|
||||
var nodeB = document.createElement('div');
|
||||
expect((match(nodeA).toEqual(nodeA))).toPass();
|
||||
expect((match(nodeA).toEqual(nodeB))).toFail();
|
||||
expect((match(5).toEqual(5))).toPass();
|
||||
expect((match(parseInt('5', 10)).toEqual(5))).toPass();
|
||||
expect((match(5).toNotEqual(5))).toFail();
|
||||
expect((match(parseInt('5', 10)).toNotEqual(5))).toFail();
|
||||
});
|
||||
|
||||
it("toEqual to build an Expectation Result", function() {
|
||||
@@ -348,11 +341,13 @@ describe("jasmine.Matchers", function() {
|
||||
expect(match("foo").toEqual(jasmine.any(Object))).toFail();
|
||||
expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toPass();
|
||||
expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toFail();
|
||||
expect(match(function() {
|
||||
}).toEqual(jasmine.any(Object))).toFail();
|
||||
expect(match(
|
||||
function() {
|
||||
}).toEqual(jasmine.any(Object))).toFail();
|
||||
expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toPass();
|
||||
expect(match(function() {
|
||||
}).toEqual(jasmine.any(Function))).toPass();
|
||||
expect(match(
|
||||
function() {
|
||||
}).toEqual(jasmine.any(Function))).toPass();
|
||||
expect(match(["a", function() {
|
||||
}]).toEqual(["a", jasmine.any(Function)])).toPass();
|
||||
});
|
||||
@@ -471,6 +466,47 @@ describe("jasmine.Matchers", function() {
|
||||
expect(result.expected).toEqual(expected);
|
||||
});
|
||||
|
||||
describe("toBeCloseTo", function() {
|
||||
it("returns 'true' iff actual and expected are equal within 2 decimal points of precision", function() {
|
||||
expect(0).toBeCloseTo(0);
|
||||
expect(1).toBeCloseTo(1);
|
||||
expect(1).not.toBeCloseTo(1.1);
|
||||
expect(1).not.toBeCloseTo(1.01);
|
||||
expect(1).toBeCloseTo(1.001);
|
||||
|
||||
expect(1.23).toBeCloseTo(1.234);
|
||||
expect(1.23).toBeCloseTo(1.233);
|
||||
expect(1.23).toBeCloseTo(1.232);
|
||||
expect(1.23).not.toBeCloseTo(1.24);
|
||||
|
||||
expect(-1.23).toBeCloseTo(-1.234);
|
||||
expect(-1.23).not.toBeCloseTo(-1.24);
|
||||
});
|
||||
|
||||
it("accepts an optional precision argument", function() {
|
||||
expect(1).toBeCloseTo(1.1, 0);
|
||||
expect(1.2).toBeCloseTo(1.23, 1);
|
||||
|
||||
expect(1.234).toBeCloseTo(1.2343, 3);
|
||||
expect(1.234).not.toBeCloseTo(1.233, 3);
|
||||
});
|
||||
|
||||
it("rounds", function() {
|
||||
expect(1.23).toBeCloseTo(1.229);
|
||||
expect(1.23).toBeCloseTo(1.226);
|
||||
expect(1.23).toBeCloseTo(1.225);
|
||||
expect(1.23).not.toBeCloseTo(1.2249999);
|
||||
|
||||
expect(1.23).toBeCloseTo(1.234);
|
||||
expect(1.23).toBeCloseTo(1.2349999);
|
||||
expect(1.23).not.toBeCloseTo(1.235);
|
||||
|
||||
expect(-1.23).toBeCloseTo(-1.234);
|
||||
expect(-1.23).not.toBeCloseTo(-1.235);
|
||||
expect(-1.23).not.toBeCloseTo(-1.236);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toThrow", function() {
|
||||
describe("when code block throws an exception", function() {
|
||||
var throwingFn;
|
||||
@@ -500,7 +536,7 @@ describe("jasmine.Matchers", function() {
|
||||
describe("and matcher is inverted with .not", function() {
|
||||
it("should match any exception", function() {
|
||||
expect(match(throwingFn).not.toThrow()).toFail();
|
||||
expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
|
||||
expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
|
||||
});
|
||||
|
||||
it("should match exceptions specified by message", function() {
|
||||
@@ -540,8 +576,9 @@ describe("jasmine.Matchers", function() {
|
||||
|
||||
describe("when code block does not throw an exception", function() {
|
||||
it("should fail (or pass when inverted with .not)", function() {
|
||||
expect(match(function() {
|
||||
}).toThrow()).toFail();
|
||||
expect(match(
|
||||
function() {
|
||||
}).toThrow()).toFail();
|
||||
expect(lastResult().message).toEqual('Expected function to throw an exception.');
|
||||
});
|
||||
});
|
||||
@@ -596,21 +633,25 @@ describe("jasmine.Matchers", function() {
|
||||
|
||||
function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
|
||||
return function() {
|
||||
expect(function() {
|
||||
match(TestClass.normalFunction)[methodName]();
|
||||
}).toThrow('Expected a spy, but got Function.');
|
||||
expect(
|
||||
function() {
|
||||
match(TestClass.normalFunction)[methodName]();
|
||||
}).toThrow('Expected a spy, but got Function.');
|
||||
|
||||
expect(function() {
|
||||
match(jasmine.undefined)[methodName]();
|
||||
}).toThrow('Expected a spy, but got undefined.');
|
||||
expect(
|
||||
function() {
|
||||
match(jasmine.undefined)[methodName]();
|
||||
}).toThrow('Expected a spy, but got undefined.');
|
||||
|
||||
expect(function() {
|
||||
match({some:'object'})[methodName]();
|
||||
}).toThrow('Expected a spy, but got { some : \'object\' }.');
|
||||
expect(
|
||||
function() {
|
||||
match({some:'object'})[methodName]();
|
||||
}).toThrow('Expected a spy, but got { some : \'object\' }.');
|
||||
|
||||
expect(function() {
|
||||
match("<b>")[methodName]();
|
||||
}).toThrow('Expected a spy, but got \'<b>\'.');
|
||||
expect(
|
||||
function() {
|
||||
match("<b>")[methodName]();
|
||||
}).toThrow('Expected a spy, but got \'<b>\'.');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -623,9 +664,10 @@ describe("jasmine.Matchers", function() {
|
||||
});
|
||||
|
||||
it("should throw an exception when invoked with any arguments", function() {
|
||||
expect(function() {
|
||||
match(TestClass.normalFunction).toHaveBeenCalled("unwanted argument");
|
||||
}).toThrow('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
|
||||
expect(
|
||||
function() {
|
||||
match(TestClass.normalFunction).toHaveBeenCalled("unwanted argument");
|
||||
}).toThrow('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
|
||||
});
|
||||
|
||||
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalled'));
|
||||
@@ -651,9 +693,10 @@ describe("jasmine.Matchers", function() {
|
||||
});
|
||||
|
||||
it("should throw an exception when invoked with any arguments", function() {
|
||||
expect(function() {
|
||||
match(TestClass.normalFunction).wasNotCalled("unwanted argument");
|
||||
}).toThrow('wasNotCalled does not take arguments');
|
||||
expect(
|
||||
function() {
|
||||
match(TestClass.normalFunction).wasNotCalled("unwanted argument");
|
||||
}).toThrow('wasNotCalled does not take arguments');
|
||||
});
|
||||
|
||||
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
|
||||
@@ -701,7 +744,7 @@ describe("jasmine.Matchers", function() {
|
||||
TestClass.spyFunction('d', 'e', 'f');
|
||||
var expected = match(TestClass.spyFunction);
|
||||
expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
|
||||
expect(lastResult().message).toEqual("Expected spy to have been called with [ 'a', 'b' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
|
||||
expect(lastResult().message).toEqual("Expected spy My spy to have been called with [ 'a', 'b' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
|
||||
});
|
||||
|
||||
it("should return a decent message when inverted", function() {
|
||||
@@ -709,7 +752,7 @@ describe("jasmine.Matchers", function() {
|
||||
TestClass.spyFunction('d', 'e', 'f');
|
||||
var expected = match(TestClass.spyFunction);
|
||||
expect(expected.not.toHaveBeenCalledWith('a', 'b', 'c')).toFail();
|
||||
expect(lastResult().message).toEqual("Expected spy not to have been called with [ 'a', 'b', 'c' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
|
||||
expect(lastResult().message).toEqual("Expected spy My spy not to have been called with [ 'a', 'b', 'c' ] but was called with [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ]");
|
||||
});
|
||||
|
||||
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalledWith'));
|
||||
@@ -18,9 +18,9 @@ describe("jasmine.MultiReporter", function() {
|
||||
delegate[methodName] = jasmine.createSpy(methodName);
|
||||
this.actual[methodName]("whatever argument");
|
||||
|
||||
return delegate[methodName].wasCalled
|
||||
&& delegate[methodName].mostRecentCall.args.length == 1
|
||||
&& delegate[methodName].mostRecentCall.args[0] == "whatever argument";
|
||||
return delegate[methodName].wasCalled &&
|
||||
delegate[methodName].mostRecentCall.args.length == 1 &&
|
||||
delegate[methodName].mostRecentCall.args[0] == "whatever argument";
|
||||
}
|
||||
});
|
||||
|
||||
@@ -58,12 +58,6 @@ describe("jasmine.pp", function () {
|
||||
}
|
||||
});
|
||||
|
||||
it("should stringify HTML nodes properly", function() {
|
||||
var sampleNode = document.createElement('div');
|
||||
sampleNode.innerHTML = 'foo<b>bar</b>';
|
||||
expect(jasmine.pp(sampleNode)).toEqual("HTMLNode");
|
||||
expect(jasmine.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }");
|
||||
});
|
||||
|
||||
it('should not do HTML escaping of strings', function() {
|
||||
expect(jasmine.pp('some <b>html string</b> &', false)).toEqual('\'some <b>html string</b> &\'');
|
||||
@@ -54,7 +54,7 @@ describe("jasmine spec running", function () {
|
||||
this.expect(foo).toEqual('baz');
|
||||
});
|
||||
|
||||
specWithMultipleExpectations = env.it('spec with multiple assertions').runs(function () {
|
||||
specWithMultipleExpectations = env.it('spec with multiple expectations').runs(function () {
|
||||
var foo = 'bar';
|
||||
var baz = 'quux';
|
||||
|
||||
@@ -1225,6 +1225,9 @@ describe("jasmine spec running", function () {
|
||||
this.expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
throw new Error("fake error");
|
||||
|
||||
});
|
||||
} catch(e) {
|
||||
}
|
||||
@@ -1240,14 +1243,16 @@ describe("jasmine spec running", function () {
|
||||
|
||||
expect(specs.join('')).toMatch(new RegExp(
|
||||
'Spec: outer1 inner1 should thingy.' +
|
||||
'Result: Passed.' +
|
||||
'Spec: outer1 encountered a declaration exception.' +
|
||||
'Result: Error: fake error.*' +
|
||||
'Spec: outer1 inner2 should other thingy.' +
|
||||
'Result: Passed.' +
|
||||
'Spec: outer2 should xxx.' +
|
||||
'Result: Passed.'
|
||||
));
|
||||
'Result: Passed.' +
|
||||
'Spec: outer1 inner1 encountered a declaration exception.' +
|
||||
'Result: Error: fake error.*' +
|
||||
'Spec: outer1 inner2 should other thingy.' +
|
||||
'Result: Passed.' +
|
||||
'Spec: outer1 encountered a declaration exception.' +
|
||||
'Result: Error: fake error.*' +
|
||||
'Spec: outer2 should xxx.' +
|
||||
'Result: Passed.'
|
||||
));
|
||||
});
|
||||
|
||||
});
|
||||
@@ -38,7 +38,7 @@ describe('Spec', function () {
|
||||
|
||||
it('getFullName returns suite & spec description', function () {
|
||||
var spec = new jasmine.Spec(env, suite, 'spec 1');
|
||||
expect(spec.getFullName()).toEqual('suite 1 spec 1.')
|
||||
expect(spec.getFullName()).toEqual('suite 1 spec 1.');
|
||||
});
|
||||
|
||||
describe('results', function () {
|
||||
@@ -25,7 +25,6 @@ describe("jasmine.util", 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() {
|
||||
@@ -10,6 +10,37 @@ describe('WaitsForBlock', function () {
|
||||
onComplete = jasmine.createSpy("onComplete");
|
||||
});
|
||||
|
||||
describe("jasmine.VERBOSE", function() {
|
||||
var jasmineVerboseOriginal;
|
||||
beforeEach(function() {
|
||||
jasmineVerboseOriginal = jasmine.VERBOSE;
|
||||
spyOn(env.reporter, 'log');
|
||||
|
||||
});
|
||||
it('do not show information if jasmine.VERBOSE is set to false', function () {
|
||||
jasmine.VERBOSE = false;
|
||||
var latchFunction = function() {
|
||||
return true;
|
||||
};
|
||||
var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
|
||||
expect(env.reporter.log).not.toHaveBeenCalled();
|
||||
block.execute(onComplete);
|
||||
expect(env.reporter.log).not.toHaveBeenCalled();
|
||||
jasmine.VERBOSE = jasmineVerboseOriginal;
|
||||
});
|
||||
it('show information if jasmine.VERBOSE is set to true', function () {
|
||||
jasmine.VERBOSE = true;
|
||||
var latchFunction = function() {
|
||||
return true;
|
||||
};
|
||||
var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
|
||||
expect(env.reporter.log).not.toHaveBeenCalled();
|
||||
block.execute(onComplete);
|
||||
expect(env.reporter.log).toHaveBeenCalled();
|
||||
jasmine.VERBOSE = jasmineVerboseOriginal;
|
||||
});
|
||||
});
|
||||
|
||||
it('onComplete should be called if the latchFunction returns true', function () {
|
||||
var latchFunction = function() {
|
||||
return true;
|
||||
@@ -84,4 +115,4 @@ describe('WaitsForBlock', function () {
|
||||
expect(onComplete).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
38
spec/html/MatchersHtmlSpec.js
Normal file
@@ -0,0 +1,38 @@
|
||||
describe("MatchersSpec - HTML Dependent", function () {
|
||||
var env, spec;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmine.Env();
|
||||
env.updateInterval = 0;
|
||||
|
||||
var suite = env.describe("suite", function() {
|
||||
spec = env.it("spec", function() {
|
||||
});
|
||||
});
|
||||
spyOn(spec, 'addMatcherResult');
|
||||
|
||||
this.addMatchers({
|
||||
toPass: function() {
|
||||
return lastResult().passed();
|
||||
},
|
||||
toFail: function() {
|
||||
return !lastResult().passed();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function match(value) {
|
||||
return spec.expect(value);
|
||||
}
|
||||
|
||||
function lastResult() {
|
||||
return spec.addMatcherResult.mostRecentCall.args[0];
|
||||
}
|
||||
|
||||
it("toEqual with DOM nodes", function() {
|
||||
var nodeA = document.createElement('div');
|
||||
var nodeB = document.createElement('div');
|
||||
expect((match(nodeA).toEqual(nodeA))).toPass();
|
||||
expect((match(nodeA).toEqual(nodeB))).toFail();
|
||||
});
|
||||
});
|
||||
8
spec/html/PrettyPrintHtmlSpec.js
Normal file
@@ -0,0 +1,8 @@
|
||||
describe("jasmine.pp (HTML Dependent)", function () {
|
||||
it("should stringify HTML nodes properly", function() {
|
||||
var sampleNode = document.createElement('div');
|
||||
sampleNode.innerHTML = 'foo<b>bar</b>';
|
||||
expect(jasmine.pp(sampleNode)).toEqual("HTMLNode");
|
||||
expect(jasmine.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }");
|
||||
});
|
||||
});
|
||||
@@ -31,7 +31,9 @@ describe("TrivialReporter", function() {
|
||||
|
||||
function findElement(divs, withClass) {
|
||||
var els = findElements(divs, withClass);
|
||||
if (els.length > 0) return els[0];
|
||||
if (els.length > 0) {
|
||||
return els[0];
|
||||
}
|
||||
throw new Error("couldn't find div with class " + withClass);
|
||||
}
|
||||
|
||||
@@ -96,7 +98,6 @@ describe("TrivialReporter", function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("failure messages (integration)", function () {
|
||||
var spec, results, expectationResult;
|
||||
|
||||
127
spec/node_suite.js
Normal file
@@ -0,0 +1,127 @@
|
||||
var fs = require('fs');
|
||||
var sys = require('sys');
|
||||
var path = require('path');
|
||||
|
||||
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
|
||||
// undefined = "diz be undefined yo";
|
||||
|
||||
|
||||
var jasmineGlobals = require('../lib/jasmine-core/jasmine.js');
|
||||
for (var k in jasmineGlobals) {
|
||||
global[k] = jasmineGlobals[k];
|
||||
}
|
||||
require('../src/console/ConsoleReporter.js');
|
||||
|
||||
/*
|
||||
Pulling in code from jasmine-node.
|
||||
|
||||
We can't just depend on jasmine-node because it has its own jasmine that it uses.
|
||||
*/
|
||||
|
||||
global.window = {
|
||||
setTimeout: setTimeout,
|
||||
clearTimeout: clearTimeout,
|
||||
setInterval: setInterval,
|
||||
clearInterval: clearInterval
|
||||
};
|
||||
|
||||
delete global.window;
|
||||
|
||||
function noop() {
|
||||
}
|
||||
|
||||
jasmine.executeSpecs = function(specs, done, isVerbose, showColors) {
|
||||
for (var i = 0, len = specs.length; i < len; ++i) {
|
||||
var filename = specs[i];
|
||||
require(filename.replace(/\.\w+$/, ""));
|
||||
}
|
||||
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
var consoleReporter = new jasmine.ConsoleReporter(sys.print, done, showColors);
|
||||
|
||||
jasmineEnv.addReporter(consoleReporter);
|
||||
jasmineEnv.execute();
|
||||
};
|
||||
|
||||
jasmine.getAllSpecFiles = function(dir, matcher) {
|
||||
var specs = [];
|
||||
|
||||
if (fs.statSync(dir).isFile() && dir.match(matcher)) {
|
||||
specs.push(dir);
|
||||
} else {
|
||||
var files = fs.readdirSync(dir);
|
||||
for (var i = 0, len = files.length; i < len; ++i) {
|
||||
var filename = dir + '/' + files[i];
|
||||
if (fs.statSync(filename).isFile() && filename.match(matcher)) {
|
||||
specs.push(filename);
|
||||
} else if (fs.statSync(filename).isDirectory()) {
|
||||
var subfiles = this.getAllSpecFiles(filename, matcher);
|
||||
subfiles.forEach(function(result) {
|
||||
specs.push(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return specs;
|
||||
};
|
||||
|
||||
function now() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
jasmine.asyncSpecWait = function() {
|
||||
var wait = jasmine.asyncSpecWait;
|
||||
wait.start = now();
|
||||
wait.done = false;
|
||||
(function innerWait() {
|
||||
waits(10);
|
||||
runs(function() {
|
||||
if (wait.start + wait.timeout < now()) {
|
||||
expect('timeout waiting for spec').toBeNull();
|
||||
} else if (wait.done) {
|
||||
wait.done = false;
|
||||
} else {
|
||||
innerWait();
|
||||
}
|
||||
});
|
||||
})();
|
||||
};
|
||||
jasmine.asyncSpecWait.timeout = 4 * 1000;
|
||||
jasmine.asyncSpecDone = function() {
|
||||
jasmine.asyncSpecWait.done = true;
|
||||
};
|
||||
|
||||
for (var key in jasmine) {
|
||||
exports[key] = jasmine[key];
|
||||
}
|
||||
|
||||
/*
|
||||
End jasmine-node runner
|
||||
*/
|
||||
|
||||
var isVerbose = false;
|
||||
var showColors = true;
|
||||
process.argv.forEach(function(arg) {
|
||||
switch (arg) {
|
||||
case '--color': showColors = true; break;
|
||||
case '--noColor': showColors = false; break;
|
||||
case '--verbose': isVerbose = true; break;
|
||||
}
|
||||
});
|
||||
|
||||
var specs = jasmine.getAllSpecFiles(__dirname, new RegExp(".js$"));
|
||||
var domIndependentSpecs = [];
|
||||
for (var i = 0; i < specs.length; i++) {
|
||||
if (fs.readFileSync(specs[i], "utf8").indexOf("document.createElement") < 0) {
|
||||
domIndependentSpecs.push(specs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
jasmine.executeSpecs(domIndependentSpecs, function(runner, log) {
|
||||
if (runner.results().failedCount === 0) {
|
||||
process.exit(0);
|
||||
} else {
|
||||
process.exit(1);
|
||||
}
|
||||
}, isVerbose, showColors);
|
||||
@@ -2,56 +2,46 @@
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Jasmine Test Runner</title>
|
||||
<title>Jasmine Spec Runner: Jasmine Core</title>
|
||||
|
||||
<link rel="shortcut icon" type="image/png" href="../images/jasmine_favicon.png">
|
||||
|
||||
<link href="../lib/jasmine-core/jasmine.css" rel="stylesheet"/>
|
||||
<script type="text/javascript" src="../lib/jasmine-core/jasmine.js"></script>
|
||||
<script type="text/javascript">
|
||||
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
|
||||
undefined = "diz be undefined yo";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="../src/base.js"></script>
|
||||
<script type="text/javascript" src="../src/util.js"></script>
|
||||
<script type="text/javascript" src="../src/Env.js"></script>
|
||||
<script type="text/javascript" src="../src/Reporter.js"></script>
|
||||
<script type="text/javascript" src="../src/Block.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../src/JsApiReporter.js"></script>
|
||||
<script type="text/javascript" src="../src/Matchers.js"></script>
|
||||
<script type="text/javascript" src="../src/mock-timeout.js"></script>
|
||||
<script type="text/javascript" src="../src/MultiReporter.js"></script>
|
||||
<script type="text/javascript" src="../src/NestedResults.js"></script>
|
||||
<script type="text/javascript" src="../src/PrettyPrinter.js"></script>
|
||||
<script type="text/javascript" src="../src/Queue.js"></script>
|
||||
<script type="text/javascript" src="../src/Runner.js"></script>
|
||||
<script type="text/javascript" src="../src/Spec.js"></script>
|
||||
<script type="text/javascript" src="../src/Suite.js"></script>
|
||||
<script type="text/javascript" src="../src/WaitsBlock.js"></script>
|
||||
<script type="text/javascript" src="../src/WaitsForBlock.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../src/html/TrivialReporter.js"></script>
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript" src="suites/BaseSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/CustomMatchersSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/EnvSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/ExceptionsSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/JsApiReporterSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/MatchersSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/MockClockSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/MultiReporterSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/NestedResultsSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/PrettyPrintSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/ReporterSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/RunnerSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/QueueSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/SpecSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/SpecRunningSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/SpySpec.js"></script>
|
||||
<script type="text/javascript" src="suites/SuiteSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/TrivialReporterSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/WaitsForBlockSpec.js"></script>
|
||||
<!-- include source files here... -->
|
||||
<script type="text/javascript" src=".././src/html/TrivialReporter.js"></script>
|
||||
<script type="text/javascript" src=".././src/console/ConsoleReporter.js"></script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script type="text/javascript" src=".././spec/core/BaseSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/CustomMatchersSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/EnvSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/ExceptionsSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/JsApiReporterSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/MatchersSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/MockClockSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/MultiReporterSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/NestedResultsSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/PrettyPrintSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/QueueSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/ReporterSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/RunnerSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/SpecRunningSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/SpecSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/SpySpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/SuiteSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/UtilSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/core/WaitsForBlockSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/html/MatchersHtmlSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/html/PrettyPrintHtmlSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/html/TrivialReporterSpec.js"></script>
|
||||
<script type="text/javascript" src=".././spec/console/ConsoleReporterSpec.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
@@ -66,15 +56,24 @@
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
jasmineEnv.execute();
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
execJasmine();
|
||||
};
|
||||
|
||||
function execJasmine() {
|
||||
jasmineEnv.execute();
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
<link href="../src/html/jasmine.css" rel="stylesheet"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
49
spec/templates/runner.html.erb
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title><%= title %></title>
|
||||
|
||||
<%= favicon %>
|
||||
<%= jasmine_tags %>
|
||||
|
||||
<!-- include source files here... -->
|
||||
<%= source_tags %>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<%= spec_file_tags %>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.updateInterval = 1000;
|
||||
|
||||
var trivialReporter = new jasmine.TrivialReporter();
|
||||
|
||||
jasmineEnv.addReporter(trivialReporter);
|
||||
|
||||
jasmineEnv.specFilter = function(spec) {
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
execJasmine();
|
||||
};
|
||||
|
||||
function execJasmine() {
|
||||
jasmineEnv.execute();
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
1
spec/templates/script_tag.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<script type="text/javascript" src="<%= file %>"></script>
|
||||
7
src/SourcesList.json
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"base.js",
|
||||
"util.js",
|
||||
"Env.js",
|
||||
"Reporter.js",
|
||||
"Block.js"
|
||||
]
|
||||
177
src/console/ConsoleReporter.js
Normal file
@@ -0,0 +1,177 @@
|
||||
jasmine.ConsoleReporter = function(print, doneCallback, showColors) {
|
||||
//inspired by mhevery's jasmine-node reporter
|
||||
//https://github.com/mhevery/jasmine-node
|
||||
|
||||
doneCallback = doneCallback || function() {};
|
||||
|
||||
var ansi = {
|
||||
green: '\033[32m',
|
||||
red: '\033[31m',
|
||||
yellow: '\033[33m',
|
||||
none: '\033[0m'
|
||||
},
|
||||
language = {
|
||||
spec: "spec",
|
||||
failure: "failure"
|
||||
};
|
||||
|
||||
function coloredStr(color, str) {
|
||||
return showColors ? (ansi[color] + str + ansi.none) : str;
|
||||
}
|
||||
|
||||
function greenStr(str) {
|
||||
return coloredStr("green", str);
|
||||
}
|
||||
|
||||
function redStr(str) {
|
||||
return coloredStr("red", str);
|
||||
}
|
||||
|
||||
function yellowStr(str) {
|
||||
return coloredStr("yellow", str);
|
||||
}
|
||||
|
||||
function newline() {
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function started() {
|
||||
print("Started");
|
||||
newline();
|
||||
}
|
||||
|
||||
function greenDot() {
|
||||
print(greenStr("."));
|
||||
}
|
||||
|
||||
function redF() {
|
||||
print(redStr("F"));
|
||||
}
|
||||
|
||||
function yellowStar() {
|
||||
print(yellowStr("*"));
|
||||
}
|
||||
|
||||
function plural(str, count) {
|
||||
return count == 1 ? str : str + "s";
|
||||
}
|
||||
|
||||
function repeat(thing, times) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < times; i++) {
|
||||
arr.push(thing);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
function indent(str, spaces) {
|
||||
var lines = (str || '').split("\n");
|
||||
var newArr = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
newArr.push(repeat(" ", spaces).join("") + lines[i]);
|
||||
}
|
||||
return newArr.join("\n");
|
||||
}
|
||||
|
||||
function specFailureDetails(suiteDescription, specDescription, stackTraces) {
|
||||
newline();
|
||||
print(suiteDescription + " " + specDescription);
|
||||
newline();
|
||||
for (var i = 0; i < stackTraces.length; i++) {
|
||||
print(indent(stackTraces[i], 2));
|
||||
newline();
|
||||
}
|
||||
}
|
||||
|
||||
function finished(elapsed) {
|
||||
newline();
|
||||
print("Finished in " + elapsed / 1000 + " seconds");
|
||||
}
|
||||
|
||||
function summary(colorF, specs, failed) {
|
||||
newline();
|
||||
print(colorF(specs + " " + plural(language.spec, specs) + ", " +
|
||||
failed + " " + plural(language.failure, failed)));
|
||||
newline();
|
||||
newline();
|
||||
}
|
||||
|
||||
function greenSummary(specs, failed) {
|
||||
summary(greenStr, specs, failed);
|
||||
}
|
||||
|
||||
function redSummary(specs, failed) {
|
||||
summary(redStr, specs, failed);
|
||||
}
|
||||
|
||||
function fullSuiteDescription(suite) {
|
||||
var fullDescription = suite.description;
|
||||
if (suite.parentSuite) fullDescription = fullSuiteDescription(suite.parentSuite) + " " + fullDescription;
|
||||
return fullDescription;
|
||||
}
|
||||
|
||||
this.now = function() {
|
||||
return new Date().getTime();
|
||||
};
|
||||
|
||||
this.reportRunnerStarting = function() {
|
||||
this.runnerStartTime = this.now();
|
||||
started();
|
||||
};
|
||||
|
||||
this.reportSpecStarting = function() { /* do nothing */
|
||||
};
|
||||
|
||||
this.reportSpecResults = function(spec) {
|
||||
var results = spec.results();
|
||||
if (results.skipped) {
|
||||
yellowStar();
|
||||
} else if (results.passed()) {
|
||||
greenDot();
|
||||
} else {
|
||||
redF();
|
||||
}
|
||||
};
|
||||
|
||||
this.suiteResults = [];
|
||||
|
||||
this.reportSuiteResults = function(suite) {
|
||||
var suiteResult = {
|
||||
description: fullSuiteDescription(suite),
|
||||
failedSpecResults: []
|
||||
};
|
||||
|
||||
suite.results().items_.forEach(function(spec) {
|
||||
if (spec.failedCount > 0 && spec.description) suiteResult.failedSpecResults.push(spec);
|
||||
});
|
||||
|
||||
this.suiteResults.push(suiteResult);
|
||||
};
|
||||
|
||||
function eachSpecFailure(suiteResults, callback) {
|
||||
for (var i = 0; i < suiteResults.length; i++) {
|
||||
var suiteResult = suiteResults[i];
|
||||
for (var j = 0; j < suiteResult.failedSpecResults.length; j++) {
|
||||
var failedSpecResult = suiteResult.failedSpecResults[j];
|
||||
var stackTraces = [];
|
||||
for (var k = 0; k < failedSpecResult.items_.length; k++) stackTraces.push(failedSpecResult.items_[k].trace.stack);
|
||||
callback(suiteResult.description, failedSpecResult.description, stackTraces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.reportRunnerResults = function(runner) {
|
||||
newline();
|
||||
|
||||
eachSpecFailure(this.suiteResults, function(suiteDescription, specDescription, stackTraces) {
|
||||
specFailureDetails(suiteDescription, specDescription, stackTraces);
|
||||
});
|
||||
|
||||
finished(this.now() - this.runnerStartTime);
|
||||
|
||||
var results = runner.results();
|
||||
var summaryFunction = results.failedCount === 0 ? greenSummary : redSummary;
|
||||
summaryFunction(runner.specs().length, results.failedCount);
|
||||
doneCallback(runner);
|
||||
};
|
||||
};
|
||||
@@ -19,4 +19,4 @@ jasmine.Block.prototype.execute = function(onComplete) {
|
||||
this.spec.fail(e);
|
||||
}
|
||||
onComplete();
|
||||
};
|
||||
};
|
||||
@@ -51,12 +51,17 @@ jasmine.Env.prototype.version = function () {
|
||||
* @returns string containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.versionString = function() {
|
||||
if (jasmine.version_) {
|
||||
var version = this.version();
|
||||
return version.major + "." + version.minor + "." + version.build + " revision " + version.revision;
|
||||
} else {
|
||||
if (!jasmine.version_) {
|
||||
return "version unknown";
|
||||
}
|
||||
|
||||
var version = this.version();
|
||||
var versionString = version.major + "." + version.minor + "." + version.build;
|
||||
if (version.release_candidate) {
|
||||
versionString += ".rc" + version.release_candidate
|
||||
}
|
||||
versionString += " revision " + version.revision;
|
||||
return versionString;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -104,14 +109,14 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
declarationError = e;
|
||||
}
|
||||
|
||||
this.currentSuite = parentSuite;
|
||||
|
||||
if (declarationError) {
|
||||
this.it("encountered a declaration exception", function() {
|
||||
throw declarationError;
|
||||
});
|
||||
}
|
||||
|
||||
this.currentSuite = parentSuite;
|
||||
|
||||
return suite;
|
||||
};
|
||||
|
||||
@@ -172,7 +177,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
||||
b.__Jasmine_been_here_before__ = a;
|
||||
|
||||
var hasKey = function(obj, keyName) {
|
||||
return obj != null && obj[keyName] !== jasmine.undefined;
|
||||
return obj !== null && obj[keyName] !== jasmine.undefined;
|
||||
};
|
||||
|
||||
for (var property in b) {
|
||||
@@ -198,7 +203,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
||||
|
||||
delete a.__Jasmine_been_here_before__;
|
||||
delete b.__Jasmine_been_here_before__;
|
||||
return (mismatchKeys.length == 0 && mismatchValues.length == 0);
|
||||
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
@@ -227,16 +227,16 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
|
||||
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
|
||||
}
|
||||
this.message = function() {
|
||||
if (this.actual.callCount == 0) {
|
||||
if (this.actual.callCount === 0) {
|
||||
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
|
||||
return [
|
||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
|
||||
"Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
||||
"Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
|
||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
|
||||
"Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall),
|
||||
"Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall)
|
||||
];
|
||||
}
|
||||
};
|
||||
@@ -258,7 +258,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
|
||||
return [
|
||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
|
||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
|
||||
]
|
||||
];
|
||||
};
|
||||
|
||||
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
|
||||
@@ -291,6 +291,23 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
|
||||
return this.actual > expected;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that checks that the expected item is equal to the actual item
|
||||
* up to a given level of decimal precision (default 2).
|
||||
*
|
||||
* @param {Number} expected
|
||||
* @param {Number} precision
|
||||
*/
|
||||
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
|
||||
if (!(precision === 0)) {
|
||||
precision = precision || 2;
|
||||
}
|
||||
var multiplier = Math.pow(10, precision);
|
||||
var actual = Math.round(this.actual * multiplier);
|
||||
expected = Math.round(expected * multiplier);
|
||||
return expected == actual;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that checks that the expected exception was thrown by the actual.
|
||||
*
|
||||
@@ -315,7 +332,7 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
|
||||
|
||||
this.message = function() {
|
||||
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
|
||||
return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
|
||||
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
|
||||
} else {
|
||||
return "Expected function to throw an exception.";
|
||||
}
|
||||
@@ -58,7 +58,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
|
||||
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
||||
for (var property in obj) {
|
||||
if (property == '__Jasmine_been_here_before__') continue;
|
||||
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false);
|
||||
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
|
||||
obj.__lookupGetter__(property) !== null) : false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,4 +74,4 @@ jasmine.Runner.prototype.topLevelSuites = function() {
|
||||
|
||||
jasmine.Runner.prototype.results = function() {
|
||||
return this.queue.results();
|
||||
};
|
||||
};
|
||||
@@ -120,7 +120,8 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag
|
||||
jasmine.Spec.prototype.fail = function (e) {
|
||||
var expectationResult = new jasmine.ExpectationResult({
|
||||
passed: false,
|
||||
message: e ? jasmine.util.formatException(e) : 'Exception'
|
||||
message: e ? jasmine.util.formatException(e) : 'Exception',
|
||||
trace: { stack: e.stack }
|
||||
});
|
||||
this.results_.addResult(expectationResult);
|
||||
};
|
||||
@@ -79,4 +79,4 @@ jasmine.Suite.prototype.execute = function(onComplete) {
|
||||
this.queue.start(function () {
|
||||
self.finish(onComplete);
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -6,7 +6,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) {
|
||||
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
|
||||
|
||||
jasmine.WaitsBlock.prototype.execute = function (onComplete) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
|
||||
if (jasmine.VERBOSE) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
|
||||
}
|
||||
this.env.setTimeout(function () {
|
||||
onComplete();
|
||||
}, this.timeout);
|
||||
@@ -21,7 +21,9 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
|
||||
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
|
||||
|
||||
jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
|
||||
if (jasmine.VERBOSE) {
|
||||
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
|
||||
}
|
||||
var latchFunctionResult;
|
||||
try {
|
||||
latchFunctionResult = this.latchFunction.apply(this.spec);
|
||||
@@ -49,4 +51,4 @@ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
|
||||
self.execute(onComplete);
|
||||
}, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,10 +1,12 @@
|
||||
var isCommonJS = typeof window == "undefined";
|
||||
|
||||
/**
|
||||
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
||||
*
|
||||
* @namespace
|
||||
*/
|
||||
var jasmine = {};
|
||||
|
||||
if (isCommonJS) exports.jasmine = jasmine;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -20,6 +22,12 @@ jasmine.unimplementedMethod_ = function() {
|
||||
*/
|
||||
jasmine.undefined = jasmine.___undefined___;
|
||||
|
||||
/**
|
||||
* Show diagnostic messages in the console if set to true
|
||||
*
|
||||
*/
|
||||
jasmine.VERBOSE = false;
|
||||
|
||||
/**
|
||||
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
|
||||
*
|
||||
@@ -72,7 +80,7 @@ jasmine.MessageResult = function(values) {
|
||||
|
||||
jasmine.MessageResult.prototype.toString = function() {
|
||||
var text = "";
|
||||
for(var i = 0; i < this.values.length; i++) {
|
||||
for (var i = 0; i < this.values.length; i++) {
|
||||
if (i > 0) text += " ";
|
||||
if (jasmine.isString_(this.values[i])) {
|
||||
text += this.values[i];
|
||||
@@ -89,9 +97,10 @@ jasmine.ExpectationResult = function(params) {
|
||||
this.passed_ = params.passed;
|
||||
this.expected = params.expected;
|
||||
this.actual = params.actual;
|
||||
|
||||
this.message = this.passed_ ? 'Passed.' : params.message;
|
||||
this.trace = this.passed_ ? '' : new Error(this.message);
|
||||
|
||||
var trace = (params.trace || new Error(this.message));
|
||||
this.trace = this.passed_ ? '' : trace;
|
||||
};
|
||||
|
||||
jasmine.ExpectationResult.prototype.toString = function () {
|
||||
@@ -106,7 +115,8 @@ jasmine.ExpectationResult.prototype.passed = function () {
|
||||
* Getter for the Jasmine environment. Ensures one gets created
|
||||
*/
|
||||
jasmine.getEnv = function() {
|
||||
return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||
return env;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,7 +126,7 @@ jasmine.getEnv = function() {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
jasmine.isArray_ = function(value) {
|
||||
return jasmine.isA_("Array", value);
|
||||
return jasmine.isA_("Array", value);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -169,7 +179,7 @@ jasmine.pp = function(value) {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
jasmine.isDomNode = function(obj) {
|
||||
return obj['nodeType'] > 0;
|
||||
return obj.nodeType > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -405,7 +415,7 @@ jasmine.isSpy = function(putativeSpy) {
|
||||
* @param {Array} methodNames array of names of methods to make spies
|
||||
*/
|
||||
jasmine.createSpyObj = function(baseName, methodNames) {
|
||||
if (!jasmine.isArray_(methodNames) || methodNames.length == 0) {
|
||||
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
|
||||
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
|
||||
}
|
||||
var obj = {};
|
||||
@@ -443,6 +453,7 @@ jasmine.log = function() {
|
||||
var spyOn = function(obj, methodName) {
|
||||
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
||||
};
|
||||
if (isCommonJS) exports.spyOn = spyOn;
|
||||
|
||||
/**
|
||||
* Creates a Jasmine spec that will be added to the current suite.
|
||||
@@ -460,6 +471,7 @@ var spyOn = function(obj, methodName) {
|
||||
var it = function(desc, func) {
|
||||
return jasmine.getEnv().it(desc, func);
|
||||
};
|
||||
if (isCommonJS) exports.it = it;
|
||||
|
||||
/**
|
||||
* Creates a <em>disabled</em> Jasmine spec.
|
||||
@@ -472,6 +484,7 @@ var it = function(desc, func) {
|
||||
var xit = function(desc, func) {
|
||||
return jasmine.getEnv().xit(desc, func);
|
||||
};
|
||||
if (isCommonJS) exports.xit = xit;
|
||||
|
||||
/**
|
||||
* Starts a chain for a Jasmine expectation.
|
||||
@@ -484,6 +497,7 @@ var xit = function(desc, func) {
|
||||
var expect = function(actual) {
|
||||
return jasmine.getEnv().currentSpec.expect(actual);
|
||||
};
|
||||
if (isCommonJS) exports.expect = expect;
|
||||
|
||||
/**
|
||||
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
||||
@@ -493,6 +507,7 @@ var expect = function(actual) {
|
||||
var runs = function(func) {
|
||||
jasmine.getEnv().currentSpec.runs(func);
|
||||
};
|
||||
if (isCommonJS) exports.runs = runs;
|
||||
|
||||
/**
|
||||
* Waits a fixed time period before moving to the next block.
|
||||
@@ -503,6 +518,7 @@ var runs = function(func) {
|
||||
var waits = function(timeout) {
|
||||
jasmine.getEnv().currentSpec.waits(timeout);
|
||||
};
|
||||
if (isCommonJS) exports.waits = waits;
|
||||
|
||||
/**
|
||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||
@@ -514,6 +530,7 @@ var waits = function(timeout) {
|
||||
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
||||
};
|
||||
if (isCommonJS) exports.waitsFor = waitsFor;
|
||||
|
||||
/**
|
||||
* A function that is called before each spec in a suite.
|
||||
@@ -525,6 +542,7 @@ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout
|
||||
var beforeEach = function(beforeEachFunction) {
|
||||
jasmine.getEnv().beforeEach(beforeEachFunction);
|
||||
};
|
||||
if (isCommonJS) exports.beforeEach = beforeEach;
|
||||
|
||||
/**
|
||||
* A function that is called after each spec in a suite.
|
||||
@@ -536,6 +554,7 @@ var beforeEach = function(beforeEachFunction) {
|
||||
var afterEach = function(afterEachFunction) {
|
||||
jasmine.getEnv().afterEach(afterEachFunction);
|
||||
};
|
||||
if (isCommonJS) exports.afterEach = afterEach;
|
||||
|
||||
/**
|
||||
* Defines a suite of specifications.
|
||||
@@ -555,6 +574,7 @@ var afterEach = function(afterEachFunction) {
|
||||
var describe = function(description, specDefinitions) {
|
||||
return jasmine.getEnv().describe(description, specDefinitions);
|
||||
};
|
||||
if (isCommonJS) exports.describe = describe;
|
||||
|
||||
/**
|
||||
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
||||
@@ -565,25 +585,33 @@ var describe = function(description, specDefinitions) {
|
||||
var xdescribe = function(description, specDefinitions) {
|
||||
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
||||
};
|
||||
if (isCommonJS) exports.xdescribe = xdescribe;
|
||||
|
||||
|
||||
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
||||
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
||||
try {
|
||||
function tryIt(f) {
|
||||
try {
|
||||
return f();
|
||||
} catch(e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var xhr = tryIt(function() {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP");
|
||||
} catch(e) {
|
||||
}
|
||||
try {
|
||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch(e) {
|
||||
}
|
||||
throw new Error("This browser does not support XMLHttpRequest.");
|
||||
}) ||
|
||||
tryIt(function() {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
||||
}) ||
|
||||
tryIt(function() {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}) ||
|
||||
tryIt(function() {
|
||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||
});
|
||||
|
||||
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
|
||||
|
||||
return xhr;
|
||||
} : XMLHttpRequest;
|
||||
@@ -17,7 +17,7 @@ jasmine.util.inherit = function(childClass, parentClass) {
|
||||
var subclass = function() {
|
||||
};
|
||||
subclass.prototype = parentClass.prototype;
|
||||
childClass.prototype = new subclass;
|
||||
childClass.prototype = new subclass();
|
||||
};
|
||||
|
||||
jasmine.util.formatException = function(e) {
|
||||
@@ -34,7 +34,7 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
|
||||
this.createDom('div', { className: 'banner' },
|
||||
this.createDom('div', { className: 'logo' },
|
||||
this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
|
||||
this.createDom('span', { className: 'title' }, "Jasmine"),
|
||||
this.createDom('span', { className: 'version' }, runner.env.versionString())),
|
||||
this.createDom('div', { className: 'options' },
|
||||
"Show ",
|
||||
@@ -110,7 +110,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
||||
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
||||
var results = suite.results();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
||||
if (results.totalCount === 0) { // todo: change this to check results.skipped
|
||||
status = 'skipped';
|
||||
}
|
||||
this.suiteDivs[suite.id].className += " " + status;
|
||||
@@ -183,6 +183,8 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||
}
|
||||
|
||||
if (!paramMap["spec"]) return true;
|
||||
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
||||
if (!paramMap.spec) {
|
||||
return true;
|
||||
}
|
||||
return spec.getFullName().indexOf(paramMap.spec) === 0;
|
||||
};
|
||||
|
||||
3
src/templates/example_project_jasmine_tags.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<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 %>/jasmine-html.js"></script>
|
||||
6
src/templates/version.js.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
jasmine.version_= {
|
||||
"major": <%= major %>,
|
||||
"minor": <%= minor %>,
|
||||
"build": <%= build %>,
|
||||
"revision": <%= revision %><%= %Q{,\n "release_candidate": #{release_candidate}} if release_candidate %>
|
||||
};
|
||||
6
src/templates/version.rb.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Jasmine
|
||||
module Core
|
||||
VERSION = "<%= "#{major}.#{minor}.#{build}" %><%= ".rc#{release_candidate}" if release_candidate %>"
|
||||
end
|
||||
end
|
||||
|
||||
7
src/version.js
Normal file
@@ -0,0 +1,7 @@
|
||||
jasmine.version_= {
|
||||
"major": 1,
|
||||
"minor": 1,
|
||||
"build": 0,
|
||||
"revision": 1310556152,
|
||||
"release_candidate": 3
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"build": 1
|
||||
"minor": 1,
|
||||
"build": 0,
|
||||
"release_candidate": 3
|
||||
}
|
||||
|
||||
48
tasks/build_dist.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
desc "Build core jasmine.js"
|
||||
task :build_dist => [:lint, :write_version_files] do
|
||||
puts 'Building Jasmine distribution from source'.cyan
|
||||
|
||||
concat_into('./lib/jasmine-core/jasmine.js') { core_sources + version_source_file }
|
||||
concat_into('./lib/jasmine-core/jasmine-html.js') { html_sources }
|
||||
|
||||
FileUtils.cp('./src/html/jasmine.css', './lib/jasmine-core/jasmine.css')
|
||||
end
|
||||
|
||||
def concat_into(output_file, &block)
|
||||
files = yield
|
||||
File.open(output_file, 'w') do |out|
|
||||
files.each do |f|
|
||||
out << File.read(f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Check jasmine sources for coding problems'
|
||||
task :lint => :require_node do
|
||||
puts "Running JSHint via Node.js".cyan
|
||||
system("node jshint/run.js") || exit(1)
|
||||
end
|
||||
|
||||
task :hint => :lint
|
||||
|
||||
task :write_version_files do
|
||||
scope = OpenStruct.new(:major => version_hash["major"],
|
||||
:minor => version_hash["minor"],
|
||||
:build => version_hash["build"],
|
||||
:release_candidate => version_hash["release_candidate"],
|
||||
:revision => Time.now.to_i)
|
||||
|
||||
js_template = Tilt.new('./src/templates/version.js.erb')
|
||||
File.open('./src/version.js', 'w+') do |f|
|
||||
f << js_template.render(scope)
|
||||
end
|
||||
|
||||
rb_template = Tilt.new('./src/templates/version.rb.erb')
|
||||
File.open('./lib/jasmine-core/version.rb', 'w+') do |f|
|
||||
f << rb_template.render(scope)
|
||||
end
|
||||
end
|
||||
|
||||
def version_source_file
|
||||
Dir.glob('src/version.js')
|
||||
end
|
||||
50
tasks/build_specs.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require 'ostruct'
|
||||
|
||||
#build the browser spec for Jasmine core based on current tree
|
||||
task :build_runner_html do
|
||||
template = Tilt.new('spec/templates/runner.html.erb')
|
||||
|
||||
File.open('spec/runner.html', 'w+') do |f|
|
||||
scope = OpenStruct.new(:title => "Jasmine Spec Runner: Jasmine Core",
|
||||
:favicon => favicon,
|
||||
:jasmine_tags => jasmine_tags,
|
||||
:source_tags => source_tags,
|
||||
:spec_file_tags => spec_file_tags)
|
||||
f << template.render(scope)
|
||||
end
|
||||
end
|
||||
|
||||
def favicon
|
||||
<<HTML
|
||||
<link rel="shortcut icon" type="image/png" href="../images/jasmine_favicon.png">
|
||||
HTML
|
||||
end
|
||||
|
||||
def jasmine_tags
|
||||
tags = %Q{<link href="../lib/jasmine-core/jasmine.css" rel="stylesheet"/>}
|
||||
tags << "\n "
|
||||
tags << script_tags_for("../lib/jasmine-core/jasmine.js")
|
||||
tags << "\n "
|
||||
tags << undefined_catch
|
||||
tags
|
||||
end
|
||||
|
||||
def undefined_catch
|
||||
<<HTML
|
||||
<script type="text/javascript">
|
||||
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
|
||||
undefined = "diz be undefined yo";
|
||||
</script>
|
||||
HTML
|
||||
end
|
||||
|
||||
def source_tags
|
||||
other_files = html_sources + console_sources
|
||||
script_tags_for other_files.collect { |f| "../#{f}" }
|
||||
end
|
||||
|
||||
def spec_file_tags
|
||||
spec_files = core_specfiles + html_specfiles + console_specfiles
|
||||
script_tags_for spec_files.collect { |f| "../#{f}" }
|
||||
end
|
||||
|
||||
17
tasks/docs.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
desc "Build jasmine documentation"
|
||||
task :doc => :require_pages_submodule do
|
||||
puts 'Creating Jasmine Documentation'
|
||||
require 'rubygems'
|
||||
require 'jsdoc_helper'
|
||||
|
||||
FileUtils.rm_r "pages/jsdoc", :force => true
|
||||
|
||||
JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
|
||||
t[:files] = core_sources + html_sources + console_sources
|
||||
t[:options] = "-a"
|
||||
t[:out] = "pages/jsdoc"
|
||||
# JsdocHelper bug: template must be relative to the JsdocHelper gem, ick
|
||||
t[:template] = File.join("../".*(100), Dir::getwd, "jsdoc-template")
|
||||
end
|
||||
Rake::Task[:lambda_jsdoc].invoke
|
||||
end
|
||||
50
tasks/helpers.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require 'json'
|
||||
|
||||
def core_sources
|
||||
first_sources = JSON.parse(File.read('./src/SourcesList.json')).collect { |f| "./src/core/#{f}" }
|
||||
|
||||
remaining_sources = Dir.glob('./src/core/*.js').reject { |f| first_sources.include?(f) }.sort
|
||||
|
||||
first_sources + remaining_sources
|
||||
end
|
||||
|
||||
def html_sources
|
||||
Dir.glob('./src/html/*.js')
|
||||
end
|
||||
|
||||
def console_sources
|
||||
Dir.glob('./src/console/*.js')
|
||||
end
|
||||
|
||||
def core_specfiles
|
||||
Dir.glob('./spec/core/*.js')
|
||||
end
|
||||
|
||||
def html_specfiles
|
||||
Dir.glob('./spec/html/*.js')
|
||||
end
|
||||
|
||||
def console_specfiles
|
||||
Dir.glob('./spec/console/*.js')
|
||||
end
|
||||
|
||||
def version_string
|
||||
version = "#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
|
||||
version += ".rc#{version_hash['release_candidate']}" if version_hash['release_candidate']
|
||||
version
|
||||
end
|
||||
|
||||
def version_hash
|
||||
@version ||= JSON.parse(File.new("./src/version.json").read);
|
||||
end
|
||||
|
||||
def script_tags_for(files)
|
||||
script_tag = Tilt::new('./spec/templates/script_tag.html.erb')
|
||||
|
||||
srcs = (files.is_a?(String) ? [files] : files)
|
||||
srcs.inject([]) do |tags, f|
|
||||
scope = OpenStruct.new :file => f
|
||||
tags << script_tag.render(scope)
|
||||
tags
|
||||
end.join("\n ")
|
||||
end
|
||||
13
tasks/pages.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
desc "Build the Github pages HTML"
|
||||
task :build_pages => :require_pages_submodule do
|
||||
Dir.chdir("pages") do
|
||||
FileUtils.rm_r('pages_output') if File.exist?('pages_output')
|
||||
Dir.chdir('pages_source') do
|
||||
system("frank export ../pages_output")
|
||||
end
|
||||
puts "\n"
|
||||
puts "Copying built website to the root of the gh-pages branch".cyan
|
||||
puts "\n\n"
|
||||
system("cp -r pages_output/* .")
|
||||
end
|
||||
end
|
||||
37
tasks/spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
desc "Run spec suite: Browser, Node, JSHint"
|
||||
task :spec => ["build_dist", "count_specs", "spec:node", "spec:browser"]
|
||||
|
||||
desc 'Run specs in Node.js'
|
||||
task "spec:node" => [:count_specs, :require_node] do
|
||||
puts "Running all appropriate specs via Node.js".cyan
|
||||
|
||||
color = Term::ANSIColor.coloring? ? "--color" : "--noColor"
|
||||
system("node spec/node_suite.js #{color}")
|
||||
end
|
||||
|
||||
desc "Run specs in the default browser (MacOS only)"
|
||||
task "spec:browser" => [:count_specs, :build_runner_html] do
|
||||
puts "Running all appropriate specs via the default web browser".cyan
|
||||
system("open spec/runner.html")
|
||||
end
|
||||
|
||||
#Count number of specs in Jasmine core
|
||||
task :count_specs do
|
||||
core_specs_count = count_specs_in(Dir.glob('spec/core/*.js'))
|
||||
console_spec_count = count_specs_in(Dir.glob('spec/console/*.js'))
|
||||
html_spec_count = count_specs_in(Dir.glob('spec/html/*.js'))
|
||||
|
||||
puts "\n"
|
||||
puts "#{(core_specs_count + console_spec_count).to_s.yellow.bold} specs for Node.js runner (exclude DOM-related specs)"
|
||||
puts "#{(core_specs_count + console_spec_count + html_spec_count).to_s.yellow.bold} specs for Browser runner (all specs)"
|
||||
puts "\n"
|
||||
puts "Please verify that these numbers match the runner output."
|
||||
puts "\n"
|
||||
end
|
||||
|
||||
def count_specs_in(files)
|
||||
files.inject(0) do |count, file|
|
||||
File.read(file).scan(/\sit\(/) {|s| count += 1}
|
||||
count
|
||||
end
|
||||
end
|
||||
91
tasks/standalone.rb
Normal file
@@ -0,0 +1,91 @@
|
||||
require 'ostruct'
|
||||
|
||||
desc "Build standalone distribution"
|
||||
task :standalone => [:require_pages_submodule, :protect_current_dist_zip, :build_spec_runner_html] do
|
||||
require 'tmpdir'
|
||||
|
||||
zip_root = File.join(Dir.tmpdir, "zip_root")
|
||||
temp_dir = File.join(zip_root, "jasmine-standalone-#{version_string}")
|
||||
puts "Building Example Project in #{temp_dir}"
|
||||
FileUtils.rm_r temp_dir if File.exist?(temp_dir)
|
||||
FileUtils.mkdir_p(temp_dir)
|
||||
|
||||
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
FileUtils.mkdir_p(File.join(root, "example"))
|
||||
FileUtils.cp_r(File.join(root, 'example/.'), File.join(temp_dir))
|
||||
|
||||
lib_dir = File.join(temp_dir, "lib/jasmine-#{version_string}")
|
||||
FileUtils.mkdir_p(lib_dir)
|
||||
{
|
||||
"images/jasmine_favicon.png" => "jasmine_favicon.png",
|
||||
"lib/jasmine-core/jasmine.js" => "jasmine.js",
|
||||
"lib/jasmine-core/jasmine-html.js" => "jasmine-html.js",
|
||||
"lib/jasmine-core/jasmine.css" => "jasmine.css",
|
||||
"MIT.LICENSE" => "MIT.LICENSE"
|
||||
}.each_pair do |src, dest|
|
||||
FileUtils.cp(File.join(root, src), File.join(lib_dir, dest))
|
||||
end
|
||||
|
||||
dist_dir = File.join(root, 'pages/downloads')
|
||||
zip_file_name = File.join(dist_dir, "jasmine-standalone-#{version_string}.zip")
|
||||
|
||||
puts "Zipping Example Project and moving to #{zip_file_name}"
|
||||
exec "cd #{zip_root} && zip #{zip_file_name} -r . -x .[a-zA-Z0-9]*"
|
||||
end
|
||||
|
||||
#Build SpecRunner.html for standalone dist example project
|
||||
task :build_spec_runner_html do
|
||||
template = Tilt.new('spec/templates/runner.html.erb')
|
||||
|
||||
File.open('lib/jasmine-core/example/SpecRunner.html', 'w+') do |f|
|
||||
scope = OpenStruct.new(:title => "Jasmine Spec Runner",
|
||||
:favicon => example_favicon,
|
||||
:jasmine_tags => example_jasmine_tags,
|
||||
:source_tags => example_source_tags,
|
||||
:spec_file_tags => example_spec_tags)
|
||||
f << template.render(scope)
|
||||
end
|
||||
end
|
||||
|
||||
def example_path
|
||||
"lib/jasmine-#{version_string}"
|
||||
end
|
||||
|
||||
def example_favicon
|
||||
<<HTML
|
||||
<link rel="shortcut icon" type="image/png" href="#{example_path}/jasmine_favicon.png">
|
||||
HTML
|
||||
end
|
||||
|
||||
def example_jasmine_tags
|
||||
tags = %Q{<link rel="stylesheet" type="text/css" href="#{example_path}/jasmine.css">}
|
||||
tags << "\n "
|
||||
tags << script_tags_for(["#{example_path}/jasmine.js", "#{example_path}/jasmine-html.js"])
|
||||
tags
|
||||
end
|
||||
|
||||
def example_source_tags
|
||||
script_tags_for ['spec/SpecHelper.js', 'spec/PlayerSpec.js']
|
||||
end
|
||||
|
||||
def example_spec_tags
|
||||
script_tags_for ['src/Player.js', 'src/Song.js']
|
||||
end
|
||||
|
||||
|
||||
task :protect_current_dist_zip do
|
||||
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
dist_dir = File.join(root, 'pages/downloads')
|
||||
zip_file_name = File.join(dist_dir, "jasmine-standalone-#{version_string}.zip")
|
||||
|
||||
zip_present_message = "\n\n"
|
||||
zip_present_message << "==> STOPPED <==".red
|
||||
zip_present_message << "\n\n"
|
||||
zip_present_message << "The file ".red + "#{zip_file_name}" + " already exists.".red + "\n"
|
||||
zip_present_message << "If you should be building the next version, update src/version.json"
|
||||
zip_present_message << "\n"
|
||||
zip_present_message << "If the version is correct, you must be trying to re-build the standalone ZIP. Delete the ZIP and rebuild."
|
||||
zip_present_message << "\n"
|
||||
|
||||
raise zip_present_message if File.exist?(zip_file_name)
|
||||
end
|
||||
5
tasks/version.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
task :version do
|
||||
require 'pp'
|
||||
pp version_hash
|
||||
pp version_string
|
||||
end
|
||||