Class: Covet::CollectionTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/covet/collection_task.rb

Overview

Define a new rake task to collect coverage information for a ‘TestTask`. Usage (in Rakefile):

require 'rake/testtask'
require 'covet/collection_task'

Rake::TestTask.new(:my_tests) do |t|
  t.verbose = true
end

Covet::CollectionTask.new(:collect) do |t|
  t.test_task = :my_tests
  t.description = "Collect coverage information for my_tests"
end

Now, we can can run ‘$ rake collect’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :covet_collect) {|_self| ... } ⇒ CollectionTask

yields

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
32
33
34
# File 'lib/covet/collection_task.rb', line 27

def initialize(name = :covet_collect) # yields
  @name = name
  @description = nil
  @test_task = nil
  @covet_opts = []
  yield self if block_given?
  define
end

Instance Attribute Details

#covet_optsObject

Array of cmdline covet options



25
26
27
# File 'lib/covet/collection_task.rb', line 25

def covet_opts
  @covet_opts
end

#descriptionObject

Returns the value of attribute description.



23
24
25
# File 'lib/covet/collection_task.rb', line 23

def description
  @description
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/covet/collection_task.rb', line 22

def name
  @name
end

#test_taskObject

Rake::TestTask or Symbol



24
25
26
# File 'lib/covet/collection_task.rb', line 24

def test_task
  @test_task
end

Instance Method Details

#defineObject

Define the task



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/covet/collection_task.rb', line 37

def define
  if @test_task.nil?
    raise "#{self.class} '#{@name}' is not properly set up. " \
      "This task needs a `test_task` that's either the `Rake::TestTask` " \
      "object to test or the name of that `TestTask` object. You can assign " \
      "it using the `test_task=` method on the instance of #{self.class}."
  end
  @description ||= "Collect coverage information for task '#{test_task_name}'"
  desc @description
  task @name do
    cmd = %Q(covet -c "rake #{test_task_name}" #{@covet_opts.join(' ')}).strip
    puts cmd
    system cmd
  end
end