Rename sources.yaml to jasmine.yaml. Add stylesheets support to jasmine yaml. Allow dir glob strings in jasmine.yaml file enumerations
This commit is contained in:
parent
0b02e82229
commit
95a6085a01
@ -37,9 +37,9 @@ if ARGV[0] == 'init'
|
||||
rails_tasks_dir = dest_path('lib/tasks')
|
||||
if File.exist?(rails_tasks_dir)
|
||||
copy_unless_exists('lib/tasks/jasmine.rake')
|
||||
copy_unless_exists('spec/javascripts/support/sources-rails.yaml', 'spec/javascripts/support/sources.yaml')
|
||||
copy_unless_exists('spec/javascripts/support/jasmine-rails.yaml', 'spec/javascripts/support/jasmine.yaml')
|
||||
else
|
||||
copy_unless_exists('spec/javascripts/support/sources.yaml')
|
||||
copy_unless_exists('spec/javascripts/support/jasmine.yaml')
|
||||
write_mode = 'w'
|
||||
if File.exist?(dest_path('Rakefile'))
|
||||
load dest_path('Rakefile')
|
||||
|
@ -9,7 +9,7 @@ class JasmineGenerator < Rails::Generator::Base
|
||||
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.file "spec/javascripts/support/jasmine-rails.yaml", "spec/javascripts/support/jasmine.yaml"
|
||||
|
||||
m.directory "lib/tasks"
|
||||
m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake"
|
||||
|
@ -1,8 +1,10 @@
|
||||
sources:
|
||||
src_files:
|
||||
- javascripts/prototype.js
|
||||
- javascripts/effects.js
|
||||
- javascripts/controls.js
|
||||
- javascripts/dragdrop.js
|
||||
- javascripts/application.js
|
||||
spec_files:
|
||||
- **/*.js
|
||||
src_dir: public
|
||||
spec_dir: spec/javascripts
|
||||
spec_dir: spec/javascripts
|
@ -0,0 +1,10 @@
|
||||
#src_files:
|
||||
# - lib/source1.js
|
||||
# - lib/source2.js
|
||||
# - dist/**/*.js
|
||||
#stylesheets:
|
||||
# - css/style.css
|
||||
#spec_files:
|
||||
# -
|
||||
#src_dir:
|
||||
#spec_dir: spec/javascripts
|
@ -2,22 +2,58 @@ 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")
|
||||
# def project_root
|
||||
# Dir.pwd
|
||||
# end
|
||||
|
||||
# Path to your JavaScript source files
|
||||
# Path to your jasmine.yaml
|
||||
# def simple_config_file
|
||||
# File.join(project_root, 'spec/javascripts/support/jasmine.yaml')
|
||||
# end
|
||||
|
||||
# Source directory path. Your src_files must be returned relative to this path.
|
||||
# def src_dir
|
||||
# File.join(project_root, "public")
|
||||
# if simple_config['src_dir']
|
||||
# File.join(project_root, simple_config['src_dir'])
|
||||
# else
|
||||
# project_root
|
||||
# end
|
||||
# end
|
||||
|
||||
# Path to your JavaScript specs
|
||||
# Spec directory path. Your spec_files must be returned relative to this path.
|
||||
# def spec_dir
|
||||
# File.join(project_root, 'spec/javascripts')
|
||||
# if simple_config['spec_dir']
|
||||
# File.join(project_root, simple_config['spec_dir'])
|
||||
# else
|
||||
# File.join(project_root, 'spec/javascripts')
|
||||
# end
|
||||
# end
|
||||
|
||||
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
||||
# def src_files
|
||||
# files = []
|
||||
# if simple_config['src_files']
|
||||
# files = simple_config['src_files'].collect {|filepath| Dir.glob(filepath)}
|
||||
# end
|
||||
# files
|
||||
# end
|
||||
|
||||
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
||||
# def spec_files
|
||||
# files = match_files(spec_dir, "**/*.js")
|
||||
# if simple_config['spec_files']
|
||||
# files = simple_config['spec_files'].collect {|filepath| Dir.glob(filepath)}
|
||||
# end
|
||||
# files
|
||||
# end
|
||||
|
||||
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
||||
# def stylesheets
|
||||
# files = []
|
||||
# if simple_config['stylesheets']
|
||||
# files = simple_config['stylesheets'].collect {|filepath| Dir.glob(filepath)}
|
||||
# end
|
||||
# files
|
||||
# end
|
||||
|
||||
end
|
||||
|
@ -1,5 +0,0 @@
|
||||
#sources:
|
||||
# - lib/source1.js
|
||||
# - lib/source2.js
|
||||
#src_dir:
|
||||
#spec_dir: spec/javascripts
|
@ -23,10 +23,10 @@ Gem::Specification.new do |s|
|
||||
"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-rails.yaml",
|
||||
"generators/jasmine/templates/spec/javascripts/support/jasmine.yaml",
|
||||
"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",
|
||||
|
@ -71,37 +71,11 @@ module Jasmine
|
||||
@client.eval_js(script)
|
||||
end
|
||||
|
||||
def stylesheets
|
||||
[]
|
||||
end
|
||||
|
||||
def src_files
|
||||
[]
|
||||
end
|
||||
|
||||
def spec_files
|
||||
raise "You need to declare a spec_files method in #{self.class}!"
|
||||
end
|
||||
|
||||
def match_files(dir, pattern)
|
||||
def match_files(dir, patterns)
|
||||
dir = File.expand_path(dir)
|
||||
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')
|
||||
patterns.collect do |pattern|
|
||||
Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
|
||||
end.flatten
|
||||
end
|
||||
|
||||
def simple_config
|
||||
@ -109,21 +83,6 @@ module Jasmine
|
||||
config || {}
|
||||
end
|
||||
|
||||
def src_files
|
||||
simple_config['sources'] || []
|
||||
end
|
||||
|
||||
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__"
|
||||
@ -144,8 +103,61 @@ module Jasmine
|
||||
src_files.collect {|f| "/" + f } + spec_files.collect {|f| File.join(spec_path, f) }
|
||||
end
|
||||
|
||||
def css_files
|
||||
stylesheets.collect {|f| "/" + f }
|
||||
end
|
||||
|
||||
def spec_files_full_paths
|
||||
spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
|
||||
end
|
||||
|
||||
def project_root
|
||||
Dir.pwd
|
||||
end
|
||||
|
||||
def simple_config_file
|
||||
File.join(project_root, 'spec/javascripts/support/jasmine.yaml')
|
||||
end
|
||||
|
||||
def src_dir
|
||||
if simple_config['src_dir']
|
||||
File.join(project_root, simple_config['src_dir'])
|
||||
else
|
||||
project_root
|
||||
end
|
||||
end
|
||||
|
||||
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 src_files
|
||||
files = []
|
||||
if simple_config['src_files']
|
||||
files = match_files(src_dir, simple_config['src_files'])
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
def spec_files
|
||||
files = match_files(spec_dir, "**/*.js")
|
||||
if simple_config['spec_files']
|
||||
files = match_files(spec_dir, simple_config['spec_files'])
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
def stylesheets
|
||||
files = []
|
||||
if simple_config['stylesheets']
|
||||
files = match_files(src_dir, simple_config['stylesheets'])
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -18,7 +18,7 @@ module Jasmine
|
||||
#noinspection RubyUnusedLocalVariable
|
||||
def run
|
||||
jasmine_files = @jasmine_files
|
||||
css_files = @jasmine_stylesheets + (@config.stylesheets || [])
|
||||
css_files = @jasmine_stylesheets + (@config.css_files || [])
|
||||
js_files = @config.js_files
|
||||
|
||||
body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html.erb"))).result(binding)
|
||||
|
@ -12,6 +12,7 @@ describe Jasmine::Config do
|
||||
it "if sources.yaml not found" do
|
||||
File.stub!(:exist?).and_return(false)
|
||||
@config.src_files.should == []
|
||||
@config.stylesheets.should == []
|
||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||
@config.mappings.should == {
|
||||
'/__root__' => @config.project_root,
|
||||
@ -20,8 +21,10 @@ describe Jasmine::Config do
|
||||
end
|
||||
|
||||
it "if sources.yaml is empty" do
|
||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
|
||||
YAML.stub!(:load).and_return(false)
|
||||
@config.src_files.should == []
|
||||
@config.stylesheets.should == []
|
||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||
@config.mappings.should == {
|
||||
'/__root__' => @config.project_root,
|
||||
@ -29,8 +32,8 @@ describe Jasmine::Config do
|
||||
}
|
||||
end
|
||||
|
||||
it "using default sources.yaml" do
|
||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources.yaml'))
|
||||
it "using default jasmine.yaml" do
|
||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
|
||||
@config.src_files.should == []
|
||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||
@config.mappings.should == {
|
||||
@ -39,14 +42,31 @@ describe Jasmine::Config do
|
||||
}
|
||||
end
|
||||
|
||||
it "using rails sources.yaml" do
|
||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources-rails.yaml'))
|
||||
it "simple_config stylesheets" do
|
||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
|
||||
YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
|
||||
Dir.stub!(:glob).and_return do |glob_string|
|
||||
glob_string
|
||||
end
|
||||
@config.stylesheets.should == ['foo.css', 'bar.css']
|
||||
end
|
||||
|
||||
it "using rails jasmine.yaml" do
|
||||
original_glob = Dir.method(:glob)
|
||||
Dir.stub!(:glob).and_return do |glob_string|
|
||||
if glob_string =~ /public/
|
||||
glob_string
|
||||
else
|
||||
original_glob.call(glob_string)
|
||||
end
|
||||
end
|
||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yaml'))
|
||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||
@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',
|
||||
|
Loading…
Reference in New Issue
Block a user