Refactor config file/path handling.

This commit is contained in:
Christian Williams
2009-12-28 16:27:02 -06:00
parent 2045226ba7
commit 81aeeeedee
15 changed files with 150 additions and 76 deletions

53
spec/config_spec.rb Normal file
View File

@@ -0,0 +1,53 @@
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"))
@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']
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')
]
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

View File

@@ -9,22 +9,7 @@ class JasmineSelfTestConfig < Jasmine::Config
File.join(proj_root, 'src')
end
def src_files
Dir.glob(File.join(src_dir, "**/*.js"))
end
def spec_dir
File.join(proj_root, 'jasmine/spec')
end
def spec_files
Dir.glob(File.join(spec_dir, "**/*[Ss]pec.js")).collect { |f| f.sub("#{spec_dir}/", "spec/") }
end
def mappings
{
"/src" => src_dir,
"/spec" => spec_dir
}
end
end

View File

@@ -1,6 +1,8 @@
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
require 'jasmine_self_test_config'
jasmine_runner = JasmineSelfTestRunner.new
jasmine_runner = JasmineSelfTestConfig.new
spec_builder = Jasmine::SpecBuilder.new(jasmine_runner)
should_stop = false