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 "flowerbox/version"
|
||||||
require 'rainbow'
|
require 'rainbow'
|
||||||
|
require 'forwardable'
|
||||||
|
|
||||||
module Flowerbox
|
module Flowerbox
|
||||||
require 'flowerbox/core_ext/module'
|
require 'flowerbox/core_ext/module'
|
||||||
@ -16,6 +17,7 @@ module Flowerbox
|
|||||||
require 'flowerbox/gathered_result'
|
require 'flowerbox/gathered_result'
|
||||||
|
|
||||||
require 'flowerbox/reporter'
|
require 'flowerbox/reporter'
|
||||||
|
require 'flowerbox/configuration'
|
||||||
|
|
||||||
if defined?(Rails::Engine)
|
if defined?(Rails::Engine)
|
||||||
require 'flowerbox/rails/engine'
|
require 'flowerbox/rails/engine'
|
||||||
@ -24,62 +26,20 @@ module Flowerbox
|
|||||||
CACHE_DIR = 'tmp/sprockets'
|
CACHE_DIR = 'tmp/sprockets'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_writer :reporters
|
|
||||||
attr_accessor :port
|
|
||||||
|
|
||||||
def reset!
|
def reset!
|
||||||
@spec_patterns = nil
|
@configuration = nil
|
||||||
@spec_files = nil
|
|
||||||
@asset_paths = nil
|
|
||||||
@reporters = nil
|
|
||||||
@port = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def spec_patterns
|
def configuration
|
||||||
@spec_patterns ||= []
|
@configuration ||= Flowerbox::Configuration.new
|
||||||
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) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def path
|
def path
|
||||||
Pathname(File.expand_path('../..', __FILE__))
|
Pathname(File.expand_path('../..', __FILE__))
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :test_environment, :runner_environment, :bare_coffeescript, :server
|
def configure(&block)
|
||||||
|
configuration.configure(&block)
|
||||||
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
|
||||||
|
|
||||||
def bare_coffeescript
|
def bare_coffeescript
|
||||||
@ -119,6 +79,14 @@ module Flowerbox
|
|||||||
def cache_dir
|
def cache_dir
|
||||||
File.join(CACHE_DIR, Flowerbox.test_environment.name)
|
File.join(CACHE_DIR, Flowerbox.test_environment.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def method_missing(method, *args)
|
||||||
|
if configuration.respond_to?(method)
|
||||||
|
configuration.send(method, *args)
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def filtered_stack
|
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 |_|
|
line.gsub(%r{\.coffee:(\d+)}) do |_|
|
||||||
".coffee:~#{($1.to_i * 0.67 + 1).to_i}"
|
".coffee:~#{($1.to_i * 0.67 + 1).to_i}"
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_local_stack
|
def first_local_stack
|
||||||
|
@ -35,14 +35,16 @@ module Flowerbox::Run
|
|||||||
def sprockets
|
def sprockets
|
||||||
require 'flowerbox/sprockets_handler'
|
require 'flowerbox/sprockets_handler'
|
||||||
|
|
||||||
Flowerbox::SprocketsHandler.new(
|
Flowerbox::SprocketsHandler.new(:asset_paths => asset_paths)
|
||||||
:asset_paths => [
|
end
|
||||||
|
|
||||||
|
def asset_paths
|
||||||
|
[
|
||||||
Flowerbox.path.join("lib/assets/javascripts"),
|
Flowerbox.path.join("lib/assets/javascripts"),
|
||||||
Flowerbox.path.join("vendor/assets/javascripts"),
|
Flowerbox.path.join("vendor/assets/javascripts"),
|
||||||
@dir,
|
@dir,
|
||||||
Flowerbox.asset_paths
|
Flowerbox.asset_paths
|
||||||
].flatten
|
].flatten
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def spec_files
|
def spec_files
|
||||||
|
@ -6,10 +6,19 @@ module Flowerbox
|
|||||||
super([])
|
super([])
|
||||||
|
|
||||||
@sprockets = sprockets
|
@sprockets = sprockets
|
||||||
|
|
||||||
|
@included = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(files)
|
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
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
@ -17,8 +26,8 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def include?(file)
|
def included?(file)
|
||||||
any? { |other_file| other_file.pathname.to_s == file.pathname.to_s }
|
@included[file.pathname.to_s]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user