From 53305edc689dea34c227336b08fa8e3e6038e3a5 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Tue, 26 Jan 2010 07:55:04 -0800 Subject: [PATCH] Add rails generators. Add sources.yaml support. Fix Prototype.js collision on jasmine:ci. Version bump to 0.4.0. --- VERSION.yml | 6 +- bin/jasmine | 59 ++++++------ generators/jasmine/jasmine_generator.rb | 25 +++++ generators/jasmine/templates/INSTALL | 9 ++ .../jasmine/templates/lib/tasks/jasmine.rake | 23 +++++ .../spec/javascripts}/ExampleSpec.js | 0 .../templates/spec/javascripts}/SpecHelper.js | 0 .../javascripts/support/jasmine_config.rb | 23 +++++ .../spec/javascripts/support/jasmine_spec.rb | 17 ++++ .../javascripts/support/sources-rails.yaml | 8 ++ .../spec/javascripts/support/sources.yaml | 5 + jasmine.gemspec | 22 +++-- lib/jasmine.rb | 1 - lib/jasmine/config.rb | 51 ++++++++-- lib/jasmine/jasmine_helper.rb | 48 ---------- lib/jasmine/jasmine_meta_spec.rb | 30 ------ lib/jasmine/selenium_driver.rb | 4 +- lib/jasmine/server.rb | 3 +- lib/jasmine/spec_builder.rb | 5 +- spec/config_spec.rb | 96 ++++++++++++------- spec/jasmine_self_test_config.rb | 6 +- templates/Rakefile | 30 ------ templates/public/javascripts/Example.js | 2 - templates/spec/jasmine_helper.rb | 12 --- 24 files changed, 267 insertions(+), 218 deletions(-) create mode 100644 generators/jasmine/jasmine_generator.rb create mode 100644 generators/jasmine/templates/INSTALL create mode 100644 generators/jasmine/templates/lib/tasks/jasmine.rake rename {templates/spec/javascript => generators/jasmine/templates/spec/javascripts}/ExampleSpec.js (100%) rename {templates/spec/javascript => generators/jasmine/templates/spec/javascripts}/SpecHelper.js (100%) create mode 100644 generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb create mode 100644 generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb create mode 100644 generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml create mode 100644 generators/jasmine/templates/spec/javascripts/support/sources.yaml delete mode 100755 lib/jasmine/jasmine_helper.rb delete mode 100644 lib/jasmine/jasmine_meta_spec.rb delete mode 100644 templates/Rakefile delete mode 100644 templates/public/javascripts/Example.js delete mode 100644 templates/spec/jasmine_helper.rb diff --git a/VERSION.yml b/VERSION.yml index 948bf8d..3e8ae89 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ --- -:minor: 1 -:build: -:patch: 3 +:patch: 0 :major: 0 +:build: +:minor: 4 diff --git a/bin/jasmine b/bin/jasmine index f098671..63e5f8b 100755 --- a/bin/jasmine +++ b/bin/jasmine @@ -10,45 +10,46 @@ def expand(*paths) File.expand_path(File.join(*paths)) end -def rakefile_path - expand(cwd, 'templates/Rakefile') +def template_path(filepath) + expand(cwd, File.join("generators/jasmine/templates", filepath)) +end + +def dest_path(filepath) + expand(Dir.pwd, filepath) +end + +def copy_unless_exists(relative_path, dest_path = nil) + unless File.exist?(dest_path(relative_path)) + File.copy(template_path(relative_path), dest_path(dest_path || relative_path)) + end end if ARGV[0] == 'init' require 'ftools' File.makedirs('spec/javascripts') - File.makedirs('spec/helpers') + File.makedirs('spec/javascripts/support') - dest_root = File.expand_path(Dir.pwd) - dest_spec = expand(dest_root, 'spec') - dest_spec_javascripts = expand(dest_root, 'spec/javascripts') - dest_spec_helpers = expand(dest_root, 'spec/helpers') + copy_unless_exists('spec/javascripts/SpecHelper.js') + copy_unless_exists('spec/javascripts/ExampleSpec.js') + copy_unless_exists('spec/javascripts/support/jasmine_config.rb') + copy_unless_exists('spec/javascripts/support/jasmine_spec.rb') - unless File.exist?(expand(dest_spec_helpers, 'spec_helper.js')) - File.copy(expand(cwd, 'templates/spec_helper.js'), dest_spec_helpers) - end - unless File.exist?(expand(dest_spec_helpers, 'jasmine_helper.rb')) - File.copy(expand(cwd, 'templates/jasmine_helper.rb'), dest_spec_helpers) - end - - File.copy(expand(cwd, 'templates/example_spec.js'), dest_spec_javascripts) - - rails_tasks_dir = expand(dest_root, 'lib', 'tasks') + rails_tasks_dir = dest_path('lib/tasks') if File.exist?(rails_tasks_dir) - File.makedirs('lib/tasks/jasmine') - File.copy(rakefile_path, File.join(rails_tasks_dir, 'jasmine/jasmine.rake')) + copy_unless_exists('lib/tasks/jasmine.rake') + copy_unless_exists('spec/javascripts/support/sources-rails.yaml', 'spec/javascripts/support/sources.yaml') else - if File.exist?(expand(dest_root, 'Rakefile')) - existing_rakefile = expand(dest_root, '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, dest_root) + copy_unless_exists('spec/javascripts/support/sources.yaml') + if File.exist?(dest_path('Rakefile')) + load dest_path('Rakefile') end + write_mode = Rake::Task.task_defined?('jasmine') ? 'a' : 'w' + File.open(dest_path('Rakefile'), write_mode) do |f| + f.write(File.read(template_path('lib/tasks/jasmine.rake'))) + end + end + File.open(template_path('INSTALL'), 'r').each_line do |line| + puts line end end diff --git a/generators/jasmine/jasmine_generator.rb b/generators/jasmine/jasmine_generator.rb new file mode 100644 index 0000000..755b122 --- /dev/null +++ b/generators/jasmine/jasmine_generator.rb @@ -0,0 +1,25 @@ +class JasmineGenerator < Rails::Generator::Base + def manifest + record do |m| + + m.directory "spec/javascripts" + m.file "spec/javascripts/SpecHelper.js", "spec/javascripts/SpecHelper.js" + m.file "spec/javascripts/ExampleSpec.js", "spec/javascripts/ExampleSpec.js" + + m.directory "spec/javascripts/support" + m.file "spec/javascripts/support/jasmine_config.rb", "spec/javascripts/support/jasmine_config.rb" + m.file "spec/javascripts/support/jasmine_spec.rb", "spec/javascripts/support/jasmine_spec.rb" + m.file "spec/javascripts/support/sources-rails.yaml", "spec/javascripts/support/sources.yaml" + + m.directory "lib/tasks" + m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake" + + m.readme "INSTALL" + end + end + + def file_name + "create_blog" + end + +end \ No newline at end of file diff --git a/generators/jasmine/templates/INSTALL b/generators/jasmine/templates/INSTALL new file mode 100644 index 0000000..a39059b --- /dev/null +++ b/generators/jasmine/templates/INSTALL @@ -0,0 +1,9 @@ +Jasmine has been installed with example specs. + +To run the server: + +rake jasmine + +To run the automated CI task with Selenium: + +rake jasmine:ci \ No newline at end of file diff --git a/generators/jasmine/templates/lib/tasks/jasmine.rake b/generators/jasmine/templates/lib/tasks/jasmine.rake new file mode 100644 index 0000000..9dee07a --- /dev/null +++ b/generators/jasmine/templates/lib/tasks/jasmine.rake @@ -0,0 +1,23 @@ +namespace :jasmine do + require 'jasmine' + + 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.verbose = true + t.spec_files = ['spec/javascripts/support/jasmine_spec.rb'] + end + task :server do + require 'spec/javascripts/support/jasmine_config' + + puts "your tests are here:" + puts " http://localhost:8888/run.html" + + Jasmine::Config.new.start_server + end +end + +desc "Run specs via server" +task :jasmine => ['jasmine:server'] diff --git a/templates/spec/javascript/ExampleSpec.js b/generators/jasmine/templates/spec/javascripts/ExampleSpec.js similarity index 100% rename from templates/spec/javascript/ExampleSpec.js rename to generators/jasmine/templates/spec/javascripts/ExampleSpec.js diff --git a/templates/spec/javascript/SpecHelper.js b/generators/jasmine/templates/spec/javascripts/SpecHelper.js similarity index 100% rename from templates/spec/javascript/SpecHelper.js rename to generators/jasmine/templates/spec/javascripts/SpecHelper.js diff --git a/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb b/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb new file mode 100644 index 0000000..633b2e0 --- /dev/null +++ b/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb @@ -0,0 +1,23 @@ +require 'jasmine' + +class Jasmine::Config + + def project_root + File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..")) + end + +# Return an array of files to include before jasmine specs. Override if needed. +# def src_files +# match_files(src_dir, "**/*.js") +# end + +# Path to your JavaScript source files +# def src_dir +# File.join(project_root, "public") +# end + +# Path to your JavaScript specs +# def spec_dir +# File.join(project_root, 'spec/javascripts') +# end +end diff --git a/generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb b/generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb new file mode 100644 index 0000000..7207e6a --- /dev/null +++ b/generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb @@ -0,0 +1,17 @@ +require 'rubygems' +require File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config')) + +jasmine_config = Jasmine::Config.new +spec_builder = Jasmine::SpecBuilder.new(jasmine_config) + +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/generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml b/generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml new file mode 100644 index 0000000..e43b817 --- /dev/null +++ b/generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml @@ -0,0 +1,8 @@ +sources: + - javascripts/prototype.js + - javascripts/effects.js + - javascripts/controls.js + - javascripts/dragdrop.js + - javascripts/application.js +src_dir: public +spec_dir: spec/javascripts \ No newline at end of file diff --git a/generators/jasmine/templates/spec/javascripts/support/sources.yaml b/generators/jasmine/templates/spec/javascripts/support/sources.yaml new file mode 100644 index 0000000..9ffe511 --- /dev/null +++ b/generators/jasmine/templates/spec/javascripts/support/sources.yaml @@ -0,0 +1,5 @@ +#sources: +# - lib/source1.js +# - lib/source2.js +#src_dir: +#spec_dir: spec/javascripts \ No newline at end of file diff --git a/jasmine.gemspec b/jasmine.gemspec index ee73fe4..c432a53 100644 --- a/jasmine.gemspec +++ b/jasmine.gemspec @@ -5,19 +5,28 @@ Gem::Specification.new do |s| s.name = %q{jasmine} - s.version = "0.1.3" + s.version = "0.4.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Rajan Agaskar", "Christian Williams"] - s.date = %q{2009-12-31} + s.date = %q{2010-01-26} + s.default_executable = %q{jasmine} s.description = %q{Javascript BDD test framework} s.email = %q{ragaskar@gmail.com} - s.executables = ["autospec", "edit_json.rb", "jasmine", "jeweler", "prettify_json.rb", "rackup", "rake", "rubyforge", "selenium-rc", "spec", "thin"] + s.executables = ["jasmine"] s.extra_rdoc_files = [ "README.markdown" ] s.files = [ - "bin/jasmine", + "generators/jasmine/jasmine_generator.rb", + "generators/jasmine/templates/INSTALL", + "generators/jasmine/templates/lib/tasks/jasmine.rake", + "generators/jasmine/templates/spec/javascripts/ExampleSpec.js", + "generators/jasmine/templates/spec/javascripts/SpecHelper.js", + "generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb", + "generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb", + "generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml", + "generators/jasmine/templates/spec/javascripts/support/sources.yaml", "jasmine/contrib/ruby/jasmine_runner.rb", "jasmine/contrib/ruby/jasmine_spec_builder.rb", "jasmine/contrib/ruby/run.html", @@ -29,13 +38,10 @@ Gem::Specification.new do |s| "lib/jasmine.rb", "lib/jasmine/base.rb", "lib/jasmine/config.rb", - "lib/jasmine/jasmine_helper.rb", - "lib/jasmine/jasmine_meta_spec.rb", "lib/jasmine/run.html.erb", "lib/jasmine/selenium_driver.rb", "lib/jasmine/server.rb", - "lib/jasmine/spec_builder.rb", - "templates/Rakefile" + "lib/jasmine/spec_builder.rb" ] s.homepage = %q{http://github.com/pivotal/jasmine-ruby} s.rdoc_options = ["--charset=UTF-8"] diff --git a/lib/jasmine.rb b/lib/jasmine.rb index a4c01aa..95f803f 100644 --- a/lib/jasmine.rb +++ b/lib/jasmine.rb @@ -3,5 +3,4 @@ require 'jasmine/config' require 'jasmine/server' require 'jasmine/selenium_driver' -require 'jasmine/jasmine_helper' require 'jasmine/spec_builder' \ No newline at end of file diff --git a/lib/jasmine/config.rb b/lib/jasmine/config.rb index 10b48ba..655a229 100644 --- a/lib/jasmine/config.rb +++ b/lib/jasmine/config.rb @@ -1,5 +1,7 @@ module Jasmine class Config + require 'yaml' + def initialize(options = {}) require 'selenium_rc' @selenium_jar_path = SeleniumRC::Server.allocate.jar_path @@ -86,31 +88,60 @@ module Jasmine Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort end + def project_root + Dir.pwd + end + + def src_dir + if simple_config['src_dir'] + File.join(project_root, simple_config['src_dir']) + else + project_root + end + end + + def simple_config_file + File.join(project_root, 'spec/javascripts/support/sources.yaml') + end + + def simple_config + config = File.exist?(simple_config_file) ? File.open(simple_config_file) { |yf| YAML::load( yf ) } : false + config || {} + end + def src_files - match_files(src_dir, "**/*.js") + simple_config['sources'] || [] end - def src_path - "src" - end - - def spec_path - "spec" + def spec_dir + if simple_config['spec_dir'] + File.join(project_root, simple_config['spec_dir']) + else + File.join(project_root, 'spec/javascripts') + end end def spec_files match_files(spec_dir, "**/*.js") end + def spec_path + "/__spec__" + end + + def root_path + "/__root__" + end + def mappings { - "/" + src_path => src_dir, - "/" + spec_path => spec_dir + spec_path => spec_dir, + root_path => project_root } end def js_files - src_files.collect {|f| "/" + File.join(src_path, f) } + spec_files.collect {|f| "/" + File.join(spec_path, f) } + src_files.collect {|f| "/" + f } + spec_files.collect {|f| File.join(spec_path, f) } end def spec_files_full_paths diff --git a/lib/jasmine/jasmine_helper.rb b/lib/jasmine/jasmine_helper.rb deleted file mode 100755 index a2c7b1d..0000000 --- a/lib/jasmine/jasmine_helper.rb +++ /dev/null @@ -1,48 +0,0 @@ -class JasmineHelper - def self.lib_dir - File.expand_path(File.join(root, 'lib')) - end - - def self.jasmine - ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.lib_dir}/jasmine*.js").first)] + - ['/lib/json2.js', - '/lib/TrivialReporter.js'] - end - - def self.root - File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'jasmine')) - end - - def self.spec_dir - File.expand_path('spec') - end - - def self.spec_files - Dir.glob(File.join(spec_dir, "javascripts/**/*[Ss]pec.js")) - end - - def self.specs - spec_files.collect {|f| f.sub(spec_dir, "/spec")} - end - - def self.spec_helpers_files - Dir.glob(File.join(spec_dir, "helpers/**/*.js")) - end - - def self.spec_helpers - spec_helpers_files.collect {|f| f.sub(spec_dir, "/spec")} - end - - def self.meta_spec_path - File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine', 'jasmine_meta_spec.rb')) - end - - def self.files - [] - end - - def self.stylesheets - [] - end - -end diff --git a/lib/jasmine/jasmine_meta_spec.rb b/lib/jasmine/jasmine_meta_spec.rb deleted file mode 100644 index 3dd0e01..0000000 --- a/lib/jasmine/jasmine_meta_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rubygems' -require "selenium_rc" -require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb")) -helper_overrides = File.expand_path(File.join(Dir.pwd, "spec", "helpers", "jasmine_helper.rb")) -if File.exist?(helper_overrides) - require helper_overrides -end -require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_runner.rb")) -require File.expand_path(File.join(File.dirname(__FILE__), "spec_builder")) - -jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, - Dir.pwd, - JasmineHelper.specs, - { :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers, - :stylesheets => JasmineHelper.stylesheets - }) - -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/lib/jasmine/selenium_driver.rb b/lib/jasmine/selenium_driver.rb index 7f9bac8..ff15d01 100644 --- a/lib/jasmine/selenium_driver.rb +++ b/lib/jasmine/selenium_driver.rb @@ -37,8 +37,8 @@ module Jasmine def eval_js(script) escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'" - result = @driver.get_eval(" try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }") - JSON.parse("[#{result}]")[0] + result = @driver.get_eval("try { eval(#{escaped_script}, window); } catch(err) { window.eval(#{escaped_script}); }") + JSON.parse("{\"result\":#{result}}")["result"] end end end \ No newline at end of file diff --git a/lib/jasmine/server.rb b/lib/jasmine/server.rb index 90918fb..93480e9 100644 --- a/lib/jasmine/server.rb +++ b/lib/jasmine/server.rb @@ -82,7 +82,7 @@ module Jasmine class Server attr_reader :thin - + def initialize(port, config) @port = port @config = config @@ -101,6 +101,7 @@ module Jasmine thin_config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root) app = Rack::Cascade.new([ + Rack::URLMap.new({'/' => Rack::File.new(@config.src_dir)}), Rack::URLMap.new(thin_config), JsAlert.new ]) diff --git a/lib/jasmine/spec_builder.rb b/lib/jasmine/spec_builder.rb index 352845e..d979cb0 100644 --- a/lib/jasmine/spec_builder.rb +++ b/lib/jasmine/spec_builder.rb @@ -58,7 +58,7 @@ module Jasmine sleep 0.1 end - @suites = eval_js('JSON.stringify(jsApiReporter.suites())') + @suites = eval_js("var result = jsApiReporter.suites(); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }") end def results_for(spec_id) @@ -69,7 +69,7 @@ module Jasmine def load_results @spec_results = {} @spec_ids.each_slice(50) do |slice| - @spec_results.merge!(eval_js("JSON.stringify(jsApiReporter.resultsForSpecs(#{JSON.generate(slice)}))")) + @spec_results.merge!(eval_js("var result = jsApiReporter.resultsForSpecs(#{JSON.generate(slice)}); if (window.Prototype && Object.toJSON) { Object.toJSON(result) } else { JSON.stringify(result) }")) end @spec_results end @@ -116,7 +116,6 @@ module Jasmine def report_spec(spec_id) spec_results = results_for(spec_id) - out = "" messages = spec_results['messages'].each do |message| case diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 3a8b657..997c8e1 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -2,52 +2,76 @@ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) describe Jasmine::Config do before(:each) do - @template_dir = File.expand_path(File.join(File.dirname(__FILE__), "../templates")) + @template_dir = File.expand_path(File.join(File.dirname(__FILE__), "../generators/jasmine/templates")) @config = Jasmine::Config.new @config.stub!(:src_dir).and_return(File.join(@template_dir, "public")) @config.stub!(:spec_dir).and_return(File.join(@template_dir, "spec")) end - it "should provide a list of all src and spec files" do - @config.src_files.should == ['javascripts/Example.js'] - @config.spec_files.should == ['javascript/ExampleSpec.js', 'javascript/SpecHelper.js'] + describe "simple_config" do + it "if sources.yaml not found" do + File.stub!(:exist?).and_return(false) + @config.src_files.should == [] + @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js'] + @config.mappings.should == { + '/__root__' => @config.project_root, + '/__spec__' => @config.spec_dir + } + end + + it "if sources.yaml is empty" do + YAML.stub!(:load).and_return(false) + @config.src_files.should == [] + @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js'] + @config.mappings.should == { + '/__root__' => @config.project_root, + '/__spec__' => @config.spec_dir + } + end + + it "using default sources.yaml" do + @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources.yaml')) + @config.src_files.should == [] + @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js'] + @config.mappings.should == { + '/__root__' => @config.project_root, + '/__spec__' => @config.spec_dir + } + end + + it "using rails sources.yaml" do + @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources-rails.yaml')) + @config.src_files.should == ['javascripts/prototype.js', + 'javascripts/effects.js', + 'javascripts/controls.js', + 'javascripts/dragdrop.js', + 'javascripts/application.js'] + @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js'] + @config.js_files.should == [ + '/javascripts/prototype.js', + '/javascripts/effects.js', + '/javascripts/controls.js', + '/javascripts/dragdrop.js', + '/javascripts/application.js', + '/__spec__/javascripts/ExampleSpec.js', + '/__spec__/javascripts/SpecHelper.js', + ] + end + end + + + it "should provide dir mappings" do + @config.mappings.should == { + '/__root__' => @config.project_root, + '/__spec__' => @config.spec_dir + } end it "should provide a list of all spec files with full paths" do @config.spec_files_full_paths.should == [ - File.join(@template_dir, 'spec/javascript/ExampleSpec.js'), - File.join(@template_dir, 'spec/javascript/SpecHelper.js') + File.join(@template_dir, 'spec/javascripts/ExampleSpec.js'), + File.join(@template_dir, 'spec/javascripts/SpecHelper.js') ] end - it "should provide a list of all js files" do - @config.js_files.should == [ - '/src/javascripts/Example.js', - '/spec/javascript/ExampleSpec.js', - '/spec/javascript/SpecHelper.js', - ] - end - - it "should provide dir mappings" do - @config.mappings.should == { - '/src' => @config.src_dir, - '/spec' => @config.spec_dir - } - end - - it "should allow overriding src and spec paths" do - @config.stub!(:src_path).and_return("public") - @config.stub!(:spec_path).and_return("spekz") - - @config.js_files.should == [ - '/public/javascripts/Example.js', - '/spekz/javascript/ExampleSpec.js', - '/spekz/javascript/SpecHelper.js', - ] - - @config.mappings.should == { - '/public' => @config.src_dir, - '/spekz' => @config.spec_dir - } - end end \ No newline at end of file diff --git a/spec/jasmine_self_test_config.rb b/spec/jasmine_self_test_config.rb index 2736157..622f985 100644 --- a/spec/jasmine_self_test_config.rb +++ b/spec/jasmine_self_test_config.rb @@ -1,15 +1,15 @@ require 'jasmine' class JasmineSelfTestConfig < Jasmine::Config - def proj_root + def project_root File.expand_path(File.join(File.dirname(__FILE__), "..")) end def src_dir - File.join(proj_root, 'src') + File.join(project_root, 'src') end def spec_dir - File.join(proj_root, 'jasmine/spec') + File.join(project_root, 'jasmine/spec') end end \ No newline at end of file diff --git a/templates/Rakefile b/templates/Rakefile deleted file mode 100644 index ce23bba..0000000 --- a/templates/Rakefile +++ /dev/null @@ -1,30 +0,0 @@ -namespace :jasmine do - require 'jasmine' - helper_overrides = File.expand_path(File.join(File.dirname(__FILE__), "spec/helpers/jasmine_helper.rb")) - if File.exist?(helper_overrides) - require helper_overrides - end - - 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.verbose = true - t.spec_files = [JasmineHelper.meta_spec_path] - end - task :server do - puts "your tests are here:" - puts " http://localhost:8888/run.html" - - Jasmine::Server.start(8888, - File.expand_path(Dir.pwd), - lambda { JasmineHelper.specs }, - { :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers, - :stylesheets => JasmineHelper.stylesheets - }) - end -end - -desc "Run specs via server" -task :jasmine => ['jasmine:server'] diff --git a/templates/public/javascripts/Example.js b/templates/public/javascripts/Example.js deleted file mode 100644 index 3fcc4e1..0000000 --- a/templates/public/javascripts/Example.js +++ /dev/null @@ -1,2 +0,0 @@ -ExampleClass = function() { -}; \ No newline at end of file diff --git a/templates/spec/jasmine_helper.rb b/templates/spec/jasmine_helper.rb deleted file mode 100644 index 09c6ac8..0000000 --- a/templates/spec/jasmine_helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -class JasmineHelper - def self.files - #return a list of files you want to load before your spec defintions load - [] - end - - def self.stylesheets - #return a list of stylesheets you want to load in the runner - [] - end - -end