Class: Thor::SpecTask

Inherits:
Task
  • Object
show all
Defined in:
lib/thor/tasks/spec.rb

Instance Attribute Summary collapse

Attributes inherited from Task

#description, #options, #usage

Instance Method Summary collapse

Methods inherited from Task

dynamic, #formatted_arguments, #formatted_options, #formatted_usage, #initialize_copy, #short_description

Constructor Details

#initialize(name, files, config = {}) ⇒ SpecTask

Returns a new instance of SpecTask.



26
27
28
29
30
31
32
33
34
35
# File 'lib/thor/tasks/spec.rb', line 26

def initialize(name, files, config={})
  options = { :verbose => Thor::Option.parse(:verbose, config.delete(:verbose) || false) }
  super(name, "#{name.capitalize} task", name, options)

  @name        = name
  @files       = files.map{ |f| %["#{f}"] }.join(" ")
  @rcov_dir    = config.delete(:rdoc_dir) || File.join(Dir.pwd, 'coverage')
  @rcov_config = config.delete(:rcov) || {}
  @spec_config = { :format => 'specdoc', :color => true }.merge(config)
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



24
25
26
# File 'lib/thor/tasks/spec.rb', line 24

def files
  @files
end

#nameObject

Returns the value of attribute name.



24
25
26
# File 'lib/thor/tasks/spec.rb', line 24

def name
  @name
end

#rcov_configObject

Returns the value of attribute rcov_config.



24
25
26
# File 'lib/thor/tasks/spec.rb', line 24

def rcov_config
  @rcov_config
end

#rcov_dirObject

Returns the value of attribute rcov_dir.



24
25
26
# File 'lib/thor/tasks/spec.rb', line 24

def rcov_dir
  @rcov_dir
end

#spec_configObject

Returns the value of attribute spec_config.



24
25
26
# File 'lib/thor/tasks/spec.rb', line 24

def spec_config
  @spec_config
end

Instance Method Details

#run(instance, args = []) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/thor/tasks/spec.rb', line 37

def run(instance, args=[])
  rcov_opts = Thor::Options.to_switches(rcov_config)
  spec_opts = Thor::Options.to_switches(spec_config)

  require 'rbconfig'
  cmd  = RbConfig::CONFIG['ruby_install_name'] << " "

  if rcov?
    FileUtils.rm_rf(rcov_dir)
    cmd << "-S #{where('rcov')} -o #{rcov_dir} #{rcov_opts} "
  end

  cmd << [where('spec'), rcov? ? " -- " : nil, files, spec_opts].join(" ")

  puts cmd if instance.options.verbose?
  system(cmd)
  exit($?.exitstatus)
end