improve things

This commit is contained in:
John Bintz 2012-03-20 14:52:23 -04:00
parent 36519aec31
commit c78174a600
2 changed files with 41 additions and 6 deletions

View File

@ -6,7 +6,19 @@ require 'thor'
class Flowerbox::CLI < Thor class Flowerbox::CLI < Thor
include Thor::Actions include Thor::Actions
desc "test", "Run the specs found in spec dir, loading spec_helper.rb for configuration details" 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, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false method_options :pwd => :string, :env_options => nil, :runners => :string, :runner => :string, :verbose_server => false
def test(dir = "spec/javascripts", *files) def test(dir = "spec/javascripts", *files)
Dir.chdir(pwd) do Dir.chdir(pwd) do
@ -24,7 +36,21 @@ class Flowerbox::CLI < Thor
end end
end end
desc "transplant DIR", "Convert an existing Jasmine gem-style project to Flowerbox" 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) def transplant(dir)
Flowerbox.transplant(dir) Flowerbox.transplant(dir)
end end
@ -35,7 +61,7 @@ class Flowerbox::CLI < Thor
puts "Sprockets cache cleaned." puts "Sprockets cache cleaned."
end end
desc "plant", "Start a new Flowerbox project" desc "plant TYPE [DIR]", "Start a new Flowerbox project of TYPE, potentially specifying a different DIR to install"
def plant(type, dir = nil) def plant(type, dir = nil)
env = Flowerbox::TestEnvironment.for(type) env = Flowerbox::TestEnvironment.for(type)
@ -44,7 +70,13 @@ class Flowerbox::CLI < Thor
directory('.', dir || env.plant_target) directory('.', dir || env.plant_target)
end end
default_task :test def method_missing(method, *args)
if File.directory?(method.to_s)
invoke :test, method.to_s, *args
else
super
end
end
no_tasks do no_tasks do
def pwd def pwd

View File

@ -35,17 +35,20 @@ module Flowerbox::Result
end end
def filtered_stack def filtered_stack
stack.reject { |line| filtered_stack = stack.reject { |line|
Flowerbox.backtrace_filter.any? { |filter| line[filter] } Flowerbox.backtrace_filter.any? { |filter| line[filter] }
}.collect { |line| }.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
} }
filtered_stack.shift if exception?
filtered_stack
end end
def first_local_stack def first_local_stack
@first_local_stack ||= stack.find do |line| @first_local_stack ||= stack[1..-1].find do |line|
!system_files.any? { |file| line[%r{\(#{file}}] } !system_files.any? { |file| line[%r{\(#{file}}] }
end || stack[1] || '' end || stack[1] || ''
end end