Jasmine::Runner arranges for jasmine.js, json.js, and TrivialReporter.js to be included, so callers should remove those files.

This commit is contained in:
Christian Williams & Kim Eric Mittler 2009-09-02 12:16:16 -07:00
parent 5e8b52debf
commit 268cb0c6c5
4 changed files with 41 additions and 21 deletions

View File

@ -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('<p>Couldn\\'t load #{env["PATH_INFO"]}!</p>');"
]
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

View File

@ -3,10 +3,14 @@
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<title>Jasmine suite</title>
<link rel="stylesheet" href="lib/jasmine.css" type="text/css" media="screen" />
<% spec_files.each do |spec_file| %>
<script src="<%= spec_file %>" type="text/javascript"></script>
<% css_files.each do |css_file| %>
<link rel="stylesheet" href="<%= css_file %>" type="text/css" media="screen" />
<% end %>
<% jasmine_files.each do |jasmine_file| %>
<script src="<%= jasmine_file %>" type="text/javascript"></script>
<% end %>
<script type="text/javascript">
var jsApiReporter;
(function() {
@ -29,6 +33,9 @@
})();
</script>
<% spec_files.each do |spec_file| %>
<script src="<%= spec_file %>" type="text/javascript"></script>
<% end %>
</head>
<body>

View File

@ -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

View File

@ -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