Class: Test::Rake::TestTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Test::Rake::TestTask
- Defined in:
- lib/rubytest/rake.rb
Overview
Define a test rake task.
The TEST environment variable can be used to select tests when using this task. Note, this is just a more convenient way than using RUBYTEST_FILES.
Constant Summary collapse
- DEFAULT_TESTS =
Glob patterns are used by default to select test scripts.
[ 'test/**/case_*.rb', 'test/**/*_case.rb', 'test/**/test_*.rb', 'test/**/*_test.rb' ]
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
Test run configuration.
Instance Method Summary collapse
-
#default_tests ⇒ Array<String>
Default test globs.
-
#define_task ⇒ Object
Define rake task for testing.
-
#initialize(name = 'test', desc = 'run tests', &block) ⇒ TestTask
constructor
Initialize new Rake::TestTask instance.
-
#run ⇒ Object
Run tests, via fork is possible, otherwise straight out.
-
#shell_run ⇒ Object
Run test via command line shell.
-
#test_files ⇒ Array<String>
Resolve test globs.
Constructor Details
#initialize(name = 'test', desc = 'run tests', &block) ⇒ TestTask
Initialize new Rake::TestTask instance.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rubytest/rake.rb', line 35 def initialize(name='test', desc='run tests', &block) @name = name || 'test' @desc = desc @config = Test::Config.new @config.files << default_tests if @config.files.empty? @config.loadpath << 'lib' if @config.loadpath.empty? block.call(@config) define_task end |
Instance Attribute Details
#config ⇒ Config (readonly)
Test run configuration.
31 32 33 |
# File 'lib/rubytest/rake.rb', line 31 def config @config end |
Instance Method Details
#default_tests ⇒ Array<String>
Default test globs. For extra convenience will look for list in ‘ENV` first.
102 103 104 105 106 107 108 |
# File 'lib/rubytest/rake.rb', line 102 def default_tests if ENV['TEST'] ENV['TEST'].split(/[:;]/) else DEFAULT_TESTS end end |
#define_task ⇒ Object
Define rake task for testing.
52 53 54 55 56 57 |
# File 'lib/rubytest/rake.rb', line 52 def define_task desc @desc task @name do config.mode == 'shell' ? run_shell : run end end |
#run ⇒ Object
Run tests, via fork is possible, otherwise straight out.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubytest/rake.rb', line 62 def run if Process.respond_to?(:fork) fork { runner = Test::Runner.new(config) success = runner.run exit -1 unless success } Process.wait else runner = Test::Runner.new(config) success = runner.run exit -1 unless success end end |
#shell_run ⇒ Object
Run test via command line shell.
80 81 82 83 |
# File 'lib/rubytest/rake.rb', line 80 def shell_run success = ruby(*config.to_shellwords) exit -1 unless success end |
#test_files ⇒ Array<String>
Implementation probably cna be simplified.
Resolve test globs.
89 90 91 92 93 94 95 96 |
# File 'lib/rubytest/rake.rb', line 89 def test_files files = tests files = files.map{ |f| Dir[f] }.flatten files = files.map{ |f| File.directory?(f) ? Dir[File.join(f, '**/*.rb')] : f } files = files.flatten.uniq files = files.map{ |f| File.(f) } files end |