2012-02-22 16:47:07 +00:00
|
|
|
require "flowerbox/version"
|
2012-03-02 18:28:52 +00:00
|
|
|
require 'flowerbox-delivery'
|
2012-02-22 16:47:07 +00:00
|
|
|
|
|
|
|
module Flowerbox
|
2012-03-02 18:28:52 +00:00
|
|
|
autoload :Runner, 'flowerbox/runner'
|
|
|
|
|
2012-02-22 16:47:07 +00:00
|
|
|
module Runner
|
|
|
|
autoload :Node, 'flowerbox/runner/node'
|
2012-02-23 21:12:00 +00:00
|
|
|
autoload :Selenium, 'flowerbox/runner/selenium'
|
2012-03-02 18:28:52 +00:00
|
|
|
autoload :Firefox, 'flowerbox/runner/firefox'
|
|
|
|
autoload :Chrome, 'flowerbox/runner/chrome'
|
2012-02-23 21:12:00 +00:00
|
|
|
autoload :Base, 'flowerbox/runner/base'
|
2012-02-22 16:47:07 +00:00
|
|
|
end
|
|
|
|
|
2012-03-02 18:28:52 +00:00
|
|
|
autoload :TestEnvironment, 'flowerbox/test_environment'
|
|
|
|
|
|
|
|
module TestEnvironment
|
|
|
|
autoload :Jasmine, 'flowerbox/test_environment/jasmine'
|
|
|
|
end
|
|
|
|
|
2012-02-29 19:23:56 +00:00
|
|
|
autoload :Rack, 'flowerbox/rack'
|
|
|
|
|
2012-02-22 16:47:07 +00:00
|
|
|
class << self
|
|
|
|
def spec_patterns
|
|
|
|
@spec_patterns ||= []
|
|
|
|
end
|
|
|
|
|
|
|
|
def asset_paths
|
|
|
|
@asset_paths ||= []
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_with(what)
|
2012-03-02 18:28:52 +00:00
|
|
|
self.test_environment = Flowerbox::TestEnvironment.for(what)
|
2012-02-22 16:47:07 +00:00
|
|
|
end
|
|
|
|
|
2012-03-02 18:28:52 +00:00
|
|
|
def run_with(*whats)
|
|
|
|
self.runner_environment = whats.collect { |what| Flowerbox::Runner.for(what) }
|
2012-02-23 21:12:00 +00:00
|
|
|
end
|
2012-02-22 16:47:07 +00:00
|
|
|
|
2012-02-23 21:12:00 +00:00
|
|
|
def path
|
|
|
|
Pathname(File.expand_path('../..', __FILE__))
|
2012-02-22 16:47:07 +00:00
|
|
|
end
|
|
|
|
|
2012-02-23 21:12:00 +00:00
|
|
|
attr_accessor :test_environment, :runner_environment, :bare_coffeescript
|
2012-02-22 16:47:07 +00:00
|
|
|
|
|
|
|
def configure
|
|
|
|
yield self
|
2012-03-02 18:28:52 +00:00
|
|
|
|
|
|
|
if spec_patterns.empty?
|
|
|
|
spec_patterns << "**/*_spec*"
|
|
|
|
spec_patterns << "*/*_spec*"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bare_coffeescript
|
|
|
|
@bare_coffeescript ||= true
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(dir)
|
|
|
|
load File.join(dir, 'spec_helper.rb')
|
|
|
|
|
|
|
|
require 'coffee_script'
|
|
|
|
require 'tilt/coffee'
|
|
|
|
|
|
|
|
Tilt::CoffeeScriptTemplate.default_bare = Flowerbox.bare_coffeescript
|
|
|
|
|
|
|
|
result = Flowerbox.runner_environment.collect do |env|
|
|
|
|
env.run(build_sprockets_for(dir))
|
|
|
|
end
|
|
|
|
|
|
|
|
result.max
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_sprockets_for(dir)
|
|
|
|
sprockets = Flowerbox::Delivery::SprocketsHandler.new(
|
|
|
|
:asset_paths => [
|
|
|
|
Flowerbox.path.join("lib/assets/javascripts"),
|
|
|
|
Flowerbox.path.join("vendor/assets/javascripts"),
|
|
|
|
dir,
|
|
|
|
Flowerbox.asset_paths
|
|
|
|
].flatten
|
|
|
|
)
|
|
|
|
|
|
|
|
sprockets.add('flowerbox')
|
|
|
|
sprockets.add('json2')
|
|
|
|
|
|
|
|
Flowerbox.test_environment.inject_into(sprockets)
|
|
|
|
|
|
|
|
spec_files_for(dir).each { |file| sprockets.add(file) }
|
|
|
|
|
|
|
|
sprockets
|
|
|
|
end
|
|
|
|
|
|
|
|
def spec_files_for(dir)
|
|
|
|
return @spec_files if @spec_files
|
|
|
|
|
|
|
|
@spec_files = []
|
|
|
|
|
|
|
|
Flowerbox.spec_patterns.each do |pattern|
|
|
|
|
Dir[File.join(dir, pattern)].each do |file|
|
|
|
|
@spec_files << file.gsub(dir + '/', '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec_files
|
2012-02-22 16:47:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|