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 shell.
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.
106 107 108 109 110 111 112 |
# File 'lib/rubytest-rake.rb', line 106 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 shell. (Not Currently Used)
Note, the problem with this approach is that before and after procedures cannot be passed along. In it’s current form it also requires that ‘rubytest-cli` be installed.
84 85 86 87 |
# File 'lib/rubytest-rake.rb', line 84 def shell_run success = ruby('rubytest', *config.to_shellwords) exit -1 unless success end |