move config to separate object, fix 1.9.2-style require issue in sprockets loading, backtrace filtering
This commit is contained in:
parent
b6db1384d6
commit
36519aec31
@ -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
|
||||
|
||||
|
54
lib/flowerbox/configuration.rb
Normal file
54
lib/flowerbox/configuration.rb
Normal file
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user