start factoring out some things

This commit is contained in:
John Bintz 2011-05-06 14:05:15 -04:00
parent 128c645d17
commit 603ba69f77
3 changed files with 68 additions and 7 deletions

View File

@ -1,9 +1,16 @@
#!/usr/bin/env ruby
gem_dir = File.expand_path('../..', __FILE__)
$:.unshift(File.join(gem_dir, 'lib'))
require 'yaml'
require 'fileutils'
require 'getoptlong'
require 'jasmine/cli'
include Jasmine::CLI
opts = GetoptLong.new(
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
[ '--no-colors', GetoptLong::NO_ARGUMENT ]
@ -28,7 +35,6 @@ end
opts.each(&process_options)
data = YAML.load_file(ARGV.shift || 'spec/javascripts/support/jasmine.yml')
gem_dir = File.expand_path('../..', __FILE__)
if !File.file?(File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'))
puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
@ -43,12 +49,6 @@ files = [
'file://' + File.join(gem_dir, 'jasmine/lib/jasmine.css')
]
DEFAULTS = {
'spec_files' => [ '**/*[sS]pec.js' ],
'helpers' => [ 'helpers/**/*.js' ],
'spec_dir' => 'spec/javascripts'
}
files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root|
data[searches] ||= DEFAULTS[searches]
data[root] ||= DEFAULTS[root]

17
lib/jasmine/cli.rb Normal file
View File

@ -0,0 +1,17 @@
module Jasmine
module CLI
DEFAULTS = {
'spec_files' => [ '**/*[sS]pec.js' ],
'helpers' => [ 'helpers/**/*.js' ],
'spec_dir' => 'spec/javascripts',
'src_dir' => '',
'stylesheets' => [],
'src_files' => []
}
def process_jasmine_config(overrides = {})
DEFAULTS.merge(overrides)
end
end
end

View File

@ -0,0 +1,44 @@
require 'spec_helper'
require 'jasmine/cli'
describe Jasmine::CLI do
include Jasmine::CLI
describe '#process_jasmine_config' do
context 'without overrides' do
let(:config) { {} }
it "should just return the defaults" do
process_jasmine_config(config).should == {
'src_files' => [],
'stylesheets' => [],
'helpers' => [ 'helpers/**/*.js' ],
'spec_files' => [ '**/*[sS]pec.js' ],
'src_dir' => '',
'spec_dir' => 'spec/javascripts'
}
end
end
context 'with overrides' do
let(:config) {
{
'src_files' => [ 'one', 'two' ],
'src_dir' => 'this-dir',
'stylesheets' => [ 'three', 'four' ],
'helpers' => [ 'five', 'six' ],
'spec_files' => [ 'seven', 'eight' ],
'spec_dir' => 'that-dir'
}
}
it "should return the merged data" do
process_jasmine_config(config).should == config
end
end
end
describe '#get_files' do
end
end