remove jasmine server; use jasmine init to copy (or append) a Rakefile with common jasmine tasks
This commit is contained in:
parent
7c043eb5d0
commit
bece09bba8
43
bin/jasmine
43
bin/jasmine
|
@ -1,26 +1,35 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'rubygems'
|
||||
cwd = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
require File.expand_path(File.join(cwd, "lib", "jasmine-ruby", "jasmine_helper.rb"))
|
||||
require 'rake'
|
||||
|
||||
#to load JasmineHelper overrides
|
||||
if ARGV[1]
|
||||
require File.expand_path(File.join(Dir.pwd, ARGV[1]))
|
||||
def cwd
|
||||
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
end
|
||||
|
||||
if ARGV[0] == 'server'
|
||||
require File.expand_path(File.join(cwd, "jasmine/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,
|
||||
:spec_helpers => JasmineHelper.spec_helpers)
|
||||
def expand(*paths)
|
||||
File.expand_path(File.join(*paths))
|
||||
end
|
||||
|
||||
def rakefile_path
|
||||
expand(cwd, 'templates/Rakefile')
|
||||
end
|
||||
|
||||
if ARGV[0] == 'init'
|
||||
require 'ftools'
|
||||
File.makedirs('spec')
|
||||
dest_dir = File.expand_path(File.join(Dir.pwd, 'spec'))
|
||||
File.copy(File.expand_path(File.join(cwd, 'templates/example_spec.js')), dest_dir)
|
||||
end
|
||||
File.makedirs('spec/javascripts')
|
||||
dest_root = expand(Dir.pwd, 'spec')
|
||||
dest_spec = expand(Dir.pwd, 'spec/javascripts')
|
||||
File.copy(expand(cwd, 'templates/example_spec.js'), dest_spec)
|
||||
if File.exist?(expand(Dir.pwd, 'Rakefile'))
|
||||
existing_rakefile = expand(Dir.pwd, 'Rakefile')
|
||||
load existing_rakefile
|
||||
unless Rake::Task.task_defined?('jasmine')
|
||||
open(existing_rakefile, 'a') do |f|
|
||||
f.write(File.read(rakefile_path))
|
||||
end
|
||||
end
|
||||
else
|
||||
File.copy(rakefile_path, Dir.pwd)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -28,8 +28,11 @@ Gem::Specification.new do |s|
|
|||
"jasmine/lib/jasmine.css",
|
||||
"jasmine/lib/json2.js",
|
||||
"lib/jasmine-ruby/jasmine_helper.rb",
|
||||
"lib/jasmine-ruby/jasmine_meta_spec.rb",
|
||||
"lib/jasmine-ruby.rb",
|
||||
"tasks/jasmine.rake",
|
||||
"templates/example_spec.js"
|
||||
"templates/example_spec.js",
|
||||
"templates/Rakefile"
|
||||
]
|
||||
s.homepage = %q{http://github.com/ragaskar/jasmine-ruby}
|
||||
s.rdoc_options = ["--charset=UTF-8"]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
require 'jasmine-ruby/jasmine_helper'
|
|
@ -1,54 +1,47 @@
|
|||
class JasmineHelper
|
||||
def self.jasmine_lib_dir
|
||||
File.expand_path(File.join(jasmine_root, 'lib'))
|
||||
def self.lib_dir
|
||||
File.expand_path(File.join(root, 'lib'))
|
||||
end
|
||||
|
||||
def self.jasmine
|
||||
['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] +
|
||||
['/lib/' + File.basename(Dir.glob("#{JasmineHelper.lib_dir}/jasmine*.js").first)] +
|
||||
['/lib/json2.js',
|
||||
'/lib/TrivialReporter.js']
|
||||
end
|
||||
|
||||
def self.jasmine_root
|
||||
def self.root
|
||||
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine'))
|
||||
end
|
||||
|
||||
def self.rails_root
|
||||
if defined? RAILS_ROOT
|
||||
RAILS_ROOT
|
||||
else
|
||||
ENV['RAILS_ROOT']
|
||||
end
|
||||
end
|
||||
|
||||
def self.jasmine_spec_dir
|
||||
if rails_root
|
||||
File.expand_path(File.join(rails_root, "spec", "javascript"))
|
||||
else
|
||||
File.expand_path('spec')
|
||||
end
|
||||
def self.spec_dir
|
||||
File.expand_path('spec/javascripts')
|
||||
end
|
||||
|
||||
def self.spec_files
|
||||
Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js"))
|
||||
Dir.glob(File.join(spec_dir, "**/*[Ss]pec.js"))
|
||||
end
|
||||
|
||||
def self.specs
|
||||
spec_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")}
|
||||
spec_files.collect {|f| f.sub(spec_dir, "/spec")}
|
||||
end
|
||||
|
||||
def self.spec_helpers_files
|
||||
Dir.glob(File.join(jasmine_spec_dir, "helpers/**/*.js"))
|
||||
Dir.glob(File.join(spec_dir, "helpers/**/*.js"))
|
||||
end
|
||||
|
||||
def self.spec_helpers
|
||||
spec_helpers_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")}
|
||||
spec_helpers_files.collect {|f| f.sub(spec_dir, "/spec")}
|
||||
end
|
||||
|
||||
def self.dir_mappings
|
||||
{
|
||||
"/spec" => jasmine_spec_dir,
|
||||
"/lib" => jasmine_lib_dir
|
||||
"/spec" => spec_dir,
|
||||
"/lib" => lib_dir
|
||||
}
|
||||
end
|
||||
|
||||
def self.meta_spec_path
|
||||
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine-ruby', 'jasmine_meta_spec.rb'))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
require 'rubygems'
|
||||
require "selenium_rc"
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb"))
|
||||
require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder"))
|
||||
|
||||
jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
|
||||
JasmineHelper.specs,
|
||||
JasmineHelper.dir_mappings)
|
||||
|
||||
spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.spec_files, jasmine_runner)
|
||||
|
||||
should_stop = false
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
config.after(:suite) do
|
||||
spec_builder.stop if should_stop
|
||||
end
|
||||
end
|
||||
|
||||
spec_builder.start
|
||||
should_stop = true
|
||||
spec_builder.declare_suites
|
|
@ -4,7 +4,7 @@ require "selenium_rc"
|
|||
JASMINE_SPEC_DIR = File.join(File.dirname(__FILE__), "..", "jasmine", "spec")
|
||||
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "jasmine-ruby", "jasmine_helper.rb"))
|
||||
require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
|
||||
require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder"))
|
||||
|
||||
jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
|
||||
JasmineHelper.spec_file_urls,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "jasmine_helper.rb"))
|
||||
|
||||
def start_jasmine_server
|
||||
require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
|
||||
require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder"))
|
||||
|
||||
puts "your tests are here:"
|
||||
puts " http://localhost:8888/run.html"
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
namespace :jasmine do
|
||||
require 'jasmine-ruby'
|
||||
helper_overrides = File.expand_path(File.join(File.dirname(__FILE__), "spec/javascripts/jasmine_helper.rb"))
|
||||
if File.exist?(helper_overrides)
|
||||
require helper_overrides
|
||||
end
|
||||
require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder"))
|
||||
|
||||
desc "Run continuous integration tests"
|
||||
require "spec"
|
||||
require 'spec/rake/spectask'
|
||||
Spec::Rake::SpecTask.new(:ci) do |t|
|
||||
t.spec_opts = ["--color", "--format", "specdoc"]
|
||||
t.spec_files = [JasmineHelper.meta_spec_path]
|
||||
end
|
||||
task :server do
|
||||
puts "your tests are here:"
|
||||
puts " http://localhost:8888/run.html"
|
||||
|
||||
Jasmine::SimpleServer.start(8888,
|
||||
lambda { JasmineHelper.specs },
|
||||
JasmineHelper.dir_mappings)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run specs via server"
|
||||
task :jasmine => ['jasmine:server']
|
Loading…
Reference in New Issue