From 4c7a1f860d3c3036a4efaa7cf260cb85e66c5eb4 Mon Sep 17 00:00:00 2001 From: Ville Lautanala Date: Fri, 16 Dec 2011 14:21:06 +0200 Subject: [PATCH 1/4] Parse and run ERB tags inside YAML config --- lib/jasmine/headless/runner.rb | 3 ++- spec/lib/jasmine/headless/runner_spec.rb | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 1337123..85763c8 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -4,6 +4,7 @@ require 'coffee-script' require 'rainbow' require 'yaml' +require 'erb' require 'sprockets' @@ -112,7 +113,7 @@ module Jasmine def jasmine_config_data raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) - YAML.load_file(@options[:jasmine_config]) + YAML.load(ERB.new(File.read(@options[:jasmine_config])).result(binding)) end end end diff --git a/spec/lib/jasmine/headless/runner_spec.rb b/spec/lib/jasmine/headless/runner_spec.rb index 6c2787c..d6e4cd2 100644 --- a/spec/lib/jasmine/headless/runner_spec.rb +++ b/spec/lib/jasmine/headless/runner_spec.rb @@ -37,13 +37,17 @@ describe Jasmine::Headless::Runner do context 'file exists' do before do File.open(Jasmine::Headless::Runner::RUNNER, 'w') - File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello') } + File.open(config_filename, 'w') { |fh| fh.print YAML.dump('test' => 'hello', 'erb' => '<%= "erb" %>') } end it 'should load the jasmine config' do runner.jasmine_config['test'].should == 'hello' runner.jasmine_config['spec_dir'].should == 'spec/javascripts' end + + it 'should execute ERB in the config file' do + runner.jasmine_config['erb'].should == 'erb' + end end context 'file does not exist' do From ac9a9cf23b250366bed4aa8a675bea5b1f47197b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 24 Dec 2011 09:53:52 -0500 Subject: [PATCH 2/4] try loading bundler too --- lib/jasmine/headless/files_list.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index d12725e..8539f04 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -39,14 +39,26 @@ module Jasmine::Headless def reset! @asset_paths = nil - # register haml-sprockets if it's available... - %w{haml-sprockets}.each do |library| + # register haml-sprockets and handlebars_assets if it's available... + %w{haml-sprockets handlebars_assets}.each do |library| begin require library rescue LoadError end end + begin + require 'bundler' + + envs = [ :default ] + %w{JHW_ENV RAILS_ENV RACK_ENV RAILS_GROUPS}.each do |env| + envs << ENV[env].to_sym if ENV[env] + end + + Bundler.require(*envs) + rescue LoadError + end + # ...and unregister ones we don't want/need Sprockets.instance_eval do EXCLUDED_FORMATS.each do |extension| @@ -173,12 +185,16 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME + p self.class.extension_filter + files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end + p file + sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end From dd86eb404e9c29f0362f4dede2ef90dc18432e0c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 24 Dec 2011 09:55:21 -0500 Subject: [PATCH 3/4] remove debugging --- lib/jasmine/headless/files_list.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index 8539f04..f49ac2e 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -185,16 +185,12 @@ module Jasmine::Headless def to_html(files) alert_time = Time.now + PLEASE_WAIT_IM_WORKING_TIME - p self.class.extension_filter - files.collect do |file| if alert_time && alert_time < Time.now puts "Rebuilding cache, please wait..." alert_time = nil end - p file - sprockets_environment.find_asset(file, :bundle => false).body end.compact.reject(&:empty?) end From 9dafb8389298ed45231cbe6f64e088738e0086cf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 29 Dec 2011 09:32:27 -0500 Subject: [PATCH 4/4] things in a weird state... --- lib/jasmine/headless/files_list.rb | 13 +++---- lib/jasmine/headless/options.rb | 42 +++++++++++++++++++++-- spec/lib/jasmine/headless/options_spec.rb | 39 +++++++++++++++++++++ 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index f49ac2e..f4f066b 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -47,16 +47,13 @@ module Jasmine::Headless end end - begin - require 'bundler' + if ENV['JHW_ENV'] + begin + require 'bundler' - envs = [ :default ] - %w{JHW_ENV RAILS_ENV RACK_ENV RAILS_GROUPS}.each do |env| - envs << ENV[env].to_sym if ENV[env] + Bundler.require(ENV['JHW_ENV'].to_sym) + rescue LoadError end - - Bundler.require(*envs) - rescue LoadError end # ...and unregister ones we don't want/need diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index d62da56..a228dd6 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -17,7 +17,10 @@ module Jasmine :do_list => false, :full_run => true, :enable_cache => true, - :files => [] + :files => [], + :reporters => [ + [ 'HeadlessConsoleReporter' ] + ] } DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') @@ -64,6 +67,10 @@ module Jasmine @options[:do_list] = true when '--seed' @options[:seed] = arg.to_i + when '--format', '-f' + add_reporter(arg) + when '--out' + @options[:reporters].last << arg end end @@ -80,18 +87,47 @@ module Jasmine [ '--colors', '-c', GetoptLong::NO_ARGUMENT ], [ '--no-colors', GetoptLong::NO_ARGUMENT ], [ '--cache', GetoptLong::NO_ARGUMENT ], - [ '--no-t stcache', GetoptLong::NO_ARGUMENT ], + [ '--no-cache', GetoptLong::NO_ARGUMENT ], [ '--keep', GetoptLong::NO_ARGUMENT ], [ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ], [ '--report', GetoptLong::REQUIRED_ARGUMENT ], [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ], [ '--no-full-run', GetoptLong::NO_ARGUMENT ], [ '--list', '-l', GetoptLong::NO_ARGUMENT ], - [ '--seed', GetoptLong::REQUIRED_ARGUMENT ] + [ '--seed', GetoptLong::REQUIRED_ARGUMENT ], + [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ], + [ '--out', GetoptLong::REQUIRED_ARGUMENT ] ) command_line_args.each { |*args| process_option(*args) } end + + def reporters + file_index = 0 + + @options[:reporters].collect do |reporter, file| + output = [ reporter ] + if file + output << "report:#{file_index}" + output << file + file_index += 1 + else + output << "stdout" + end + + output + end + end + + private + def add_reporter(name) + if !@added_reporter + @options[:reporters] = [] + @added_reporter = true + end + + @options[:reporters] << [ name ] + end end end end diff --git a/spec/lib/jasmine/headless/options_spec.rb b/spec/lib/jasmine/headless/options_spec.rb index 237423d..8494681 100644 --- a/spec/lib/jasmine/headless/options_spec.rb +++ b/spec/lib/jasmine/headless/options_spec.rb @@ -110,6 +110,45 @@ describe Jasmine::Headless::Options do end end + let(:test_reporter) { 'TestReporter' } + let(:file) { 'file' } + + context 'no reporters' do + it 'should have the default reporter' do + options[:reporters].should == [ [ 'HeadlessConsoleReporter' ] ] + end + end + + context 'one reporter' do + context 'stdout' do + before do + ARGV.replace([ "--format", test_reporter ]) + end + + it 'should have the new reporter on stdout' do + options[:reporters].should == [ [ test_reporter ] ] + + options.reporters.should == [ [ test_reporter, 'stdout' ] ] + end + end + + context 'file' do + before do + ARGV.replace([ "--format", test_reporter, '--out', file ]) + end + + it 'should have the new reporter on stdout' do + options[:reporters].should == [ [ test_reporter, file ] ] + + options.reporters.should == [ [ test_reporter, 'report:0', file ] ] + end + end + end + + context 'two reporters' do + + end + after do ARGV.replace(@argv) end