Merge branch 'master' of git@github.com:emi/jasmine

This commit is contained in:
xian 2009-08-10 13:52:27 -07:00
commit 0f04084f6c
7 changed files with 123 additions and 45 deletions

1
.tylium/bootstrap.rb Normal file
View File

@ -0,0 +1 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '.tylium', 'bootstrap'))

View File

@ -19,15 +19,39 @@ module Jasmine
port
end
class RunAdapter
def initialize(spec_files)
p "spec_files: #{spec_files}"
def self.server_is_listening_on(hostname, port)
require 'socket'
begin
socket = TCPSocket.open(hostname, port)
rescue Errno::ECONNREFUSED
return false
end
socket.close
true
end
@spec_files = spec_files
def self.wait_for_listener(port, name = "required process", seconds_to_wait = 10)
time_out_at = Time.now + seconds_to_wait
until server_is_listening_on "localhost", port
sleep 0.1
puts "Waiting for #{name} on #{port}..."
raise "#{name} didn't show up on port #{port} after #{seconds_to_wait} seconds." if Time.now > time_out_at
end
end
def self.kill_process_group(process_group_id, signal="TERM")
Process.kill signal, -process_group_id # negative pid means kill process group. (see man 2 kill)
end
class RunAdapter
def initialize(spec_files_or_proc)
@spec_files_or_proc = spec_files_or_proc
end
def call(env)
spec_files = @spec_files
spec_files = @spec_files_or_proc
spec_files = spec_files.call if spec_files.respond_to?(:call)
body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding)
[
200,
@ -38,11 +62,11 @@ module Jasmine
end
class SimpleServer
def self.start(port, spec_dir, mappings)
def self.start(port, spec_files_or_proc, mappings)
require 'thin'
config = {
'/run.html' => Jasmine::RunAdapter.new(spec_dir)
'/run.html' => Jasmine::RunAdapter.new(spec_files_or_proc)
}
mappings.each do |from, to|
config[from] = Rack::File.new(to)
@ -50,7 +74,6 @@ module Jasmine
app = Rack::URLMap.new(config)
server_port = Jasmine::find_unused_port
Thin::Server.start('0.0.0.0', port, app)
end
end
@ -119,26 +142,6 @@ module Jasmine
stop_servers
end
def server_is_listening_on(hostname, port)
require 'socket'
begin
socket = TCPSocket.open(hostname, port)
rescue Errno::ECONNREFUSED
return false
end
socket.close
true
end
def wait_for_listener(port, name = "required process", seconds_to_wait = 10)
seconds_waited = 0
until server_is_listening_on "localhost", port
sleep 1
puts "Waiting for #{name} on #{port}..."
raise "#{name} didn't show up on port #{port} after #{seconds_to_wait} seconds." if (seconds_waited += 1) >= seconds_to_wait
end
end
def start_servers
@jasmine_server_port = Jasmine::find_unused_port
@selenium_server_port = Jasmine::find_unused_port
@ -156,18 +159,14 @@ module Jasmine
end
puts "jasmine server started. pid is #{@jasmine_server_pid}"
wait_for_listener(@selenium_server_port, "selenium server")
wait_for_listener(@jasmine_server_port, "jasmine server")
end
def kill_process_group(process_group_id, signal="TERM")
Process.kill signal, -process_group_id # negative pid means kill process group. (see man 2 kill)
Jasmine::wait_for_listener(@selenium_server_port, "selenium server")
Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server")
end
def stop_servers
puts "shutting down the servers..."
kill_process_group(@selenium_pid) if @selenium_pid
kill_process_group(@jasmine_server_pid) if @jasmine_server_pid
Jasmine::kill_process_group(@selenium_pid) if @selenium_pid
Jasmine::kill_process_group(@jasmine_server_pid) if @jasmine_server_pid
end
def run

View File

@ -0,0 +1,51 @@
require 'spec'
require 'open-uri'
require File.dirname(__FILE__) + '/jasmine_runner'
describe Jasmine::SimpleServer do
before do
@port = Jasmine::find_unused_port
end
after do
Jasmine::kill_process_group(@jasmine_server_pid) if @jasmine_server_pid
end
it "should start and print script tags" do
@jasmine_server_pid = fork do
Process.setpgrp
Jasmine::SimpleServer.start(@port, ["file1", "file2"], {})
exit! 0
end
Jasmine::wait_for_listener(@port)
run_html = open("http://localhost:#{@port}/run.html").read
run_html.should =~ /<script src="file1"/
run_html.should =~ /<script src="file2"/
end
it "should take a proc that returns a list of spec files" do
spec_fileses = [["file1", "file2"], ["file1", "file2", "file3"]]
spec_files_proc = lambda do
spec_fileses.shift
end
@jasmine_server_pid = fork do
Process.setpgrp
Jasmine::SimpleServer.start(@port, spec_files_proc, {})
exit! 0
end
Jasmine::wait_for_listener(@port)
run_html = open("http://localhost:#{@port}/run.html").read
run_html.should =~ /<script src="file1"/
run_html.should =~ /<script src="file2"/
run_html = open("http://localhost:#{@port}/run.html").read
run_html.should =~ /<script src="file1"/
run_html.should =~ /<script src="file2"/
run_html.should =~ /<script src="file3"/
end
end

View File

@ -121,7 +121,7 @@ module Jasmine
out << "\n"
unless message["passed"]
stack_trace = message["trace"]["stack"]
stack_trace = message["trace"]["stack"].gsub(/<br \/>/, "\n").gsub(/<\/?b>/, " ")
STDERR << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/")
STDERR << "\n"
end

View File

@ -3,12 +3,12 @@
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<title>Jasmine suite</title>
<script src="/specs/javascripts/jasmine/lib/jasmine.js"></script>
<script src="/specs/javascripts/jasmine/lib/json2.js"></script><!-- todo: don't load JSON in the test runner! [20090710 xw] -->
<script src="/specs/javascripts/jasmine/lib/TrivialReporter.js"></script>
<script src="/jasmine/lib/jasmine.js"></script>
<script src="/jasmine/lib/json2.js"></script><!-- todo: don't load JSON in the test runner! [20090710 xw] -->
<script src="/jasmine/lib/TrivialReporter.js"></script>
<script src="/specs/javascripts/screw-jasmine-compat.js"></script>
<script type="text/javascript"></script>
<link href="/core/jasmine.css" rel="stylesheet"/>
<link href="/jasmine/lib/jasmine.css" rel="stylesheet"/>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
var jsApiReporter = new jasmine.JsApiReporter();

View File

@ -42,7 +42,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (!result.passed) {
var resultMessageDiv = this.createDom('div', {className: 'resultMessage'});
var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'});
resultMessageDiv.innerHTML = result.message; // todo: lame; mend
specDiv.appendChild(resultMessageDiv);
specDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));

View File

@ -14,11 +14,38 @@ p {
padding-left: 20px;
}
p.fail {
.fail {
background: url( ../images/fail-16.png ) no-repeat;
padding-left: 20px;
color: red;
}
p.fail_in_summary {
.fail_in_summary {
color: red;
}
}
.spec {
margin: 5px;
}
.passed {
background-color: lightgreen;
}
.failed {
background-color: pink;
}
.resultMessage {
white-space: pre;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
height: 5em;
overflow: auto;
border-left: 1px solid red;
padding-left: 5em;
}