flowerbox/bin/flowerbox
2012-03-24 10:17:33 -04:00

96 lines
2.7 KiB
Ruby
Executable File

#!/usr/bin/env ruby
if !ENV['BUNDLE_GEMFILE'] && File.file?('Gemfile')
require 'bundler/setup'
$: << File.expand_path('../../lib', __FILE__)
end
require 'flowerbox'
require 'thor'
class Flowerbox::CLI < Thor
include Thor::Actions
default_task :help
def help(*args)
if !args.first
puts "Flowerbox is a multi-environment, multi-runner JavaScript testing tool."
puts "It supports Jasmine and Cucumber.js, and it runs tests on Node.js and Selenium-driven browsers."
puts
end
super
end
desc "test [DIR]", "Run the specs found in spec dir, loading spec_helper.rb for configuration details"
method_options :pwd => :string, [:quiet, '-q'] => false, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false
def test(dir = "spec/javascripts", *files)
Dir.chdir(pwd) do
result = Flowerbox.run(dir, options.dup.merge(:files => files))
Flowerbox.cleanup!
exit result
end
end
desc "debug DIR", "Start the Flowerbox server to help debug loading issues."
method_options :pwd => :string, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false
def debug(dir = "spec/javascripts")
Dir.chdir(pwd) do
Flowerbox.debug(dir, options.dup)
end
end
desc "transplant DIR", "Convert an existing JavaScript testing project to Flowerbox"
long_desc <<-TXT
`flowerbox transplant` converts an existing JavaScript testing project type
to Flowerbox. Currently, you can transplant the following types of projects:
* Pivotal Labs Jasmine gem-style
\x5 (also covers jasmine-headless-webkit)
These types of projects live in `spec/javascripts` (or the specified directory)
and have the file `support/jasmine.yml` that defines what files are loaded
at what parts in the test load process. `jasmine.yml` is converted to a
Flowerbox `spec_helper.rb` file and placed into `spec/javascripts`.
Flowerbox will ask before overwriting existing files.
TXT
def transplant(dir)
Flowerbox.transplant(dir)
end
desc "clean", "Clean the Sprockets cache"
def clean
FileUtils.rm_rf(Flowerbox::CACHE_DIR)
puts "Sprockets cache cleaned."
end
desc "plant TYPE [DIR]", "Start a new Flowerbox project of TYPE, potentially specifying a different DIR to install"
def plant(type, dir = nil)
env = Flowerbox::TestEnvironment.for(type)
self.class.source_root(Flowerbox.path.join(env.plant_source))
directory('.', dir || env.plant_target)
end
def method_missing(method, *args)
if File.directory?(method.to_s)
test(method.to_s, *args)
else
super
end
end
no_tasks do
def pwd
options[:pwd] || Dir.pwd
end
end
end
Flowerbox::CLI.start