Load spec_hhelpers before spec definitions

This commit is contained in:
ragaskar 2009-11-25 08:01:09 -08:00
parent 1c2780d0c1
commit e3585b79f0
7 changed files with 54 additions and 12 deletions

View File

@ -17,11 +17,24 @@ end
if ARGV[0] == 'init' if ARGV[0] == 'init'
require 'ftools' require 'ftools'
File.makedirs('spec/javascripts') File.makedirs('spec/javascripts')
dest_root = expand(Dir.pwd, 'spec') File.makedirs('spec/helpers')
dest_spec = expand(Dir.pwd, 'spec/javascripts')
File.copy(expand(cwd, 'templates/example_spec.js'), dest_spec) dest_root = File.expand_path(Dir.pwd)
if File.exist?(expand(Dir.pwd, 'Rakefile')) dest_spec = expand(dest_root, 'spec')
existing_rakefile = expand(Dir.pwd, 'Rakefile') 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 load existing_rakefile
unless Rake::Task.task_defined?('jasmine') unless Rake::Task.task_defined?('jasmine')
open(existing_rakefile, 'a') do |f| open(existing_rakefile, 'a') do |f|
@ -29,7 +42,7 @@ if ARGV[0] == 'init'
end end
end end
else else
File.copy(rakefile_path, Dir.pwd) File.copy(rakefile_path, dest_root)
end end
end end

View File

@ -32,6 +32,8 @@ Gem::Specification.new do |s|
"lib/jasmine-ruby.rb", "lib/jasmine-ruby.rb",
"tasks/jasmine.rake", "tasks/jasmine.rake",
"templates/example_spec.js", "templates/example_spec.js",
"templates/spec_helper.js",
"templates/jasmine_helper.rb",
"templates/Rakefile" "templates/Rakefile"
] ]
s.homepage = %q{http://github.com/ragaskar/jasmine-ruby} s.homepage = %q{http://github.com/ragaskar/jasmine-ruby}

View File

@ -14,11 +14,11 @@ class JasmineHelper
end end
def self.spec_dir def self.spec_dir
File.expand_path('spec/javascripts') File.expand_path('spec')
end end
def self.spec_files def self.spec_files
Dir.glob(File.join(spec_dir, "**/*[Ss]pec.js")) Dir.glob(File.join(spec_dir, "javascripts/**/*[Ss]pec.js"))
end end
def self.specs def self.specs
@ -41,7 +41,15 @@ class JasmineHelper
end end
def self.meta_spec_path 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
end end

View File

@ -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, jasmine_runner = Jasmine::Runner.new(SeleniumRC::Server.new.jar_path,
JasmineHelper.specs, 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) spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.spec_files, jasmine_runner)

View File

@ -1,6 +1,6 @@
namespace :jasmine do namespace :jasmine do
require 'jasmine-ruby' 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) if File.exist?(helper_overrides)
require helper_overrides require helper_overrides
end end
@ -19,7 +19,10 @@ namespace :jasmine do
Jasmine::SimpleServer.start(8888, Jasmine::SimpleServer.start(8888,
lambda { JasmineHelper.specs }, lambda { JasmineHelper.specs },
JasmineHelper.dir_mappings) JasmineHelper.dir_mappings,
{ :spec_helpers => JasmineHelper.files + JasmineHelper.spec_helpers,
:stylesheets => JasmineHelper.stylesheets
})
end end
end end

View File

@ -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

1
templates/spec_helper.js Normal file
View File

@ -0,0 +1 @@
//You may load required files here, or create test-runner-wide environment settings.