diff --git a/Rakefile b/Rakefile index f6ae1cd..767a100 100644 --- a/Rakefile +++ b/Rakefile @@ -13,19 +13,16 @@ def version_hash JSON.parse(File.new("src/version.json").read); end -def start_jasmine_server(jasmine_includes) +def start_jasmine_server(jasmine_includes = nil) require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) - includes = jasmine_includes + - ['/lib/json2.js', - '/lib/TrivialReporter.js'] - puts "your tests are here:" puts " http://localhost:8888/run.html" Jasmine::SimpleServer.start(8888, - lambda { includes + JasmineHelper.spec_file_urls }, - JasmineHelper.dir_mappings) + lambda { JasmineHelper.spec_file_urls }, + JasmineHelper.dir_mappings, + jasmine_includes) end namespace :jasmine do @@ -70,15 +67,14 @@ jasmine.version_= { desc "Run jasmine tests of source via server" task :server do - jasmine_includes = jasmine_sources + jasmine_includes = lambda { jasmine_sources + ['lib/TrivialReporter.js'] } start_jasmine_server(jasmine_includes) end desc "Build jasmine and run tests via server" task :server_build => 'jasmine:build' do - jasmine_includes = ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] - start_jasmine_server(jasmine_includes) + start_jasmine_server end namespace :test do @@ -95,23 +91,4 @@ jasmine.version_= { end -end - -desc "Run jasmine tests via server" -task :jasmine_server do - require File.expand_path(File.join(File.dirname(__FILE__), "contrib/ruby/jasmine_spec_builder")) - - includes = jasmine_sources + ['lib/TrivialReporter.js'] - spec_files = Dir.glob("spec/**/*.js") - - dir_mappings = { - "/spec" => "spec", - "/lib" => "lib", - "/src" => 'src' - } - - puts "your tests are here:" - puts " http://localhost:8888/run.html" - - Jasmine::SimpleServer.start(8888, includes + spec_files, dir_mappings) end \ No newline at end of file diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index bc77549..61ff5e0 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -61,20 +61,23 @@ module Jasmine end class RunAdapter - def initialize(spec_files_or_proc) + def initialize(spec_files_or_proc, jasmine_files = nil) @spec_files_or_proc = spec_files_or_proc + @jasmine_files = jasmine_files || [ + "/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first), + "/__JASMINE_ROOT__/lib/TrivialReporter.js", + "/__JASMINE_ROOT__/lib/json2.js" + ] end def call(env) spec_files = @spec_files_or_proc spec_files = spec_files.call if spec_files.respond_to?(:call) + jasmine_files = @jasmine_files + jasmine_files = jasmine_files.call if jasmine_files.respond_to?(:call) + css_files = ["/__JASMINE_ROOT__/lib/jasmine.css"] - jasmine_files = [ - "/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first), - "/__JASMINE_ROOT__/lib/TrivialReporter.js", - "/__JASMINE_ROOT__/lib/json2.js" - ] body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding) [ @@ -110,12 +113,12 @@ module Jasmine end class SimpleServer - def self.start(port, spec_files_or_proc, mappings) + def self.start(port, spec_files_or_proc, mappings, jasmine_files = nil) require 'thin' config = { - '/run.html' => Jasmine::Redirect.new('/'), - '/' => Jasmine::RunAdapter.new(spec_files_or_proc) + '/run.html' => Jasmine::Redirect.new('/'), + '/' => Jasmine::RunAdapter.new(spec_files_or_proc, jasmine_files) } mappings.each do |from, to| config[from] = Rack::File.new(to) @@ -124,8 +127,8 @@ module Jasmine config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root) app = Rack::Cascade.new([ - Rack::URLMap.new(config), - JsAlert.new + Rack::URLMap.new(config), + JsAlert.new ]) Thin::Server.start('0.0.0.0', port, app) @@ -170,16 +173,21 @@ module Jasmine def eval_js(script) escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'" - result = @driver.get_eval("window.eval(#{escaped_script})") + begin + result = @driver.get_eval("window.eval(#{escaped_script})") + rescue Selenium::CommandError + result = @driver.get_eval("eval(#{escaped_script}, window)") + end JSON.parse("[#{result}]")[0] end end class Runner - def initialize(selenium_jar_path, spec_files, dir_mappings) + def initialize(selenium_jar_path, spec_files, dir_mappings, jasmine_files = nil) @selenium_jar_path = selenium_jar_path @spec_files = spec_files @dir_mappings = dir_mappings + @jasmine_files = jasmine_files @selenium_pid = nil @jasmine_server_pid = nil @@ -208,7 +216,7 @@ module Jasmine @jasmine_server_pid = fork do Process.setpgrp - Jasmine::SimpleServer.start(@jasmine_server_port, @spec_files, @dir_mappings) + Jasmine::SimpleServer.start(@jasmine_server_port, @spec_files, @dir_mappings, @jasmine_files) exit! 0 end puts "jasmine server started. pid is #{@jasmine_server_pid}" diff --git a/doc/files.html b/doc/files.html index a6cf772..5d4b5dd 100644 --- a/doc/files.html +++ b/doc/files.html @@ -258,7 +258,7 @@ ul.inheritsList