Fix compatibility with the ruby contrib runner
This commit is contained in:
parent
f9d61108ee
commit
ba5b4ab166
57
Rakefile
57
Rakefile
@ -1,17 +1,14 @@
|
|||||||
desc 'Builds lib/jasmine from source'
|
desc 'Builds lib/jasmine from source'
|
||||||
task :build do
|
task :build do
|
||||||
require 'json'
|
require 'json'
|
||||||
|
sources = jasmine_sources
|
||||||
version = JSON.parse(File.new("src/version.json").read);
|
version = version_hash
|
||||||
sources = ["src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
|
|
||||||
|
|
||||||
sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort
|
|
||||||
old_jasmine_files = Dir.glob('lib/jasmine*.js')
|
old_jasmine_files = Dir.glob('lib/jasmine*.js')
|
||||||
old_jasmine_files.each do |file|
|
old_jasmine_files.each do |file|
|
||||||
File.delete(file)
|
File.delete(file)
|
||||||
end
|
end
|
||||||
jasmine = File.new("lib/jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js", 'w')
|
jasmine = File.new("lib/#{jasmine_filename version}", 'w')
|
||||||
jasmine.puts(File.read('src/base.js'))
|
jasmine.puts(File.read(sources.shift))
|
||||||
jasmine.puts %{
|
jasmine.puts %{
|
||||||
jasmine.version_= {
|
jasmine.version_= {
|
||||||
"major": #{version['major']},
|
"major": #{version['major']},
|
||||||
@ -24,3 +21,49 @@ jasmine.version_= {
|
|||||||
jasmine.puts(File.read(source_filename))
|
jasmine.puts(File.read(source_filename))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def jasmine_sources
|
||||||
|
sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
|
||||||
|
|
||||||
|
sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def jasmine_filename(version)
|
||||||
|
"jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js"
|
||||||
|
end
|
||||||
|
|
||||||
|
def version_hash
|
||||||
|
JSON.parse(File.new("src/version.json").read);
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :test do
|
||||||
|
desc "Run continuous integration tests"
|
||||||
|
require "spec"
|
||||||
|
require 'spec/rake/spectask'
|
||||||
|
|
||||||
|
Spec::Rake::SpecTask.new(:ci) do |t|
|
||||||
|
Rake::Task['build'].invoke
|
||||||
|
t.spec_opts = ["--color", "--format", "specdoc"]
|
||||||
|
t.spec_files = ["spec/jasmine_spec.rb"]
|
||||||
|
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
|
||||||
|
end
|
@ -1,5 +1,6 @@
|
|||||||
require 'socket'
|
require 'socket'
|
||||||
require 'erb'
|
require 'erb'
|
||||||
|
require 'json'
|
||||||
|
|
||||||
module Jasmine
|
module Jasmine
|
||||||
# this seemingly-over-complex method is necessary to get an open port on at least some of our Macs
|
# this seemingly-over-complex method is necessary to get an open port on at least some of our Macs
|
||||||
@ -61,11 +62,26 @@ module Jasmine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Redirect
|
||||||
|
def initialize(url)
|
||||||
|
@url = url
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
[
|
||||||
|
302,
|
||||||
|
{ 'Location' => @url },
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class SimpleServer
|
class SimpleServer
|
||||||
def self.start(port, spec_files_or_proc, mappings)
|
def self.start(port, spec_files_or_proc, mappings)
|
||||||
require 'thin'
|
require 'thin'
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
'/' => Jasmine::Redirect.new('/run.html'),
|
||||||
'/run.html' => Jasmine::RunAdapter.new(spec_files_or_proc)
|
'/run.html' => Jasmine::RunAdapter.new(spec_files_or_proc)
|
||||||
}
|
}
|
||||||
mappings.each do |from, to|
|
mappings.each do |from, to|
|
||||||
@ -116,7 +132,7 @@ module Jasmine
|
|||||||
def eval_js(script)
|
def eval_js(script)
|
||||||
escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'"
|
escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'"
|
||||||
|
|
||||||
result = @driver.get_eval("window.eval(#{escaped_script})")
|
result = @driver.get_eval("eval(#{escaped_script}, window)")
|
||||||
JSON.parse("[#{result}]")[0]
|
JSON.parse("[#{result}]")[0]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -114,13 +114,15 @@ module Jasmine
|
|||||||
puts message["text"]
|
puts message["text"]
|
||||||
puts "\n"
|
puts "\n"
|
||||||
else
|
else
|
||||||
|
unless message["message"] =~ /^Passed.$/
|
||||||
STDERR << message["message"]
|
STDERR << message["message"]
|
||||||
STDERR << "\n"
|
STDERR << "\n"
|
||||||
|
|
||||||
out << message["message"]
|
out << message["message"]
|
||||||
out << "\n"
|
out << "\n"
|
||||||
|
end
|
||||||
|
|
||||||
unless message["passed"]
|
unless message["passed_"]
|
||||||
stack_trace = message["trace"]["stack"].gsub(/<br \/>/, "\n").gsub(/<\/?b>/, " ")
|
stack_trace = message["trace"]["stack"].gsub(/<br \/>/, "\n").gsub(/<\/?b>/, " ")
|
||||||
STDERR << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/")
|
STDERR << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/")
|
||||||
STDERR << "\n"
|
STDERR << "\n"
|
||||||
@ -129,7 +131,7 @@ module Jasmine
|
|||||||
|
|
||||||
end
|
end
|
||||||
fail out unless spec_results['result'] == 'passed'
|
fail out unless spec_results['result'] == 'passed'
|
||||||
puts out
|
puts out unless out.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -3,12 +3,10 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
|
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
|
||||||
<title>Jasmine suite</title>
|
<title>Jasmine suite</title>
|
||||||
<script src="/jasmine/lib/jasmine.js"></script>
|
<link rel="stylesheet" href="lib/jasmine.css" type="text/css" media="screen" />
|
||||||
<script src="/jasmine/lib/json2.js"></script><!-- todo: don't load JSON in the test runner! [20090710 xw] -->
|
<% spec_files.each do |spec_file| %>
|
||||||
<script src="/jasmine/lib/TrivialReporter.js"></script>
|
<script src="<%= spec_file %>" type="text/javascript"></script>
|
||||||
<script src="/specs/javascripts/screw-jasmine-compat.js"></script>
|
<% end %>
|
||||||
<script type="text/javascript"></script>
|
|
||||||
<link href="/jasmine/lib/jasmine.css" rel="stylesheet"/>
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var jsApiReporter;
|
var jsApiReporter;
|
||||||
(function() {
|
(function() {
|
||||||
@ -31,9 +29,7 @@
|
|||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<% spec_files.each do |spec_file| %>
|
|
||||||
<script src="<%= spec_file %>" type="text/javascript"></script>
|
|
||||||
<% end %>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="jasmine_content"></div>
|
<div id="jasmine_content"></div>
|
||||||
|
@ -78,7 +78,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
|||||||
var resultItems = results.getItems();
|
var resultItems = results.getItems();
|
||||||
for (var i = 0; i < resultItems.length; i++) {
|
for (var i = 0; i < resultItems.length; i++) {
|
||||||
var result = resultItems[i];
|
var result = resultItems[i];
|
||||||
if (!result.passed()) {
|
if (result.passed && !result.passed()) {
|
||||||
var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'});
|
var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'});
|
||||||
resultMessageDiv.innerHTML = result.message; // todo: lame; mend
|
resultMessageDiv.innerHTML = result.message; // todo: lame; mend
|
||||||
specDiv.appendChild(resultMessageDiv);
|
specDiv.appendChild(resultMessageDiv);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Jasmine Test Runner</title>
|
<title>Jasmine Test Runner</title>
|
||||||
</head>
|
</head>
|
||||||
<script type="text/javascript" src="json2.js"></script>
|
|
||||||
<script type="text/javascript" src="jasmine.js"></script>
|
<script type="text/javascript" src="jasmine.js"></script>
|
||||||
<script type="text/javascript" src="TrivialReporter.js"></script>
|
<script type="text/javascript" src="TrivialReporter.js"></script>
|
||||||
|
|
||||||
|
@ -1751,6 +1751,7 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
|
|||||||
self.env = env;
|
self.env = env;
|
||||||
self.beforeQueue = [];
|
self.beforeQueue = [];
|
||||||
self.afterQueue = [];
|
self.afterQueue = [];
|
||||||
|
self.specs = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1788,6 +1789,7 @@ jasmine.Suite.prototype.add = function(block) {
|
|||||||
if (block instanceof jasmine.Suite) {
|
if (block instanceof jasmine.Suite) {
|
||||||
this.env.currentRunner.addSuite(block);
|
this.env.currentRunner.addSuite(block);
|
||||||
}
|
}
|
||||||
|
this.specs.push(block);
|
||||||
this.queue.add(block);
|
this.queue.add(block);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,3 +84,8 @@ p {
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#jasmine_content {
|
||||||
|
position:fixed;
|
||||||
|
left: 100%;
|
||||||
|
}
|
32
spec/jasmine_spec.rb
Normal file
32
spec/jasmine_spec.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
require 'rubygems'
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), "../contrib/ruby/jasmine_spec_builder"))
|
||||||
|
require "selenium_rc"
|
||||||
|
|
||||||
|
dir_mappings = {
|
||||||
|
"/spec" => 'spec',
|
||||||
|
"/lib" => 'lib',
|
||||||
|
"/src" => 'src'
|
||||||
|
}
|
||||||
|
|
||||||
|
def jasmine_sources
|
||||||
|
sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
|
||||||
|
|
||||||
|
sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
includes = jasmine_sources + ['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)
|
||||||
|
spec_builder = Jasmine::SpecBuilder.new(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
|
@ -26,17 +26,17 @@
|
|||||||
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jasmine.include('suites/EnvTest.js', true);
|
jasmine.include('suites/EnvSpec.js', true);
|
||||||
jasmine.include('suites/ExceptionsTest.js', true);
|
jasmine.include('suites/ExceptionsSpec.js', true);
|
||||||
jasmine.include('suites/MatchersTest.js', true);
|
jasmine.include('suites/MatchersSpec.js', true);
|
||||||
jasmine.include('suites/MultiReporterTest.js', true);
|
jasmine.include('suites/MultiReporterSpec.js', true);
|
||||||
jasmine.include('suites/NestedResultsTest.js', true);
|
jasmine.include('suites/NestedResultsSpec.js', true);
|
||||||
jasmine.include('suites/PrettyPrintTest.js', true);
|
jasmine.include('suites/PrettyPrintSpec.js', true);
|
||||||
jasmine.include('suites/ReporterTest.js', true);
|
jasmine.include('suites/ReporterSpec.js', true);
|
||||||
jasmine.include('suites/RunnerTest.js', true);
|
jasmine.include('suites/RunnerSpec.js', true);
|
||||||
jasmine.include('suites/SpecRunningTest.js', true);
|
jasmine.include('suites/SpecRunningSpec.js', true);
|
||||||
jasmine.include('suites/SpyTest.js', true);
|
jasmine.include('suites/SpySpec.js', true);
|
||||||
jasmine.include('suites/TrivialReporterTest.js', true);
|
jasmine.include('suites/TrivialReporterSpec.js', true);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<link href="../lib/jasmine.css" rel="stylesheet"/>
|
<link href="../lib/jasmine.css" rel="stylesheet"/>
|
||||||
|
@ -16,6 +16,7 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
|
|||||||
self.env = env;
|
self.env = env;
|
||||||
self.beforeQueue = [];
|
self.beforeQueue = [];
|
||||||
self.afterQueue = [];
|
self.afterQueue = [];
|
||||||
|
self.specs = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ jasmine.Suite.prototype.add = function(block) {
|
|||||||
if (block instanceof jasmine.Suite) {
|
if (block instanceof jasmine.Suite) {
|
||||||
this.env.currentRunner.addSuite(block);
|
this.env.currentRunner.addSuite(block);
|
||||||
}
|
}
|
||||||
|
this.specs.push(block);
|
||||||
this.queue.add(block);
|
this.queue.add(block);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user