Class: Megatest::TestTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/megatest/test_task.rb

Overview

Megatest::TestTask is a rake helper that generates several rake tasks under the main test task’s name-space.

task <name>      :: the main test task
task <name>:cmd  :: prints the command to use

Examples:

Megatest::TestTask.create

The most basic and default setup.

Megatest::TestTask.create :my_tests

The most basic/default setup, but with a custom name

Megatest::TestTask.create :unit do |t|
  t.warning = true
end

Customize the name and only run unit tests.

Constant Summary collapse

WINDOWS =

:nodoc:

RbConfig::CONFIG["host_os"] =~ /mswin|mingw/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :test) ⇒ TestTask

Use TestTask.create instead.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/megatest/test_task.rb', line 92

def initialize(name = :test) # :nodoc:
  super()
  @libs = []
  @name = name
  @tests = ["test/"]
  @extra_args = []
  @verbose = Rake.application.options.trace || Rake.verbose == true
  @warning = true
  @deps = []
  if @name.is_a?(Hash)
    @deps = @name.values.first
    @name = @name.keys.first
  end
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



87
88
89
# File 'lib/megatest/test_task.rb', line 87

def command
  @command
end

#depsObject

Task prerequisites.



85
86
87
# File 'lib/megatest/test_task.rb', line 85

def deps
  @deps
end

#extra_argsObject

Extra arguments to pass to the tests. Defaults empty.



51
52
53
# File 'lib/megatest/test_task.rb', line 51

def extra_args
  @extra_args
end

#full_backtraceObject

Show full backtraces on error



82
83
84
# File 'lib/megatest/test_task.rb', line 82

def full_backtrace
  @full_backtrace
end

#libsObject

Extra library directories to include.



56
57
58
# File 'lib/megatest/test_task.rb', line 56

def libs
  @libs
end

#nameObject

The name of the task and base name for the other tasks generated.



61
62
63
# File 'lib/megatest/test_task.rb', line 61

def name
  @name
end

#testsObject

Test files or directories to run. Defaults to test/



66
67
68
# File 'lib/megatest/test_task.rb', line 66

def tests
  @tests
end

#verboseObject

Print out commands as they run. Defaults to Rake’s trace (-t flag) option.



77
78
79
# File 'lib/megatest/test_task.rb', line 77

def verbose
  @verbose
end

#warningObject

Turn on ruby warnings (-w flag). Defaults to true.



71
72
73
# File 'lib/megatest/test_task.rb', line 71

def warning
  @warning
end

Class Method Details

.create(name = :test, &block) ⇒ Object

Create several test-oriented tasks under name. Takes an optional block to customize variables.



41
42
43
44
45
46
# File 'lib/megatest/test_task.rb', line 41

def self.create(name = :test, &block)
  task = new name
  task.instance_eval(&block) if block
  task.define
  task
end

Instance Method Details

#defineObject

:nodoc:



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/megatest/test_task.rb', line 107

def define # :nodoc:
  desc "Run the test suite."
  task name => Array(deps) do
    sh(*make_test_cmd, verbose: verbose)
  end

  desc "Print out the test command. Good for profiling and other tools."
  task "#{name}:cmd" do
    puts make_test_cmd.join(" ")
  end
end

#make_test_cmdObject

Generate the test command-line.



122
123
124
125
126
127
128
129
130
# File 'lib/megatest/test_task.rb', line 122

def make_test_cmd
  cmd = [command || "megatest"]
  cmd << "-I#{libs.join(File::PATH_SEPARATOR)}" unless libs.empty?
  # cmd << "-w" if warning
  cmd << "--backtrace" if full_backtrace
  cmd.concat(extra_args)
  cmd.concat(tests)
  cmd
end