Class: Megatest::TestTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Megatest::TestTask
- 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
-
#command ⇒ Object
Returns the value of attribute command.
-
#deps ⇒ Object
Task prerequisites.
-
#extra_args ⇒ Object
Extra arguments to pass to the tests.
-
#full_backtrace ⇒ Object
Show full backtraces on error.
-
#libs ⇒ Object
Extra library directories to include.
-
#name ⇒ Object
The name of the task and base name for the other tasks generated.
-
#tests ⇒ Object
Test files or directories to run.
-
#verbose ⇒ Object
Print out commands as they run.
-
#warning ⇒ Object
Turn on ruby warnings (-w flag).
Class Method Summary collapse
-
.create(name = :test, &block) ⇒ Object
Create several test-oriented tasks under
name.
Instance Method Summary collapse
-
#define ⇒ Object
:nodoc:.
-
#initialize(name = :test) ⇒ TestTask
constructor
Use TestTask.create instead.
-
#make_test_cmd ⇒ Object
Generate the test command-line.
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..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
#command ⇒ Object
Returns the value of attribute command.
87 88 89 |
# File 'lib/megatest/test_task.rb', line 87 def command @command end |
#deps ⇒ Object
Task prerequisites.
85 86 87 |
# File 'lib/megatest/test_task.rb', line 85 def deps @deps end |
#extra_args ⇒ Object
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_backtrace ⇒ Object
Show full backtraces on error
82 83 84 |
# File 'lib/megatest/test_task.rb', line 82 def full_backtrace @full_backtrace end |
#libs ⇒ Object
Extra library directories to include.
56 57 58 |
# File 'lib/megatest/test_task.rb', line 56 def libs @libs end |
#name ⇒ Object
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 |
#tests ⇒ Object
Test files or directories to run. Defaults to test/
66 67 68 |
# File 'lib/megatest/test_task.rb', line 66 def tests @tests end |
#verbose ⇒ Object
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 |
#warning ⇒ Object
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
#define ⇒ Object
: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_cmd ⇒ Object
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 |