2009-09-05 06:04:48 +00:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper.rb"))
|
|
|
|
|
|
|
|
def jasmine_sources
|
|
|
|
sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
|
2010-06-25 00:15:06 +00:00
|
|
|
sources += Dir.glob('src/*.js').reject { |f| f == 'src/base.js' || sources.include?(f) }.sort
|
2009-11-26 15:41:10 +00:00
|
|
|
sources
|
2009-09-05 06:04:48 +00:00
|
|
|
end
|
|
|
|
|
2010-06-25 00:15:06 +00:00
|
|
|
def jasmine_filename
|
|
|
|
"jasmine-#{jasmine_version}.js"
|
|
|
|
end
|
|
|
|
|
|
|
|
def jasmine_version
|
|
|
|
"#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
|
2009-09-05 06:04:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def version_hash
|
2010-06-25 00:15:06 +00:00
|
|
|
require 'json'
|
|
|
|
@version ||= JSON.parse(File.new("src/version.json").read);
|
2009-09-05 06:04:48 +00:00
|
|
|
end
|
|
|
|
|
2009-09-10 01:18:00 +00:00
|
|
|
def start_jasmine_server(jasmine_includes = nil)
|
2009-09-05 06:04:48 +00:00
|
|
|
require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
|
|
|
|
|
|
|
|
puts "your tests are here:"
|
|
|
|
puts " http://localhost:8888/run.html"
|
|
|
|
|
2009-11-01 04:47:11 +00:00
|
|
|
Jasmine::SimpleServer.start(
|
2010-06-25 00:15:06 +00:00
|
|
|
8888,
|
|
|
|
lambda { JasmineHelper.specs },
|
|
|
|
JasmineHelper.dir_mappings,
|
|
|
|
:jasmine_files => jasmine_includes)
|
2009-09-05 06:04:48 +00:00
|
|
|
end
|
|
|
|
|
2009-11-26 15:41:10 +00:00
|
|
|
task :default => 'jasmine:dist'
|
|
|
|
|
2010-06-25 00:15:06 +00:00
|
|
|
def substitute_jasmine_version(filename)
|
|
|
|
contents = File.read(filename)
|
|
|
|
contents = contents.gsub(/##JASMINE_VERSION##/, (jasmine_version))
|
|
|
|
File.open(filename, 'w') { |f| f.write(contents) }
|
|
|
|
end
|
|
|
|
|
2009-09-05 06:04:48 +00:00
|
|
|
namespace :jasmine do
|
2009-11-26 15:41:10 +00:00
|
|
|
|
|
|
|
desc 'Prepares for distribution'
|
2010-06-25 00:15:06 +00:00
|
|
|
task :dist => ['jasmine:build', 'jasmine:doc', 'jasmine:build_example_project']
|
2009-11-26 15:41:10 +00:00
|
|
|
|
2009-11-26 16:12:06 +00:00
|
|
|
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
|
2010-06-23 18:31:38 +00:00
|
|
|
|
|
|
|
if line.scan(/window/).length > 0
|
|
|
|
puts "Dangerous window at #{src}:#{i}:\n > #{line}"
|
|
|
|
passed = false
|
|
|
|
end
|
2009-11-26 16:12:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
unless passed
|
|
|
|
puts "Lint failed!"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-09-05 06:04:48 +00:00
|
|
|
desc 'Builds lib/jasmine from source'
|
2010-04-19 22:57:23 +00:00
|
|
|
task :build => :lint do
|
2009-09-05 06:04:48 +00:00
|
|
|
puts 'Building Jasmine from source'
|
2009-12-17 01:27:06 +00:00
|
|
|
|
2009-08-28 05:15:50 +00:00
|
|
|
sources = jasmine_sources
|
|
|
|
version = version_hash
|
2009-11-26 15:41:10 +00:00
|
|
|
|
2009-08-28 05:15:50 +00:00
|
|
|
old_jasmine_files = Dir.glob('lib/jasmine*.js')
|
2010-06-23 18:31:38 +00:00
|
|
|
old_jasmine_files.each { |file| File.delete(file) }
|
2009-11-26 15:41:10 +00:00
|
|
|
|
2010-06-23 18:31:38 +00:00
|
|
|
jasmine = File.new("lib/jasmine.js", 'w')
|
2009-11-26 15:41:10 +00:00
|
|
|
|
|
|
|
sources.each do |source_filename|
|
|
|
|
jasmine.puts(File.read(source_filename))
|
|
|
|
end
|
|
|
|
|
2009-08-28 05:15:50 +00:00
|
|
|
jasmine.puts %{
|
2009-08-21 05:16:14 +00:00
|
|
|
jasmine.version_= {
|
|
|
|
"major": #{version['major']},
|
|
|
|
"minor": #{version['minor']},
|
|
|
|
"build": #{version['build']},
|
2009-08-28 05:23:51 +00:00
|
|
|
"revision": #{Time.now.to_i}
|
2009-08-21 05:16:14 +00:00
|
|
|
};
|
|
|
|
}
|
2009-11-26 15:41:10 +00:00
|
|
|
|
2009-09-05 06:04:48 +00:00
|
|
|
jasmine.close
|
2010-06-23 18:31:38 +00:00
|
|
|
|
|
|
|
FileUtils.cp("lib/jasmine.js", "lib/#{jasmine_filename version}")
|
2009-08-28 05:15:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Build jasmine documentation"
|
|
|
|
task :doc do
|
2009-09-05 06:04:48 +00:00
|
|
|
puts 'Creating Jasmine Documentation'
|
2009-08-28 05:15:50 +00:00
|
|
|
require 'rubygems'
|
|
|
|
#sudo gem install ragaskar-jsdoc_helper
|
|
|
|
require 'jsdoc_helper'
|
|
|
|
|
|
|
|
|
2009-11-10 19:28:47 +00:00
|
|
|
JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
|
|
|
|
t[:files] = jasmine_sources << 'lib/TrivialReporter.js'
|
2009-11-10 22:32:29 +00:00
|
|
|
t[:options] = "-a"
|
2009-11-10 19:28:47 +00:00
|
|
|
end
|
2009-08-28 05:15:50 +00:00
|
|
|
Rake::Task[:lambda_jsdoc].invoke
|
2009-06-16 14:13:45 +00:00
|
|
|
end
|
2009-08-28 05:15:50 +00:00
|
|
|
|
2010-06-25 00:15:06 +00:00
|
|
|
desc "Build example project"
|
|
|
|
task :build_example_project do
|
|
|
|
require 'tmpdir'
|
|
|
|
|
|
|
|
temp_dir = File.join(Dir.tmpdir, 'jasmine-standalone-project')
|
|
|
|
puts "Building Example Project in #{temp_dir}"
|
|
|
|
FileUtils.rm_r temp_dir if File.exists?(temp_dir)
|
|
|
|
Dir.mkdir(temp_dir)
|
|
|
|
|
|
|
|
root = JasmineHelper.jasmine_root
|
|
|
|
FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir)
|
|
|
|
substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html"))
|
|
|
|
|
|
|
|
lib_dir = File.join(temp_dir, "lib/jasmine-#{jasmine_version}")
|
|
|
|
FileUtils.mkdir_p(lib_dir)
|
|
|
|
[
|
|
|
|
"jasmine.js",
|
|
|
|
"TrivialReporter.js",
|
|
|
|
"jasmine.css"
|
|
|
|
].each do |f|
|
|
|
|
FileUtils.cp(File.join(root, 'lib', f), File.join(lib_dir, f))
|
|
|
|
end
|
|
|
|
|
|
|
|
dist = File.join(root, 'dist')
|
|
|
|
FileUtils.rm_r dist if File.exists?(dist)
|
|
|
|
Dir.mkdir(dist)
|
|
|
|
exec "cd #{temp_dir} && zip -r #{File.join(dist, "jasmine-standalone-#{jasmine_version}.zip")} ."
|
|
|
|
end
|
|
|
|
|
2009-08-26 22:55:08 +00:00
|
|
|
|
2009-09-05 06:04:48 +00:00
|
|
|
task :server do
|
2009-11-01 04:47:11 +00:00
|
|
|
files = jasmine_sources + ['lib/TrivialReporter.js', 'lib/consolex.js']
|
|
|
|
jasmine_includes = lambda {
|
|
|
|
raw_jasmine_includes = files.collect { |f| File.expand_path(File.join(JasmineHelper.jasmine_root, f)) }
|
2010-06-25 00:15:06 +00:00
|
|
|
Jasmine.cachebust(raw_jasmine_includes).collect { |f| f.sub(JasmineHelper.jasmine_src_dir, "/src").sub(JasmineHelper.jasmine_lib_dir, "/lib") }
|
2009-11-01 04:47:11 +00:00
|
|
|
}
|
2009-09-05 06:04:48 +00:00
|
|
|
start_jasmine_server(jasmine_includes)
|
2009-08-27 05:41:19 +00:00
|
|
|
end
|
2009-08-26 22:55:08 +00:00
|
|
|
|
2009-09-05 06:04:48 +00:00
|
|
|
task :server_build => 'jasmine:build' do
|
2009-06-19 18:47:33 +00:00
|
|
|
|
2009-09-10 01:18:00 +00:00
|
|
|
start_jasmine_server
|
2009-09-04 17:57:08 +00:00
|
|
|
end
|
2009-06-16 14:13:45 +00:00
|
|
|
|
2009-09-05 06:04:48 +00:00
|
|
|
namespace :test do
|
2009-12-17 01:27:06 +00:00
|
|
|
task :ci => :'ci:local'
|
|
|
|
namespace :ci do
|
|
|
|
|
|
|
|
task :local => 'jasmine:build' do
|
|
|
|
require "spec"
|
|
|
|
require 'spec/rake/spectask'
|
|
|
|
Spec::Rake::SpecTask.new(:lambda_ci) do |t|
|
|
|
|
t.spec_opts = ["--color", "--format", "specdoc"]
|
|
|
|
t.spec_files = ["spec/jasmine_spec.rb"]
|
|
|
|
end
|
|
|
|
Rake::Task[:lambda_ci].invoke
|
2009-09-05 06:04:48 +00:00
|
|
|
end
|
2009-08-26 22:55:08 +00:00
|
|
|
|
2009-12-29 00:45:01 +00:00
|
|
|
task :saucelabs => ['jasmine:copy_saucelabs_config', 'jasmine:build'] do
|
2009-12-17 01:27:06 +00:00
|
|
|
ENV['SAUCELABS'] = 'true'
|
|
|
|
Rake::Task['jasmine:test:ci:local'].invoke
|
|
|
|
end
|
|
|
|
end
|
2009-06-16 14:13:45 +00:00
|
|
|
end
|
2009-08-26 22:55:08 +00:00
|
|
|
|
2009-12-29 00:45:01 +00:00
|
|
|
desc 'Copy saucelabs.yml to work directory'
|
|
|
|
task 'copy_saucelabs_config' do
|
|
|
|
FileUtils.cp '../saucelabs.yml', 'spec'
|
|
|
|
end
|
2009-12-17 01:27:06 +00:00
|
|
|
end
|
2009-12-29 00:02:09 +00:00
|
|
|
|
2010-03-17 14:54:20 +00:00
|
|
|
task :jasmine => ['jasmine:server']
|