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')
|
rails_tasks_dir = dest_path('lib/tasks')
|
||||||
if File.exist?(rails_tasks_dir)
|
if File.exist?(rails_tasks_dir)
|
||||||
copy_unless_exists('lib/tasks/jasmine.rake')
|
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
|
else
|
||||||
copy_unless_exists('spec/javascripts/support/sources.yaml')
|
copy_unless_exists('spec/javascripts/support/jasmine.yaml')
|
||||||
write_mode = 'w'
|
write_mode = 'w'
|
||||||
if File.exist?(dest_path('Rakefile'))
|
if File.exist?(dest_path('Rakefile'))
|
||||||
load dest_path('Rakefile')
|
load dest_path('Rakefile')
|
||||||
|
@ -9,7 +9,7 @@ class JasmineGenerator < Rails::Generator::Base
|
|||||||
m.directory "spec/javascripts/support"
|
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_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/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.directory "lib/tasks"
|
||||||
m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake"
|
m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake"
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
sources:
|
src_files:
|
||||||
- javascripts/prototype.js
|
- javascripts/prototype.js
|
||||||
- javascripts/effects.js
|
- javascripts/effects.js
|
||||||
- javascripts/controls.js
|
- javascripts/controls.js
|
||||||
- javascripts/dragdrop.js
|
- javascripts/dragdrop.js
|
||||||
- javascripts/application.js
|
- javascripts/application.js
|
||||||
|
spec_files:
|
||||||
|
- **/*.js
|
||||||
src_dir: public
|
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
|
class Jasmine::Config
|
||||||
|
|
||||||
def project_root
|
# def project_root
|
||||||
File.expand_path(File.join(File.dirname(__FILE__), "..", "..", ".."))
|
# Dir.pwd
|
||||||
end
|
|
||||||
|
|
||||||
# Return an array of files to include before jasmine specs. Override if needed.
|
|
||||||
# def src_files
|
|
||||||
# match_files(src_dir, "**/*.js")
|
|
||||||
# end
|
# 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
|
# 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
|
# end
|
||||||
|
|
||||||
# Path to your JavaScript specs
|
# Spec directory path. Your spec_files must be returned relative to this path.
|
||||||
# def spec_dir
|
# 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
|
# 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
|
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/lib/tasks/jasmine.rake",
|
||||||
"generators/jasmine/templates/spec/javascripts/ExampleSpec.js",
|
"generators/jasmine/templates/spec/javascripts/ExampleSpec.js",
|
||||||
"generators/jasmine/templates/spec/javascripts/SpecHelper.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_config.rb",
|
||||||
"generators/jasmine/templates/spec/javascripts/support/jasmine_spec.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_runner.rb",
|
||||||
"jasmine/contrib/ruby/jasmine_spec_builder.rb",
|
"jasmine/contrib/ruby/jasmine_spec_builder.rb",
|
||||||
"jasmine/contrib/ruby/run.html",
|
"jasmine/contrib/ruby/run.html",
|
||||||
|
@ -71,37 +71,11 @@ module Jasmine
|
|||||||
@client.eval_js(script)
|
@client.eval_js(script)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheets
|
def match_files(dir, patterns)
|
||||||
[]
|
|
||||||
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)
|
|
||||||
dir = File.expand_path(dir)
|
dir = File.expand_path(dir)
|
||||||
Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
|
patterns.collect do |pattern|
|
||||||
end
|
Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
|
||||||
|
end.flatten
|
||||||
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
|
end
|
||||||
|
|
||||||
def simple_config
|
def simple_config
|
||||||
@ -109,21 +83,6 @@ module Jasmine
|
|||||||
config || {}
|
config || {}
|
||||||
end
|
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
|
def spec_path
|
||||||
"/__spec__"
|
"/__spec__"
|
||||||
@ -144,8 +103,61 @@ module Jasmine
|
|||||||
src_files.collect {|f| "/" + 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
|
end
|
||||||
|
|
||||||
|
def css_files
|
||||||
|
stylesheets.collect {|f| "/" + f }
|
||||||
|
end
|
||||||
|
|
||||||
def spec_files_full_paths
|
def spec_files_full_paths
|
||||||
spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
|
spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
|
||||||
end
|
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
|
||||||
end
|
end
|
@ -18,7 +18,7 @@ module Jasmine
|
|||||||
#noinspection RubyUnusedLocalVariable
|
#noinspection RubyUnusedLocalVariable
|
||||||
def run
|
def run
|
||||||
jasmine_files = @jasmine_files
|
jasmine_files = @jasmine_files
|
||||||
css_files = @jasmine_stylesheets + (@config.stylesheets || [])
|
css_files = @jasmine_stylesheets + (@config.css_files || [])
|
||||||
js_files = @config.js_files
|
js_files = @config.js_files
|
||||||
|
|
||||||
body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html.erb"))).result(binding)
|
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
|
it "if sources.yaml not found" do
|
||||||
File.stub!(:exist?).and_return(false)
|
File.stub!(:exist?).and_return(false)
|
||||||
@config.src_files.should == []
|
@config.src_files.should == []
|
||||||
|
@config.stylesheets.should == []
|
||||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||||
@config.mappings.should == {
|
@config.mappings.should == {
|
||||||
'/__root__' => @config.project_root,
|
'/__root__' => @config.project_root,
|
||||||
@ -20,8 +21,10 @@ describe Jasmine::Config do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "if sources.yaml is empty" do
|
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)
|
YAML.stub!(:load).and_return(false)
|
||||||
@config.src_files.should == []
|
@config.src_files.should == []
|
||||||
|
@config.stylesheets.should == []
|
||||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||||
@config.mappings.should == {
|
@config.mappings.should == {
|
||||||
'/__root__' => @config.project_root,
|
'/__root__' => @config.project_root,
|
||||||
@ -29,8 +32,8 @@ describe Jasmine::Config do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "using default sources.yaml" do
|
it "using default jasmine.yaml" do
|
||||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources.yaml'))
|
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
|
||||||
@config.src_files.should == []
|
@config.src_files.should == []
|
||||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
||||||
@config.mappings.should == {
|
@config.mappings.should == {
|
||||||
@ -39,14 +42,31 @@ describe Jasmine::Config do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "using rails sources.yaml" do
|
it "simple_config stylesheets" do
|
||||||
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources-rails.yaml'))
|
@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',
|
@config.src_files.should == ['javascripts/prototype.js',
|
||||||
'javascripts/effects.js',
|
'javascripts/effects.js',
|
||||||
'javascripts/controls.js',
|
'javascripts/controls.js',
|
||||||
'javascripts/dragdrop.js',
|
'javascripts/dragdrop.js',
|
||||||
'javascripts/application.js']
|
'javascripts/application.js']
|
||||||
@config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
|
|
||||||
@config.js_files.should == [
|
@config.js_files.should == [
|
||||||
'/javascripts/prototype.js',
|
'/javascripts/prototype.js',
|
||||||
'/javascripts/effects.js',
|
'/javascripts/effects.js',
|
||||||
|
Loading…
Reference in New Issue
Block a user