From bece09bba8dbb43442aa68ac565fa014bea556d3 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Tue, 24 Nov 2009 22:42:15 -0800 Subject: [PATCH] remove jasmine server; use jasmine init to copy (or append) a Rakefile with common jasmine tasks --- bin/jasmine | 43 ++++++++++++++++----------- jasmine-ruby.gemspec | 5 +++- lib/jasmine-ruby.rb | 1 + lib/jasmine-ruby/jasmine_helper.rb | 41 +++++++++++-------------- lib/jasmine-ruby/jasmine_meta_spec.rb | 22 ++++++++++++++ spec/jasmine_spec.rb | 2 +- tasks/jasmine.rake | 2 +- templates/Rakefile | 27 +++++++++++++++++ 8 files changed, 99 insertions(+), 44 deletions(-) create mode 100644 lib/jasmine-ruby.rb create mode 100644 lib/jasmine-ruby/jasmine_meta_spec.rb create mode 100644 templates/Rakefile diff --git a/bin/jasmine b/bin/jasmine index 21c5bb5..92815ee 100755 --- a/bin/jasmine +++ b/bin/jasmine @@ -1,26 +1,35 @@ #!/usr/bin/env ruby require 'rubygems' -cwd = File.expand_path(File.join(File.dirname(__FILE__), '..')) -require File.expand_path(File.join(cwd, "lib", "jasmine-ruby", "jasmine_helper.rb")) +require 'rake' -#to load JasmineHelper overrides -if ARGV[1] - require File.expand_path(File.join(Dir.pwd, ARGV[1])) +def cwd + File.expand_path(File.join(File.dirname(__FILE__), '..')) end -if ARGV[0] == 'server' - require File.expand_path(File.join(cwd, "jasmine/contrib/ruby/jasmine_spec_builder")) - puts "your tests are here:" - puts " http://localhost:8888/run.html" - Jasmine::SimpleServer.start(8888, - lambda { JasmineHelper.specs }, - JasmineHelper.dir_mappings, - :spec_helpers => JasmineHelper.spec_helpers) +def expand(*paths) + File.expand_path(File.join(*paths)) +end + +def rakefile_path + expand(cwd, 'templates/Rakefile') end if ARGV[0] == 'init' require 'ftools' - File.makedirs('spec') - dest_dir = File.expand_path(File.join(Dir.pwd, 'spec')) - File.copy(File.expand_path(File.join(cwd, 'templates/example_spec.js')), dest_dir) -end \ No newline at end of file + File.makedirs('spec/javascripts') + dest_root = expand(Dir.pwd, 'spec') + dest_spec = expand(Dir.pwd, 'spec/javascripts') + File.copy(expand(cwd, 'templates/example_spec.js'), dest_spec) + if File.exist?(expand(Dir.pwd, 'Rakefile')) + existing_rakefile = expand(Dir.pwd, 'Rakefile') + load existing_rakefile + unless Rake::Task.task_defined?('jasmine') + open(existing_rakefile, 'a') do |f| + f.write(File.read(rakefile_path)) + end + end + else + File.copy(rakefile_path, Dir.pwd) + end +end + diff --git a/jasmine-ruby.gemspec b/jasmine-ruby.gemspec index 5fdb6d2..9cdec64 100644 --- a/jasmine-ruby.gemspec +++ b/jasmine-ruby.gemspec @@ -28,8 +28,11 @@ Gem::Specification.new do |s| "jasmine/lib/jasmine.css", "jasmine/lib/json2.js", "lib/jasmine-ruby/jasmine_helper.rb", + "lib/jasmine-ruby/jasmine_meta_spec.rb", + "lib/jasmine-ruby.rb", "tasks/jasmine.rake", - "templates/example_spec.js" + "templates/example_spec.js", + "templates/Rakefile" ] s.homepage = %q{http://github.com/ragaskar/jasmine-ruby} s.rdoc_options = ["--charset=UTF-8"] diff --git a/lib/jasmine-ruby.rb b/lib/jasmine-ruby.rb new file mode 100644 index 0000000..83f5ebd --- /dev/null +++ b/lib/jasmine-ruby.rb @@ -0,0 +1 @@ +require 'jasmine-ruby/jasmine_helper' \ No newline at end of file diff --git a/lib/jasmine-ruby/jasmine_helper.rb b/lib/jasmine-ruby/jasmine_helper.rb index 772bf13..cdaf6cc 100755 --- a/lib/jasmine-ruby/jasmine_helper.rb +++ b/lib/jasmine-ruby/jasmine_helper.rb @@ -1,54 +1,47 @@ class JasmineHelper - def self.jasmine_lib_dir - File.expand_path(File.join(jasmine_root, 'lib')) + def self.lib_dir + File.expand_path(File.join(root, 'lib')) end def self.jasmine - ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] + + ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.lib_dir}/jasmine*.js").first)] + ['/lib/json2.js', '/lib/TrivialReporter.js'] end - def self.jasmine_root + def self.root File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine')) end - def self.rails_root - if defined? RAILS_ROOT - RAILS_ROOT - else - ENV['RAILS_ROOT'] - end - end - - def self.jasmine_spec_dir - if rails_root - File.expand_path(File.join(rails_root, "spec", "javascript")) - else - File.expand_path('spec') - end + def self.spec_dir + File.expand_path('spec/javascripts') end def self.spec_files - Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js")) + Dir.glob(File.join(spec_dir, "**/*[Ss]pec.js")) end def self.specs - spec_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")} + spec_files.collect {|f| f.sub(spec_dir, "/spec")} end def self.spec_helpers_files - Dir.glob(File.join(jasmine_spec_dir, "helpers/**/*.js")) + Dir.glob(File.join(spec_dir, "helpers/**/*.js")) end def self.spec_helpers - spec_helpers_files.collect {|f| f.sub(jasmine_spec_dir, "/spec")} + spec_helpers_files.collect {|f| f.sub(spec_dir, "/spec")} end def self.dir_mappings { - "/spec" => jasmine_spec_dir, - "/lib" => jasmine_lib_dir + "/spec" => spec_dir, + "/lib" => lib_dir } end + + def self.meta_spec_path + File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine-ruby', 'jasmine_meta_spec.rb')) + end + end diff --git a/lib/jasmine-ruby/jasmine_meta_spec.rb b/lib/jasmine-ruby/jasmine_meta_spec.rb new file mode 100644 index 0000000..6afa1b9 --- /dev/null +++ b/lib/jasmine-ruby/jasmine_meta_spec.rb @@ -0,0 +1,22 @@ +require 'rubygems' +require "selenium_rc" +require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb")) +require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder")) + +jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, + JasmineHelper.specs, + JasmineHelper.dir_mappings) + +spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.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 \ No newline at end of file diff --git a/spec/jasmine_spec.rb b/spec/jasmine_spec.rb index 4d50565..5f652fb 100644 --- a/spec/jasmine_spec.rb +++ b/spec/jasmine_spec.rb @@ -4,7 +4,7 @@ require "selenium_rc" JASMINE_SPEC_DIR = File.join(File.dirname(__FILE__), "..", "jasmine", "spec") require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "jasmine-ruby", "jasmine_helper.rb")) -require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) +require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder")) jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, JasmineHelper.spec_file_urls, diff --git a/tasks/jasmine.rake b/tasks/jasmine.rake index ee32de4..8ba1462 100644 --- a/tasks/jasmine.rake +++ b/tasks/jasmine.rake @@ -1,7 +1,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "jasmine_helper.rb")) def start_jasmine_server - require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder")) + require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder")) puts "your tests are here:" puts " http://localhost:8888/run.html" diff --git a/templates/Rakefile b/templates/Rakefile new file mode 100644 index 0000000..3fbc551 --- /dev/null +++ b/templates/Rakefile @@ -0,0 +1,27 @@ +namespace :jasmine do + require 'jasmine-ruby' + helper_overrides = File.expand_path(File.join(File.dirname(__FILE__), "spec/javascripts/jasmine_helper.rb")) + if File.exist?(helper_overrides) + require helper_overrides + end + require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spec_builder")) + + desc "Run continuous integration tests" + require "spec" + require 'spec/rake/spectask' + Spec::Rake::SpecTask.new(:ci) do |t| + t.spec_opts = ["--color", "--format", "specdoc"] + t.spec_files = [JasmineHelper.meta_spec_path] + end + task :server do + puts "your tests are here:" + puts " http://localhost:8888/run.html" + + Jasmine::SimpleServer.start(8888, + lambda { JasmineHelper.specs }, + JasmineHelper.dir_mappings) + end +end + +desc "Run specs via server" +task :jasmine => ['jasmine:server']