diff --git a/bin/jasmine b/bin/jasmine index 92815ee..f3a23a4 100755 --- a/bin/jasmine +++ b/bin/jasmine @@ -17,11 +17,24 @@ end if ARGV[0] == 'init' require 'ftools' 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') + File.makedirs('spec/helpers') + + 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') + + 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) + + 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| @@ -29,7 +42,7 @@ if ARGV[0] == 'init' end end else - File.copy(rakefile_path, Dir.pwd) + File.copy(rakefile_path, dest_root) end end diff --git a/jasmine-ruby.gemspec b/jasmine-ruby.gemspec index 9cdec64..f15ddc6 100644 --- a/jasmine-ruby.gemspec +++ b/jasmine-ruby.gemspec @@ -32,6 +32,8 @@ Gem::Specification.new do |s| "lib/jasmine-ruby.rb", "tasks/jasmine.rake", "templates/example_spec.js", + "templates/spec_helper.js", + "templates/jasmine_helper.rb", "templates/Rakefile" ] s.homepage = %q{http://github.com/ragaskar/jasmine-ruby} diff --git a/lib/jasmine-ruby/jasmine_helper.rb b/lib/jasmine-ruby/jasmine_helper.rb index cdaf6cc..0fddcdc 100755 --- a/lib/jasmine-ruby/jasmine_helper.rb +++ b/lib/jasmine-ruby/jasmine_helper.rb @@ -14,11 +14,11 @@ class JasmineHelper end def self.spec_dir - File.expand_path('spec/javascripts') + File.expand_path('spec') end def self.spec_files - Dir.glob(File.join(spec_dir, "**/*[Ss]pec.js")) + Dir.glob(File.join(spec_dir, "javascripts/**/*[Ss]pec.js")) end def self.specs @@ -41,7 +41,15 @@ class JasmineHelper end def self.meta_spec_path - File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine-ruby', 'jasmine_meta_spec.rb')) + File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'jasmine-ruby', 'jasmine_meta_spec.rb')) + end + + def self.files + [] + end + + def self.stylesheets + [] end end diff --git a/lib/jasmine-ruby/jasmine_meta_spec.rb b/lib/jasmine-ruby/jasmine_meta_spec.rb index 6afa1b9..79436d0 100644 --- a/lib/jasmine-ruby/jasmine_meta_spec.rb +++ b/lib/jasmine-ruby/jasmine_meta_spec.rb @@ -5,7 +5,10 @@ require File.expand_path(File.join(JasmineHelper.root, "contrib/ruby/jasmine_spe jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path, JasmineHelper.specs, - JasmineHelper.dir_mappings) + JasmineHelper.dir_mappings, + { :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers, + :stylesheets => JasmineHelper.stylesheets + }) spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.spec_files, jasmine_runner) diff --git a/templates/Rakefile b/templates/Rakefile index 3fbc551..73608cc 100644 --- a/templates/Rakefile +++ b/templates/Rakefile @@ -1,6 +1,6 @@ namespace :jasmine do require 'jasmine-ruby' - helper_overrides = File.expand_path(File.join(File.dirname(__FILE__), "spec/javascripts/jasmine_helper.rb")) + helper_overrides = File.expand_path(File.join(File.dirname(__FILE__), "spec/helpers/jasmine_helper.rb")) if File.exist?(helper_overrides) require helper_overrides end @@ -19,7 +19,10 @@ namespace :jasmine do Jasmine::SimpleServer.start(8888, lambda { JasmineHelper.specs }, - JasmineHelper.dir_mappings) + JasmineHelper.dir_mappings, + { :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers, + :stylesheets => JasmineHelper.stylesheets + }) end end diff --git a/templates/jasmine_helper.rb b/templates/jasmine_helper.rb new file mode 100644 index 0000000..09c6ac8 --- /dev/null +++ b/templates/jasmine_helper.rb @@ -0,0 +1,12 @@ +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 diff --git a/templates/spec_helper.js b/templates/spec_helper.js new file mode 100644 index 0000000..3b6d023 --- /dev/null +++ b/templates/spec_helper.js @@ -0,0 +1 @@ +//You may load required files here, or create test-runner-wide environment settings. \ No newline at end of file