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
41
bin/jasmine
41
bin/jasmine
@ -1,26 +1,35 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
cwd = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
require 'rake'
|
||||||
require File.expand_path(File.join(cwd, "lib", "jasmine-ruby", "jasmine_helper.rb"))
|
|
||||||
|
|
||||||
#to load JasmineHelper overrides
|
def cwd
|
||||||
if ARGV[1]
|
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||||
require File.expand_path(File.join(Dir.pwd, ARGV[1]))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV[0] == 'server'
|
def expand(*paths)
|
||||||
require File.expand_path(File.join(cwd, "jasmine/contrib/ruby/jasmine_spec_builder"))
|
File.expand_path(File.join(*paths))
|
||||||
puts "your tests are here:"
|
end
|
||||||
puts " http://localhost:8888/run.html"
|
|
||||||
Jasmine::SimpleServer.start(8888,
|
def rakefile_path
|
||||||
lambda { JasmineHelper.specs },
|
expand(cwd, 'templates/Rakefile')
|
||||||
JasmineHelper.dir_mappings,
|
|
||||||
:spec_helpers => JasmineHelper.spec_helpers)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV[0] == 'init'
|
if ARGV[0] == 'init'
|
||||||
require 'ftools'
|
require 'ftools'
|
||||||
File.makedirs('spec')
|
File.makedirs('spec/javascripts')
|
||||||
dest_dir = File.expand_path(File.join(Dir.pwd, 'spec'))
|
dest_root = expand(Dir.pwd, 'spec')
|
||||||
File.copy(File.expand_path(File.join(cwd, 'templates/example_spec.js')), dest_dir)
|
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
|
end
|
||||||
|
|
||||||
|
@ -28,8 +28,11 @@ Gem::Specification.new do |s|
|
|||||||
"jasmine/lib/jasmine.css",
|
"jasmine/lib/jasmine.css",
|
||||||
"jasmine/lib/json2.js",
|
"jasmine/lib/json2.js",
|
||||||
"lib/jasmine-ruby/jasmine_helper.rb",
|
"lib/jasmine-ruby/jasmine_helper.rb",
|
||||||
|
"lib/jasmine-ruby/jasmine_meta_spec.rb",
|
||||||
|
"lib/jasmine-ruby.rb",
|
||||||
"tasks/jasmine.rake",
|
"tasks/jasmine.rake",
|
||||||
"templates/example_spec.js"
|
"templates/example_spec.js",
|
||||||
|
"templates/Rakefile"
|
||||||
]
|
]
|
||||||
s.homepage = %q{http://github.com/ragaskar/jasmine-ruby}
|
s.homepage = %q{http://github.com/ragaskar/jasmine-ruby}
|
||||||
s.rdoc_options = ["--charset=UTF-8"]
|
s.rdoc_options = ["--charset=UTF-8"]
|
||||||
|
1
lib/jasmine-ruby.rb
Normal file
1
lib/jasmine-ruby.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
require 'jasmine-ruby/jasmine_helper'
|
@ -1,54 +1,47 @@
|
|||||||
class JasmineHelper
|
class JasmineHelper
|
||||||
def self.jasmine_lib_dir
|
def self.lib_dir
|
||||||
File.expand_path(File.join(jasmine_root, 'lib'))
|
File.expand_path(File.join(root, 'lib'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.jasmine
|
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/json2.js',
|
||||||
'/lib/TrivialReporter.js']
|
'/lib/TrivialReporter.js']
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.jasmine_root
|
def self.root
|
||||||
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine'))
|
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rails_root
|
def self.spec_dir
|
||||||
if defined? RAILS_ROOT
|
File.expand_path('spec/javascripts')
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.spec_files
|
def self.spec_files
|
||||||
Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js"))
|
Dir.glob(File.join(spec_dir, "**/*[Ss]pec.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.specs
|
def self.specs
|
||||||
spec_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")}
|
spec_files.collect {|f| f.sub(spec_dir, "/spec")}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.spec_helpers_files
|
def self.spec_helpers_files
|
||||||
Dir.glob(File.join(jasmine_spec_dir, "helpers/**/*.js"))
|
Dir.glob(File.join(spec_dir, "helpers/**/*.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.spec_helpers
|
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
|
end
|
||||||
|
|
||||||
def self.dir_mappings
|
def self.dir_mappings
|
||||||
{
|
{
|
||||||
"/spec" => jasmine_spec_dir,
|
"/spec" => spec_dir,
|
||||||
"/lib" => jasmine_lib_dir
|
"/lib" => lib_dir
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.meta_spec_path
|
||||||
|
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine-ruby', 'jasmine_meta_spec.rb'))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
22
lib/jasmine-ruby/jasmine_meta_spec.rb
Normal file
22
lib/jasmine-ruby/jasmine_meta_spec.rb
Normal file
@ -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")
|
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(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,
|
jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
|
||||||
JasmineHelper.spec_file_urls,
|
JasmineHelper.spec_file_urls,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "jasmine_helper.rb"))
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "jasmine_helper.rb"))
|
||||||
|
|
||||||
def start_jasmine_server
|
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 "your tests are here:"
|
||||||
puts " http://localhost:8888/run.html"
|
puts " http://localhost:8888/run.html"
|
||||||
|
27
templates/Rakefile
Normal file
27
templates/Rakefile
Normal file
@ -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
Block a user