diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index a0a75ce..2107c55 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -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] diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb new file mode 100644 index 0000000..dd5d761 --- /dev/null +++ b/lib/jasmine/cli.rb @@ -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 + diff --git a/spec/lib/jasmine/cli_spec.rb b/spec/lib/jasmine/cli_spec.rb new file mode 100644 index 0000000..62322c9 --- /dev/null +++ b/spec/lib/jasmine/cli_spec.rb @@ -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