Class: Minitest::Test
- Inherits:
-
Object
- Object
- Minitest::Test
- Defined in:
- lib/minitest/excludes.rb
Overview
minitest/excludes.rb extends Minitest::Test to provide a clean API for excluding certain tests you don't want to run under certain conditions.
For example, in test/test_xyz.rb you have:
class TestXYZ < Minitest::Test
def test_good
# test that passes
end
def test_bad
# test that fails only on jruby
end
end
For jruby runs, you can add test/excludes/TestXYZ.rb with:
exclude :test_bad, "Uses ObjectSpace" if jruby?
The file is instance_eval'd on TestXYZ so you can call the exclude class method directly. Since it is ruby you can provide any sort of conditions you want to figure out if your tests should be excluded.
TestCase.exclude removes test methods entirely so they don't run setup/teardown at all.
If you want to change where the exclude files are located, you can set the EXCLUDE_DIR environment variable.
Constant Summary collapse
- EXCLUDE_DIR =
ENV['EXCLUDE_DIR'] || +"test/excludes"
Class Method Summary collapse
-
.exclude(name, reason) ⇒ Object
Exclude a test from a testcase.
-
.load_excludes ⇒ Object
Loads the exclusion file for the class, if any.
-
.old_runnable_methods ⇒ Object
:nodoc:.
-
.runnable_methods ⇒ Object
:nodoc:.
Class Method Details
.exclude(name, reason) ⇒ Object
Exclude a test from a testcase. This is intended to be used by exclusion files.
46 47 48 49 50 51 |
# File 'lib/minitest/excludes.rb', line 46 def self.exclude name, reason return warn "Method #{self}##{name} is not defined" unless method_defined? name undef_method name end |
.load_excludes ⇒ Object
Loads the exclusion file for the class, if any.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/minitest/excludes.rb', line 56 def self.load_excludes @__load_excludes__ ||= begin if name and not name.empty? then file = File.join EXCLUDE_DIR, "#{name.gsub(/::/, '/')}.rb" instance_eval File.read(file), file if File.exist? file end true end end |
.old_runnable_methods ⇒ Object
:nodoc:
68 |
# File 'lib/minitest/excludes.rb', line 68 alias :old_runnable_methods :runnable_methods |
.runnable_methods ⇒ Object
:nodoc:
70 71 72 73 |
# File 'lib/minitest/excludes.rb', line 70 def runnable_methods # :nodoc: load_excludes old_runnable_methods end |