Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Complete Config renaming
Browse files Browse the repository at this point in the history
- Files, locals for RunnerConfig, Config renamed
  • Loading branch information
ragaskar committed Jul 12, 2012
1 parent 196607e commit c5d39ff
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 211 deletions.
2 changes: 1 addition & 1 deletion lib/jasmine.rb
@@ -1,7 +1,7 @@
jasmine_files = ['base',
'dependencies',
'runner_config',
'config',
'user_config',
'server',
'selenium_driver',
'spec_builder',
Expand Down
104 changes: 83 additions & 21 deletions lib/jasmine/config.rb
@@ -1,47 +1,109 @@
module Jasmine
class RunnerConfig
def initialize(user_config)
@user_config = user_config
class Config
require 'yaml'
require 'erb'

def match_files(dir, patterns)
dir = File.expand_path(dir)
negative, positive = patterns.partition {|pattern| /^!/ =~ pattern}
chosen, negated = [positive, negative].collect do |patterns|
patterns.collect do |pattern|
matches = Dir.glob(File.join(dir, pattern.gsub(/^!/,'')))
matches.empty? && !(pattern =~ /\*|^\!/) ? pattern : matches.collect {|f| f.sub("#{dir}/", "")}.sort
end.flatten.uniq
end
chosen - negated
end

def css_files
@user_config.jasmine_stylesheets + @user_config.user_stylesheets
def simple_config
config = File.exist?(simple_config_file) ? YAML::load(ERB.new(File.read(simple_config_file)).result(binding)) : false
config || {}
end

def jasmine_files
@user_config.jasmine_javascripts

def spec_path
"/__spec__"
end

def js_files
@user_config.js_files
def root_path
"/__root__"
end

def spec_files
@user_config.spec_files
def js_files(spec_filter = nil)
spec_files_to_include = spec_filter.nil? ? spec_files : match_files(spec_dir, [spec_filter])
src_files.collect {|f| "/" + f } + helpers.collect {|f| File.join(spec_path, f) } + spec_files_to_include.collect {|f| File.join(spec_path, f) }
end

def user_stylesheets
stylesheets.collect {|f| "/" + f }
end

def spec_files_full_paths
@user_config.spec_files_full_paths
spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
end

def spec_path
@user_config.spec_path
def project_root
Dir.pwd
end

def spec_dir
@user_config.spec_dir
def simple_config_file
File.join(project_root, 'spec/javascripts/support/jasmine.yml')
end

def src_dir
@user_config.src_dir
if simple_config['src_dir']
File.join(project_root, simple_config['src_dir'])
else
project_root
end
end

def project_root
@user_config.project_root
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 root_path
@user_config.root_path
def helpers
if simple_config['helpers']
match_files(spec_dir, simple_config['helpers'])
else
match_files(spec_dir, ["helpers/**/*.js"])
end
end

def src_files
if simple_config['src_files']
match_files(src_dir, simple_config['src_files'])
else
[]
end
end

def spec_files
if simple_config['spec_files']
match_files(spec_dir, simple_config['spec_files'])
else
match_files(spec_dir, ["**/*[sS]pec.js"])
end
end

def stylesheets
if simple_config['stylesheets']
match_files(src_dir, simple_config['stylesheets'])
else
[]
end
end

def jasmine_stylesheets
::Jasmine::Core.css_files.map {|f| "/__JASMINE_ROOT__/#{f}"}
end

def jasmine_javascripts
::Jasmine::Core.js_files.map {|f| "/__JASMINE_ROOT__/#{f}" }
end
end
end
4 changes: 2 additions & 2 deletions lib/jasmine/runner.rb
Expand Up @@ -10,8 +10,8 @@
require 'spec'
end

jasmine_config = Jasmine::RunnerConfig.new(Jasmine::Config.new)
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
jasmine_runner_config = Jasmine::RunnerConfig.new(Jasmine::Config.new)
spec_builder = Jasmine::SpecBuilder.new(jasmine_runner_config)

should_stop = false

Expand Down
47 changes: 47 additions & 0 deletions lib/jasmine/runner_config.rb
@@ -0,0 +1,47 @@
module Jasmine
class RunnerConfig
def initialize(config)
@config = config
end

def css_files
@config.jasmine_stylesheets + @config.user_stylesheets
end

def jasmine_files
@config.jasmine_javascripts
end

def js_files
@config.js_files
end

def spec_files
@config.spec_files
end

def spec_files_full_paths
@config.spec_files_full_paths
end

def spec_path
@config.spec_path
end

def spec_dir
@config.spec_dir
end

def src_dir
@config.src_dir
end

def project_root
@config.project_root
end

def root_path
@config.root_path
end
end
end
14 changes: 7 additions & 7 deletions lib/jasmine/server.rb
Expand Up @@ -8,8 +8,8 @@
require 'ostruct'

module Jasmine
def self.app(config)
page = Jasmine::Page.new(config)
def self.app(runner_config)
page = Jasmine::Page.new(runner_config)
Rack::Builder.app do
use Rack::Head
use Rack::Jasmine::CacheControl
Expand All @@ -20,16 +20,16 @@ def self.app(config)
end

map('/run.html') { run Rack::Jasmine::Redirect.new('/') }
map('/__suite__') { run Rack::Jasmine::FocusedSuite.new(config) }
map('/__suite__') { run Rack::Jasmine::FocusedSuite.new(runner_config) }

#TODO: These path mappings should come from the config.
#TODO: These path mappings should come from the runner_config.
map('/__JASMINE_ROOT__') { run Rack::File.new(Jasmine::Core.path) }
map(config.spec_path) { run Rack::File.new(config.spec_dir) }
map(config.root_path) { run Rack::File.new(config.project_root) }
map(runner_config.spec_path) { run Rack::File.new(runner_config.spec_dir) }
map(runner_config.root_path) { run Rack::File.new(runner_config.project_root) }

map('/') do
run Rack::Cascade.new([
Rack::URLMap.new('/' => Rack::File.new(config.src_dir)),
Rack::URLMap.new('/' => Rack::File.new(runner_config.src_dir)),
Rack::Jasmine::Runner.new(page)
])
end
Expand Down
109 changes: 0 additions & 109 deletions lib/jasmine/user_config.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/rack/jasmine/focused_suite.rb
Expand Up @@ -2,12 +2,12 @@ module Rack
module Jasmine

class FocusedSuite
def initialize(config)
@config = config
def initialize(runner_config)
@runner_config = runner_config
end

def call(env)
run_adapter = Rack::Jasmine::RunAdapter.new(@config)
run_adapter = Rack::Jasmine::RunAdapter.new(@runner_config)
run_adapter.run(env["PATH_INFO"])
end
end
Expand Down

0 comments on commit c5d39ff

Please sign in to comment.