jasmine/Rakefile

135 lines
3.5 KiB
Ruby
Raw Normal View History

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"]
sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort
sources
2009-09-05 06:04:48 +00:00
end
def jasmine_filename(version)
"jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js"
end
def version_hash
JSON.parse(File.new("src/version.json").read);
end
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"
Jasmine::SimpleServer.start(
8888,
lambda { JasmineHelper.specs },
JasmineHelper.dir_mappings,
:jasmine_files => jasmine_includes)
2009-09-05 06:04:48 +00:00
end
task :default => 'jasmine:dist'
2009-09-05 06:04:48 +00:00
namespace :jasmine do
desc 'Prepares for distribution'
task :dist => ['jasmine:build', 'jasmine:doc']
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
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'
task :build => :lint do
2009-09-05 06:04:48 +00:00
puts 'Building Jasmine from source'
require 'json'
sources = jasmine_sources
version = version_hash
old_jasmine_files = Dir.glob('lib/jasmine*.js')
old_jasmine_files.each do |file|
File.delete(file)
end
jasmine = File.new("lib/#{jasmine_filename version}", 'w')
sources.each do |source_filename|
jasmine.puts(File.read(source_filename))
end
jasmine.puts %{
2009-08-21 05:16:14 +00:00
jasmine.version_= {
"major": #{version['major']},
"minor": #{version['minor']},
"build": #{version['build']},
"revision": #{Time.now.to_i}
2009-08-21 05:16:14 +00:00
};
}
2009-09-05 06:04:48 +00:00
jasmine.close
end
desc "Build jasmine documentation"
task :doc do
2009-09-05 06:04:48 +00:00
puts 'Creating Jasmine Documentation'
require 'rubygems'
#sudo gem install ragaskar-jsdoc_helper
require 'jsdoc_helper'
JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
t[:files] = jasmine_sources << 'lib/TrivialReporter.js'
t[:options] = "-a"
end
Rake::Task[:lambda_jsdoc].invoke
end
2009-09-05 06:04:48 +00:00
desc "Run jasmine tests of source via server"
task :server do
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)) }
Jasmine.cachebust(raw_jasmine_includes).collect {|f| f.sub(JasmineHelper.jasmine_src_dir, "/src").sub(JasmineHelper.jasmine_lib_dir, "/lib") }
}
2009-09-05 06:04:48 +00:00
start_jasmine_server(jasmine_includes)
2009-08-27 05:41:19 +00:00
end
2009-09-05 06:04:48 +00:00
desc "Build jasmine and run tests via server"
task :server_build => 'jasmine:build' do
start_jasmine_server
2009-09-04 17:57:08 +00:00
end
2009-09-05 06:04:48 +00:00
namespace :test do
desc "Run continuous integration tests"
task :ci => '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
end
end
end