diff --git a/lib/flowerbox.rb b/lib/flowerbox.rb index fcd2294..1e767fe 100644 --- a/lib/flowerbox.rb +++ b/lib/flowerbox.rb @@ -1,5 +1,6 @@ require "flowerbox/version" require 'rainbow' +require 'forwardable' module Flowerbox require 'flowerbox/core_ext/module' @@ -16,6 +17,7 @@ module Flowerbox require 'flowerbox/gathered_result' require 'flowerbox/reporter' + require 'flowerbox/configuration' if defined?(Rails::Engine) require 'flowerbox/rails/engine' @@ -24,62 +26,20 @@ module Flowerbox CACHE_DIR = 'tmp/sprockets' class << self - attr_writer :reporters - attr_accessor :port - def reset! - @spec_patterns = nil - @spec_files = nil - @asset_paths = nil - @reporters = nil - @port = nil + @configuration = nil end - def spec_patterns - @spec_patterns ||= [] - end - - def asset_paths - @asset_paths ||= [] - end - - def reporters - @reporters ||= [] - end - - def additional_files - @additional_files ||= [] - end - - def test_with(what) - self.test_environment = Flowerbox::TestEnvironment.for(what) - end - - def run_with(*whats) - self.runner_environment = whats.flatten.collect { |what| Flowerbox::Runner.for(what.to_s) } - end - - def report_with(*whats) - self.reporters = whats.flatten.collect { |what| Flowerbox::Reporter.for(what.to_s) } + def configuration + @configuration ||= Flowerbox::Configuration.new end def path Pathname(File.expand_path('../..', __FILE__)) end - attr_accessor :test_environment, :runner_environment, :bare_coffeescript, :server - - def configure - yield self - - if spec_patterns.empty? - spec_patterns << "**/*_spec*" - spec_patterns << "*/*_spec*" - end - - if reporters.empty? - reporters << Flowerbox::Reporter.for(:progress) - end + def configure(&block) + configuration.configure(&block) end def bare_coffeescript @@ -119,6 +79,14 @@ module Flowerbox def cache_dir File.join(CACHE_DIR, Flowerbox.test_environment.name) end + + def method_missing(method, *args) + if configuration.respond_to?(method) + configuration.send(method, *args) + else + super + end + end end end diff --git a/lib/flowerbox/configuration.rb b/lib/flowerbox/configuration.rb new file mode 100644 index 0000000..1ba758a --- /dev/null +++ b/lib/flowerbox/configuration.rb @@ -0,0 +1,54 @@ +module Flowerbox + class Configuration + attr_writer :reporters, :backtrace_filter + attr_accessor :port + + attr_accessor :test_environment, :runner_environment, :bare_coffeescript, :server + + def spec_patterns + @spec_patterns ||= [] + end + + def asset_paths + @asset_paths ||= [] + end + + def reporters + @reporters ||= [] + end + + def additional_files + @additional_files ||= [] + end + + def backtrace_filter + @backtrace_filter ||= [] + end + + def test_with(what) + self.test_environment = Flowerbox::TestEnvironment.for(what) + end + + def run_with(*whats) + self.runner_environment = whats.flatten.collect { |what| Flowerbox::Runner.for(what.to_s) } + end + + def report_with(*whats) + self.reporters = whats.flatten.collect { |what| Flowerbox::Reporter.for(what.to_s) } + end + + def configure + yield self + + if spec_patterns.empty? + spec_patterns << "**/*_spec*" + spec_patterns << "*/*_spec*" + end + + if reporters.empty? + reporters << Flowerbox::Reporter.for(:progress) + end + end + end +end + diff --git a/lib/flowerbox/result/failure_message.rb b/lib/flowerbox/result/failure_message.rb index 27f325a..d6a8084 100644 --- a/lib/flowerbox/result/failure_message.rb +++ b/lib/flowerbox/result/failure_message.rb @@ -35,11 +35,13 @@ module Flowerbox::Result end def filtered_stack - stack.collect do |line| + stack.reject { |line| + Flowerbox.backtrace_filter.any? { |filter| line[filter] } + }.collect { |line| line.gsub(%r{\.coffee:(\d+)}) do |_| ".coffee:~#{($1.to_i * 0.67 + 1).to_i}" end - end + } end def first_local_stack diff --git a/lib/flowerbox/run/base.rb b/lib/flowerbox/run/base.rb index fe2e134..418c3a2 100644 --- a/lib/flowerbox/run/base.rb +++ b/lib/flowerbox/run/base.rb @@ -35,14 +35,16 @@ module Flowerbox::Run def sprockets require 'flowerbox/sprockets_handler' - Flowerbox::SprocketsHandler.new( - :asset_paths => [ - Flowerbox.path.join("lib/assets/javascripts"), - Flowerbox.path.join("vendor/assets/javascripts"), - @dir, - Flowerbox.asset_paths - ].flatten - ) + Flowerbox::SprocketsHandler.new(:asset_paths => asset_paths) + end + + def asset_paths + [ + Flowerbox.path.join("lib/assets/javascripts"), + Flowerbox.path.join("vendor/assets/javascripts"), + @dir, + Flowerbox.asset_paths + ].flatten end def spec_files diff --git a/lib/flowerbox/unique_asset_list.rb b/lib/flowerbox/unique_asset_list.rb index 03353a7..47fe21b 100644 --- a/lib/flowerbox/unique_asset_list.rb +++ b/lib/flowerbox/unique_asset_list.rb @@ -6,10 +6,19 @@ module Flowerbox super([]) @sprockets = sprockets + + @included = {} end def add(files) - [ files ].flatten.each { |file| self << file if !include?(file) } + [ files ].flatten.each do |file| + self << file if !included?(file) + end + end + + def <<(file) + super(file) + @included[file.pathname.to_s] = true end def to_json @@ -17,8 +26,8 @@ module Flowerbox end private - def include?(file) - any? { |other_file| other_file.pathname.to_s == file.pathname.to_s } + def included?(file) + @included[file.pathname.to_s] end end end