lib/shenandoah/tasks.rb in rsutphin-shenandoah-0.1.0 vs lib/shenandoah/tasks.rb in rsutphin-shenandoah-0.1.1
- old
+ new
@@ -1,8 +1,11 @@
require 'rake'
+require 'shenandoah/locator'
require 'shenandoah/runner'
require 'shenandoah/server'
+require 'rails_generator'
+require 'rails_generator/scripts/generate'
module Shenandoah
class Tasks
attr_accessor :locator, :options, :runner
@@ -16,47 +19,88 @@
end
@runner = Shenandoah::Runner.new(@locator)
create_serve_task
create_shell_task
create_run_task
+ create_gen_task
end
- def run_specs
+ def run_specs(pattern=nil)
files = @locator.spec_files
if ENV['SHEN_SPEC']
+ trace "limiting shenandoah specs based on #{ENV['SHEN_SPEC'].inspect}"
files = files.select { |f| f =~ /#{ENV['SHEN_SPEC']}/ }
end
+ if pattern
+ trace "limiting shenandoah specs based on #{pattern.inspect}"
+ files = files.select { |f| f =~ /#{pattern}/ }
+ end
+ trace "running shenandoah specs\n - #{files.join("\n - ")}"
successes = @runner.run_console(files)
if (successes.size != files.size)
raise "Shenandoah specs failed!"
end
end
+ def generate_spec(name)
+ raise "Please specify a spec name. E.g., shen:generate[foo]." unless name
+ ::Rails::Generator::Base::prepend_sources(
+ ::Rails::Generator::PathSource.new(
+ :shenandoah, File.join(File.dirname(__FILE__), '../../rails_generators'))
+ )
+ # These branches are functionally equivalent. They change the logging
+ # that rails_generator emits to omit the WD when the target is under
+ # the WD.
+ ENV['SHEN_SPEC_PATH'], dest =
+ if @locator.spec_path =~ /^#{FileUtils.pwd}\/?/
+ [@locator.spec_path.sub(/^#{FileUtils.pwd}\/?/, ''), FileUtils.pwd]
+ else
+ [@locator.spec_path, '']
+ end
+ ::Rails::Generator::Scripts::Generate.new.run(
+ ['shen_spec', '-t', name], :destination => dest,
+ :quiet => Rake.application.options.quiet)
+ end
+
protected
+ def trace(msg)
+ $stderr.puts msg if Rake.application.options.trace
+ end
+
def default_locator_type
DefaultLocator
end
def create_serve_task
+ desc "Start the in-browser JavaScript spec runner on http://localhost:4410/"
task('shen:serve') do |t|
Shenandoah::Server.set :locator, @locator
if @options[:project_name]
Shenandoah::Server.set :project_name, @options[:project_name]
end
Shenandoah::Server.run!
end
end
def create_shell_task
+ desc "Start the Shenandoah interactive JavaScript shell"
task('shen:shell') do |t|
@runner.run_shell
end
end
def create_run_task
- task('shen:spec') do |t|
- run_specs
+ desc "Run the JavaScript specs"
+ task('shen:spec', :pattern) do |t, args|
+ run_specs args.pattern
+ end
+ end
+
+ def create_gen_task
+ desc "Generate a skeleton spec. Give the spec name as a task arg -- i.e. shen:generate[commands]."
+ task('shen:generate', :basename) do |t, args|
+ generate_spec args.basename
end
end
end
end