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'
|
||||
task :build do
|
||||
require 'json'
|
||||
|
||||
version = JSON.parse(File.new("src/version.json").read);
|
||||
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
|
||||
sources = jasmine_sources
|
||||
version = version_hash
|
||||
old_jasmine_files = Dir.glob('lib/jasmine*.js')
|
||||
old_jasmine_files.each do |file|
|
||||
File.delete(file)
|
||||
end
|
||||
jasmine = File.new("lib/jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js", 'w')
|
||||
jasmine.puts(File.read('src/base.js'))
|
||||
jasmine = File.new("lib/#{jasmine_filename version}", 'w')
|
||||
jasmine.puts(File.read(sources.shift))
|
||||
jasmine.puts %{
|
||||
jasmine.version_= {
|
||||
"major": #{version['major']},
|
||||
|
@ -24,3 +21,49 @@ jasmine.version_= {
|
|||
jasmine.puts(File.read(source_filename))
|
||||
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 'erb'
|
||||
require 'json'
|
||||
|
||||
module Jasmine
|
||||
# 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
|
||||
|
||||
class Redirect
|
||||
def initialize(url)
|
||||
@url = url
|
||||
end
|
||||
|
||||
def call(env)
|
||||
[
|
||||
302,
|
||||
{ 'Location' => @url },
|
||||
[]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
class SimpleServer
|
||||
def self.start(port, spec_files_or_proc, mappings)
|
||||
require 'thin'
|
||||
|
||||
config = {
|
||||
'/' => Jasmine::Redirect.new('/run.html'),
|
||||
'/run.html' => Jasmine::RunAdapter.new(spec_files_or_proc)
|
||||
}
|
||||
mappings.each do |from, to|
|
||||
|
@ -116,7 +132,7 @@ module Jasmine
|
|||
def eval_js(script)
|
||||
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]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -114,13 +114,15 @@ module Jasmine
|
|||
puts message["text"]
|
||||
puts "\n"
|
||||
else
|
||||
unless message["message"] =~ /^Passed.$/
|
||||
STDERR << message["message"]
|
||||
STDERR << "\n"
|
||||
|
||||
out << message["message"]
|
||||
out << "\n"
|
||||
end
|
||||
|
||||
unless message["passed"]
|
||||
unless message["passed_"]
|
||||
stack_trace = message["trace"]["stack"].gsub(/<br \/>/, "\n").gsub(/<\/?b>/, " ")
|
||||
STDERR << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/")
|
||||
STDERR << "\n"
|
||||
|
@ -129,7 +131,7 @@ module Jasmine
|
|||
|
||||
end
|
||||
fail out unless spec_results['result'] == 'passed'
|
||||
puts out
|
||||
puts out unless out.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
<head>
|
||||
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
|
||||
<title>Jasmine suite</title>
|
||||
<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="/jasmine/lib/jasmine.css" rel="stylesheet"/>
|
||||
<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>
|
||||
<% end %>
|
||||
<script type="text/javascript">
|
||||
var jsApiReporter;
|
||||
(function() {
|
||||
|
@ -31,9 +29,7 @@
|
|||
})();
|
||||
</script>
|
||||
|
||||
<% spec_files.each do |spec_file| %>
|
||||
<script src="<%= spec_file %>" type="text/javascript"></script>
|
||||
<% end %>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="jasmine_content"></div>
|
||||
|
|
|
@ -78,7 +78,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
|||
var resultItems = results.getItems();
|
||||
for (var i = 0; i < resultItems.length; i++) {
|
||||
var result = resultItems[i];
|
||||
if (!result.passed()) {
|
||||
if (result.passed && !result.passed()) {
|
||||
var resultMessageDiv = this.createDom('div', {className: 'resultMessage fail'});
|
||||
resultMessageDiv.innerHTML = result.message; // todo: lame; mend
|
||||
specDiv.appendChild(resultMessageDiv);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<head>
|
||||
<title>Jasmine Test Runner</title>
|
||||
</head>
|
||||
<script type="text/javascript" src="json2.js"></script>
|
||||
<script type="text/javascript" src="jasmine.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.beforeQueue = [];
|
||||
self.afterQueue = [];
|
||||
self.specs = [];
|
||||
};
|
||||
|
||||
|
||||
|
@ -1788,6 +1789,7 @@ jasmine.Suite.prototype.add = function(block) {
|
|||
if (block instanceof jasmine.Suite) {
|
||||
this.env.currentRunner.addSuite(block);
|
||||
}
|
||||
this.specs.push(block);
|
||||
this.queue.add(block);
|
||||
};
|
||||
|
||||
|
|
|
@ -84,3 +84,8 @@ p {
|
|||
margin-left: 5px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
#jasmine_content {
|
||||
position:fixed;
|
||||
left: 100%;
|
||||
}
|
|
@ -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">
|
||||
jasmine.include('suites/EnvTest.js', true);
|
||||
jasmine.include('suites/ExceptionsTest.js', true);
|
||||
jasmine.include('suites/MatchersTest.js', true);
|
||||
jasmine.include('suites/MultiReporterTest.js', true);
|
||||
jasmine.include('suites/NestedResultsTest.js', true);
|
||||
jasmine.include('suites/PrettyPrintTest.js', true);
|
||||
jasmine.include('suites/ReporterTest.js', true);
|
||||
jasmine.include('suites/RunnerTest.js', true);
|
||||
jasmine.include('suites/SpecRunningTest.js', true);
|
||||
jasmine.include('suites/SpyTest.js', true);
|
||||
jasmine.include('suites/TrivialReporterTest.js', true);
|
||||
jasmine.include('suites/EnvSpec.js', true);
|
||||
jasmine.include('suites/ExceptionsSpec.js', true);
|
||||
jasmine.include('suites/MatchersSpec.js', true);
|
||||
jasmine.include('suites/MultiReporterSpec.js', true);
|
||||
jasmine.include('suites/NestedResultsSpec.js', true);
|
||||
jasmine.include('suites/PrettyPrintSpec.js', true);
|
||||
jasmine.include('suites/ReporterSpec.js', true);
|
||||
jasmine.include('suites/RunnerSpec.js', true);
|
||||
jasmine.include('suites/SpecRunningSpec.js', true);
|
||||
jasmine.include('suites/SpySpec.js', true);
|
||||
jasmine.include('suites/TrivialReporterSpec.js', true);
|
||||
</script>
|
||||
|
||||
<link href="../lib/jasmine.css" rel="stylesheet"/>
|
||||
|
|
|
@ -16,6 +16,7 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
|
|||
self.env = env;
|
||||
self.beforeQueue = [];
|
||||
self.afterQueue = [];
|
||||
self.specs = [];
|
||||
};
|
||||
|
||||
|
||||
|
@ -53,6 +54,7 @@ jasmine.Suite.prototype.add = function(block) {
|
|||
if (block instanceof jasmine.Suite) {
|
||||
this.env.currentRunner.addSuite(block);
|
||||
}
|
||||
this.specs.push(block);
|
||||
this.queue.add(block);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue