Class: Shenandoah::Tasks

Inherits:
Object
  • Object
show all
Defined in:
lib/shenandoah/tasks.rb

Direct Known Subclasses

Rails::Tasks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Tasks

Returns a new instance of Tasks.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shenandoah/tasks.rb', line 10

def initialize(options = {})
  @options = options
  @locator =
    if options[:locator]
      options[:locator]
    else
      default_locator_type.new(options)
    end
  @runner = Shenandoah::Runner.new(@locator)
  create_serve_task
  create_shell_task
  create_run_task
  create_gen_task unless options[:generate_task] == false
end

Instance Attribute Details

#locatorObject

Returns the value of attribute locator.



8
9
10
# File 'lib/shenandoah/tasks.rb', line 8

def locator
  @locator
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/shenandoah/tasks.rb', line 8

def options
  @options
end

#runnerObject

Returns the value of attribute runner.



8
9
10
# File 'lib/shenandoah/tasks.rb', line 8

def runner
  @runner
end

Instance Method Details

#generate_spec(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shenandoah/tasks.rb', line 42

def generate_spec(name)
  raise "Please specify a spec name.  E.g., shen:generate[foo]." unless name
  require 'rails_generator'
  require 'rails_generator/scripts/generate'
  ::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

#run_specs(pattern = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shenandoah/tasks.rb', line 25

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