diff --git a/Gemfile b/Gemfile index 403dc97..7799a83 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,4 @@ gemspec gem 'rspec' gem 'autotest' - +gem 'fakefs', :require => nil diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 79590e3..f83d07d 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -27,8 +27,8 @@ opts = GetoptLong.new( options = { :colors => false } -process_options = lambda { |*args| - opt = args.shift +@process_options = lambda { |*args| + opt = args.flatten.shift case opt when '--colors', '-c' options[:colors] = true @@ -37,11 +37,9 @@ process_options = lambda { |*args| end } -if File.file?('.jasmine-headless-webkit') - File.readlines('.jasmine-headless-webkit').collect { |line| line.strip.split(' ', 2) }.flatten(1).each(&process_options) -end +read_defaults_file if defaults_file? -opts.each(&process_options) +opts.each(&@process_options) data = YAML.load_file(ARGV.shift || 'spec/javascripts/support/jasmine.yml') diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb index 1d38187..809d156 100644 --- a/lib/jasmine/cli.rb +++ b/lib/jasmine/cli.rb @@ -9,9 +9,19 @@ module Jasmine 'src_files' => [] } + DEFAULTS_FILE = '.jasmine-headless-webkit' + def process_jasmine_config(overrides = {}) DEFAULTS.merge(overrides) end + + def read_defaults_file + File.readlines(DEFAULTS_FILE).collect { |line| line.strip.split(' ', 2) }.each(&@process_options) + end + + def defaults_file? + File.file?(DEFAULTS_FILE) + end end end diff --git a/spec/lib/jasmine/cli_spec.rb b/spec/lib/jasmine/cli_spec.rb index 4296b9e..5c4e340 100644 --- a/spec/lib/jasmine/cli_spec.rb +++ b/spec/lib/jasmine/cli_spec.rb @@ -1,8 +1,10 @@ require 'spec_helper' require 'jasmine/cli' +require 'fakefs/spec_helpers' describe Jasmine::CLI do include Jasmine::CLI + include FakeFS::SpecHelpers describe '#process_jasmine_config' do context 'without overrides' do @@ -38,7 +40,23 @@ describe Jasmine::CLI do end end - describe '#get_files' do + describe '#read_defaults_file' do + let(:test_data) { %w{first second} } + before do + File.open(DEFAULTS_FILE, 'w') { |fh| fh.puts test_data.join(' ') } + end + + it "should read the options" do + found = false + + @process_options = lambda { |*args| + found = true if args.flatten == test_data + } + + read_defaults_file + + found.should be_true + end end end