Add rails generators. Add sources.yaml support. Fix Prototype.js collision on jasmine:ci. Version bump to 0.4.0.
This commit is contained in:
@@ -3,5 +3,4 @@ require 'jasmine/config'
|
||||
require 'jasmine/server'
|
||||
require 'jasmine/selenium_driver'
|
||||
|
||||
require 'jasmine/jasmine_helper'
|
||||
require 'jasmine/spec_builder'
|
||||
@@ -1,5 +1,7 @@
|
||||
module Jasmine
|
||||
class Config
|
||||
require 'yaml'
|
||||
|
||||
def initialize(options = {})
|
||||
require 'selenium_rc'
|
||||
@selenium_jar_path = SeleniumRC::Server.allocate.jar_path
|
||||
@@ -86,31 +88,60 @@ module Jasmine
|
||||
Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
|
||||
end
|
||||
|
||||
def project_root
|
||||
Dir.pwd
|
||||
end
|
||||
|
||||
def src_dir
|
||||
if simple_config['src_dir']
|
||||
File.join(project_root, simple_config['src_dir'])
|
||||
else
|
||||
project_root
|
||||
end
|
||||
end
|
||||
|
||||
def simple_config_file
|
||||
File.join(project_root, 'spec/javascripts/support/sources.yaml')
|
||||
end
|
||||
|
||||
def simple_config
|
||||
config = File.exist?(simple_config_file) ? File.open(simple_config_file) { |yf| YAML::load( yf ) } : false
|
||||
config || {}
|
||||
end
|
||||
|
||||
def src_files
|
||||
match_files(src_dir, "**/*.js")
|
||||
simple_config['sources'] || []
|
||||
end
|
||||
|
||||
def src_path
|
||||
"src"
|
||||
end
|
||||
|
||||
def spec_path
|
||||
"spec"
|
||||
def spec_dir
|
||||
if simple_config['spec_dir']
|
||||
File.join(project_root, simple_config['spec_dir'])
|
||||
else
|
||||
File.join(project_root, 'spec/javascripts')
|
||||
end
|
||||
end
|
||||
|
||||
def spec_files
|
||||
match_files(spec_dir, "**/*.js")
|
||||
end
|
||||
|
||||
def spec_path
|
||||
"/__spec__"
|
||||
end
|
||||
|
||||
def root_path
|
||||
"/__root__"
|
||||
end
|
||||
|
||||
def mappings
|
||||
{
|
||||
"/" + src_path => src_dir,
|
||||
"/" + spec_path => spec_dir
|
||||
spec_path => spec_dir,
|
||||
root_path => project_root
|
||||
}
|
||||
end
|
||||
|
||||
def js_files
|
||||
src_files.collect {|f| "/" + File.join(src_path, f) } + spec_files.collect {|f| "/" + File.join(spec_path, f) }
|
||||
src_files.collect {|f| "/" + f } + spec_files.collect {|f| File.join(spec_path, f) }
|
||||
end
|
||||
|
||||
def spec_files_full_paths
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
class JasmineHelper
|
||||
def self.lib_dir
|
||||
File.expand_path(File.join(root, 'lib'))
|
||||
end
|
||||
|
||||
def self.jasmine
|
||||
['/lib/' + File.basename(Dir.glob("#{JasmineHelper.lib_dir}/jasmine*.js").first)] +
|
||||
['/lib/json2.js',
|
||||
'/lib/TrivialReporter.js']
|
||||
end
|
||||
|
||||
def self.root
|
||||
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine'))
|
||||
end
|
||||
|
||||
def self.spec_dir
|
||||
File.expand_path('spec')
|
||||
end
|
||||
|
||||
def self.spec_files
|
||||
Dir.glob(File.join(spec_dir, "javascripts/**/*[Ss]pec.js"))
|
||||
end
|
||||
|
||||
def self.specs
|
||||
spec_files.collect {|f| f.sub(spec_dir, "/spec")}
|
||||
end
|
||||
|
||||
def self.spec_helpers_files
|
||||
Dir.glob(File.join(spec_dir, "helpers/**/*.js"))
|
||||
end
|
||||
|
||||
def self.spec_helpers
|
||||
spec_helpers_files.collect {|f| f.sub(spec_dir, "/spec")}
|
||||
end
|
||||
|
||||
def self.meta_spec_path
|
||||
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine', 'jasmine_meta_spec.rb'))
|
||||
end
|
||||
|
||||
def self.files
|
||||
[]
|
||||
end
|
||||
|
||||
def self.stylesheets
|
||||
[]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
require 'rubygems'
|
||||
require "selenium_rc"
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb"))
|
||||
helper_overrides = File.expand_path(File.join(Dir.pwd, "spec", "helpers", "jasmine_helper.rb"))
|
||||
if File.exist?(helper_overrides)
|
||||
require helper_overrides
|
||||
end
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_runner.rb"))
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "spec_builder"))
|
||||
|
||||
jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
|
||||
Dir.pwd,
|
||||
JasmineHelper.specs,
|
||||
{ :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers,
|
||||
:stylesheets => JasmineHelper.stylesheets
|
||||
})
|
||||
|
||||
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
|
||||
@@ -37,8 +37,8 @@ module Jasmine
|
||||
def eval_js(script)
|
||||
escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'"
|
||||
|
||||
result = @driver.get_eval(" try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }")
|
||||
JSON.parse("[#{result}]")[0]
|
||||
result = @driver.get_eval("try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }")
|
||||
JSON.parse("{\"result\":#{result}}")["result"]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -82,7 +82,7 @@ module Jasmine
|
||||
|
||||
class Server
|
||||
attr_reader :thin
|
||||
|
||||
|
||||
def initialize(port, config)
|
||||
@port = port
|
||||
@config = config
|
||||
@@ -101,6 +101,7 @@ module Jasmine
|
||||
thin_config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root)
|
||||
|
||||
app = Rack::Cascade.new([
|
||||
Rack::URLMap.new({'/' => Rack::File.new(@config.src_dir)}),
|
||||
Rack::URLMap.new(thin_config),
|
||||
JsAlert.new
|
||||
])
|
||||
|
||||
@@ -58,7 +58,7 @@ module Jasmine
|
||||
sleep 0.1
|
||||
end
|
||||
|
||||
@suites = eval_js('JSON.stringify(jsApiReporter.suites())')
|
||||
@suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }")
|
||||
end
|
||||
|
||||
def results_for(spec_id)
|
||||
@@ -69,7 +69,7 @@ module Jasmine
|
||||
def load_results
|
||||
@spec_results = {}
|
||||
@spec_ids.each_slice(50) do |slice|
|
||||
@spec_results.merge!(eval_js("JSON.stringify(jsApiReporter.resultsForSpecs(#{JSON.generate(slice)}))"))
|
||||
@spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{JSON.generate(slice)}); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }"))
|
||||
end
|
||||
@spec_results
|
||||
end
|
||||
@@ -116,7 +116,6 @@ module Jasmine
|
||||
|
||||
def report_spec(spec_id)
|
||||
spec_results = results_for(spec_id)
|
||||
|
||||
out = ""
|
||||
messages = spec_results['messages'].each do |message|
|
||||
case
|
||||
|
||||
Reference in New Issue
Block a user