Simplify mapping

This commit is contained in:
ragaskar 2009-11-25 18:43:51 -08:00
parent 2b9667c82e
commit 692ae5980a
4 changed files with 20 additions and 17 deletions

View File

@ -33,13 +33,6 @@ class JasmineHelper
spec_helpers_files.collect {|f| f.sub(spec_dir, "/spec")}
end
def self.dir_mappings
{
"/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

View File

@ -1,11 +1,12 @@
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"))
require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_runner.rb"))
require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_spec_builder"))
jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
Dir.pwd,
JasmineHelper.specs,
JasmineHelper.dir_mappings,
{ :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers,
:stylesheets => JasmineHelper.stylesheets
})

View File

@ -148,20 +148,27 @@ module Jasmine
end
class SimpleServer
def self.start(port, spec_files_or_proc, mappings, options = {})
def self.start(port, root_path, spec_files_or_proc, options = {})
require 'thin'
config = {
'/__suite__' => Jasmine::FocusedSuite.new(spec_files_or_proc, options),
'/run.html' => Jasmine::Redirect.new('/'),
'/' => Jasmine::RunAdapter.new(spec_files_or_proc, options)
}
mappings.each do |from, to|
config[from] = Rack::File.new(to)
if (options[:mappings])
options[:mappings].each do |from, to|
config[from] = Rack::File.new(to)
end
end
config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root)
file_serve_config = {
'/' => Rack::File.new(root_path)
}
app = Rack::Cascade.new([
Rack::URLMap.new(file_serve_config),
Rack::URLMap.new(config),
JsAlert.new
])
@ -219,10 +226,10 @@ module Jasmine
end
class Runner
def initialize(selenium_jar_path, spec_files, dir_mappings, options={})
def initialize(selenium_jar_path, root_path, spec_files, options={})
@root_path = root_path
@selenium_jar_path = selenium_jar_path
@spec_files = spec_files
@dir_mappings = dir_mappings
@options = options
@browser = options[:browser] ? options[:browser].delete(:browser) : 'firefox'
@ -253,7 +260,7 @@ module Jasmine
@jasmine_server_pid = fork do
Process.setpgrp
Jasmine::SimpleServer.start(@jasmine_server_port, @spec_files, @dir_mappings, @options)
Jasmine::SimpleServer.start(@jasmine_server_port, @root_path, @spec_files, @options)
exit! 0
end
puts "jasmine server started. pid is #{@jasmine_server_pid}"

View File

@ -10,6 +10,8 @@ namespace :jasmine do
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:ci) do |t|
t.spec_opts = ["--color", "--format", "specdoc"]
t.ruby_opts = ["MY_ROOT=foo"]
t.verbose = true
t.spec_files = [JasmineHelper.meta_spec_path]
end
task :server do
@ -17,8 +19,8 @@ namespace :jasmine do
puts " http://localhost:8888/run.html"
Jasmine::SimpleServer.start(8888,
File.expand_path(File.join(File.dirname(__FILE__))),
lambda { JasmineHelper.specs },
JasmineHelper.dir_mappings,
{ :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers,
:stylesheets => JasmineHelper.stylesheets
})