From ba5b4ab166b2577d7f0dc1bf4f36b65bc045e262 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Wed, 26 Aug 2009 15:55:08 -0700 Subject: [PATCH] Fix compatibility with the ruby contrib runner --- Rakefile | 57 ++++++++++++++++--- contrib/ruby/jasmine_runner.rb | 18 +++++- contrib/ruby/jasmine_spec_builder.rb | 14 +++-- contrib/ruby/run.html | 14 ++--- lib/TrivialReporter.js | 2 +- lib/example_suite.html | 1 - lib/jasmine-0.9.0.js | 2 + lib/jasmine.css | 5 ++ spec/jasmine_spec.rb | 32 +++++++++++ spec/runner.html | 22 +++---- spec/suites/{EnvTest.js => EnvSpec.js} | 0 .../{ExceptionsTest.js => ExceptionsSpec.js} | 0 .../{MatchersTest.js => MatchersSpec.js} | 0 ...tiReporterTest.js => MultiReporterSpec.js} | 0 ...tedResultsTest.js => NestedResultsSpec.js} | 0 ...{PrettyPrintTest.js => PrettyPrintSpec.js} | 0 .../{ReporterTest.js => ReporterSpec.js} | 0 spec/suites/{RunnerTest.js => RunnerSpec.js} | 0 ...{SpecRunningTest.js => SpecRunningSpec.js} | 0 spec/suites/{SpyTest.js => SpySpec.js} | 0 ...ReporterTest.js => TrivialReporterSpec.js} | 0 src/Suite.js | 2 + 22 files changed, 133 insertions(+), 36 deletions(-) create mode 100644 spec/jasmine_spec.rb rename spec/suites/{EnvTest.js => EnvSpec.js} (100%) rename spec/suites/{ExceptionsTest.js => ExceptionsSpec.js} (100%) rename spec/suites/{MatchersTest.js => MatchersSpec.js} (100%) rename spec/suites/{MultiReporterTest.js => MultiReporterSpec.js} (100%) rename spec/suites/{NestedResultsTest.js => NestedResultsSpec.js} (100%) rename spec/suites/{PrettyPrintTest.js => PrettyPrintSpec.js} (100%) rename spec/suites/{ReporterTest.js => ReporterSpec.js} (100%) rename spec/suites/{RunnerTest.js => RunnerSpec.js} (100%) rename spec/suites/{SpecRunningTest.js => SpecRunningSpec.js} (100%) rename spec/suites/{SpyTest.js => SpySpec.js} (100%) rename spec/suites/{TrivialReporterTest.js => TrivialReporterSpec.js} (100%) diff --git a/Rakefile b/Rakefile index 45276ce..cd8abf6 100644 --- a/Rakefile +++ b/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']}, @@ -23,4 +20,50 @@ jasmine.version_= { sources.each do |source_filename| 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 \ No newline at end of file diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 0f0eb4f..f20fd0c 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -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 diff --git a/contrib/ruby/jasmine_spec_builder.rb b/contrib/ruby/jasmine_spec_builder.rb index 591cd10..6e03801 100644 --- a/contrib/ruby/jasmine_spec_builder.rb +++ b/contrib/ruby/jasmine_spec_builder.rb @@ -114,13 +114,15 @@ module Jasmine puts message["text"] puts "\n" else - STDERR << message["message"] - STDERR << "\n" + unless message["message"] =~ /^Passed.$/ + STDERR << message["message"] + STDERR << "\n" - out << message["message"] - out << "\n" + out << message["message"] + out << "\n" + end - unless message["passed"] + unless message["passed_"] stack_trace = message["trace"]["stack"].gsub(/
/, "\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 diff --git a/contrib/ruby/run.html b/contrib/ruby/run.html index 0f3035d..9b307c7 100644 --- a/contrib/ruby/run.html +++ b/contrib/ruby/run.html @@ -3,12 +3,10 @@ Jasmine suite - - - - - - + + <% spec_files.each do |spec_file| %> + + <% end %> - <% spec_files.each do |spec_file| %> - - <% end %> +
diff --git a/lib/TrivialReporter.js b/lib/TrivialReporter.js index 5799d3f..ff8cdbf 100644 --- a/lib/TrivialReporter.js +++ b/lib/TrivialReporter.js @@ -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); diff --git a/lib/example_suite.html b/lib/example_suite.html index b59d189..4fc289c 100644 --- a/lib/example_suite.html +++ b/lib/example_suite.html @@ -4,7 +4,6 @@ Jasmine Test Runner - diff --git a/lib/jasmine-0.9.0.js b/lib/jasmine-0.9.0.js index dbfac26..a76eb85 100644 --- a/lib/jasmine-0.9.0.js +++ b/lib/jasmine-0.9.0.js @@ -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); }; diff --git a/lib/jasmine.css b/lib/jasmine.css index 6370d7a..760b13e 100644 --- a/lib/jasmine.css +++ b/lib/jasmine.css @@ -83,4 +83,9 @@ p { .runSpec { margin-left: 5px; float: right; +} + +#jasmine_content { + position:fixed; + left: 100%; } \ No newline at end of file diff --git a/spec/jasmine_spec.rb b/spec/jasmine_spec.rb new file mode 100644 index 0000000..06e3b40 --- /dev/null +++ b/spec/jasmine_spec.rb @@ -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 diff --git a/spec/runner.html b/spec/runner.html index 70e344f..8816958 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -26,17 +26,17 @@ diff --git a/spec/suites/EnvTest.js b/spec/suites/EnvSpec.js similarity index 100% rename from spec/suites/EnvTest.js rename to spec/suites/EnvSpec.js diff --git a/spec/suites/ExceptionsTest.js b/spec/suites/ExceptionsSpec.js similarity index 100% rename from spec/suites/ExceptionsTest.js rename to spec/suites/ExceptionsSpec.js diff --git a/spec/suites/MatchersTest.js b/spec/suites/MatchersSpec.js similarity index 100% rename from spec/suites/MatchersTest.js rename to spec/suites/MatchersSpec.js diff --git a/spec/suites/MultiReporterTest.js b/spec/suites/MultiReporterSpec.js similarity index 100% rename from spec/suites/MultiReporterTest.js rename to spec/suites/MultiReporterSpec.js diff --git a/spec/suites/NestedResultsTest.js b/spec/suites/NestedResultsSpec.js similarity index 100% rename from spec/suites/NestedResultsTest.js rename to spec/suites/NestedResultsSpec.js diff --git a/spec/suites/PrettyPrintTest.js b/spec/suites/PrettyPrintSpec.js similarity index 100% rename from spec/suites/PrettyPrintTest.js rename to spec/suites/PrettyPrintSpec.js diff --git a/spec/suites/ReporterTest.js b/spec/suites/ReporterSpec.js similarity index 100% rename from spec/suites/ReporterTest.js rename to spec/suites/ReporterSpec.js diff --git a/spec/suites/RunnerTest.js b/spec/suites/RunnerSpec.js similarity index 100% rename from spec/suites/RunnerTest.js rename to spec/suites/RunnerSpec.js diff --git a/spec/suites/SpecRunningTest.js b/spec/suites/SpecRunningSpec.js similarity index 100% rename from spec/suites/SpecRunningTest.js rename to spec/suites/SpecRunningSpec.js diff --git a/spec/suites/SpyTest.js b/spec/suites/SpySpec.js similarity index 100% rename from spec/suites/SpyTest.js rename to spec/suites/SpySpec.js diff --git a/spec/suites/TrivialReporterTest.js b/spec/suites/TrivialReporterSpec.js similarity index 100% rename from spec/suites/TrivialReporterTest.js rename to spec/suites/TrivialReporterSpec.js diff --git a/src/Suite.js b/src/Suite.js index 71b8dca..4b7d46f 100644 --- a/src/Suite.js +++ b/src/Suite.js @@ -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); };