diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 201abe7..26b1493 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -3,6 +3,10 @@ require 'erb' require 'json' module Jasmine + def self.root + File.expand_path(File.join(File.dirname(__FILE__), '../..')) + end + # this seemingly-over-complex method is necessary to get an open port on at least some of our Macs def self.open_socket_on_unused_port infos = Socket::getaddrinfo("localhost", nil, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE) @@ -65,6 +69,13 @@ module Jasmine spec_files = @spec_files_or_proc spec_files = spec_files.call if spec_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) [ 200, @@ -88,6 +99,16 @@ module Jasmine end end + class JsAlert + def call(env) + [ + 200, + { 'Content-Type' => 'application/javascript' }, + "document.write('

Couldn\\'t load #{env["PATH_INFO"]}!

');" + ] + end + end + class SimpleServer def self.start(port, spec_files_or_proc, mappings) require 'thin' @@ -98,9 +119,14 @@ module Jasmine } mappings.each do |from, to| config[from] = Rack::File.new(to) - end + end - app = Rack::URLMap.new(config) + config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root) + + app = Rack::Cascade.new([ + Rack::URLMap.new(config), + JsAlert.new + ]) Thin::Server.start('0.0.0.0', port, app) end diff --git a/contrib/ruby/run.html b/contrib/ruby/run.html index 9b307c7..f11b042 100644 --- a/contrib/ruby/run.html +++ b/contrib/ruby/run.html @@ -3,10 +3,14 @@ Jasmine suite - - <% spec_files.each do |spec_file| %> - + <% css_files.each do |css_file| %> + <% end %> + + <% jasmine_files.each do |jasmine_file| %> + + <% end %> + + <% spec_files.each do |spec_file| %> + + <% end %> diff --git a/examples/ruby/Rakefile b/examples/ruby/Rakefile index 79f3945..39e7893 100644 --- a/examples/ruby/Rakefile +++ b/examples/ruby/Rakefile @@ -13,20 +13,14 @@ desc "Run specs via server" task :jasmine_server do require File.expand_path(File.join(File.dirname(__FILE__), "../../contrib/ruby/jasmine_spec_builder")) - JASMINE_LIB = File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) dir_mappings = { - "/spec" => 'spec', - "/lib" => JASMINE_LIB + "/spec" => 'spec' } - includes = ['lib/' + File.basename(Dir.glob("#{JASMINE_LIB}/jasmine*.js").first), - 'lib/json2.js', - 'lib/TrivialReporter.js'] - spec_files = Dir.glob("spec/**/*[Ss]pec.js") puts "your tests are here:" puts " http://localhost:8888/run.html" - Jasmine::SimpleServer.start(8888, includes + spec_files, dir_mappings) + Jasmine::SimpleServer.start(8888, spec_files, dir_mappings) end diff --git a/examples/ruby/spec/jasmine_spec.rb b/examples/ruby/spec/jasmine_spec.rb index 9d7d6fc..6b2819b 100644 --- a/examples/ruby/spec/jasmine_spec.rb +++ b/examples/ruby/spec/jasmine_spec.rb @@ -2,19 +2,12 @@ require 'rubygems' require File.expand_path(File.join(File.dirname(__FILE__), "../../../contrib/ruby/jasmine_spec_builder")) require "selenium_rc" - -JASMINE_LIB = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib')) dir_mappings = { "/spec" => 'spec', - "/lib" => JASMINE_LIB } -includes = ['lib/' + File.basename(Dir.glob("#{JASMINE_LIB}/jasmine*.js").first), - 'lib/json2.js', - 'lib/TrivialReporter.js'] - spec_files = Dir.glob("spec/**/*[Ss]pec.js") -jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, includes + spec_files, dir_mappings) +jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, spec_files, dir_mappings) spec_builder = Jasmine::SpecBuilder.new(spec_files, jasmine_runner) should_stop = false