Class: MicroTest::Test
- Inherits:
-
Object
- Object
- MicroTest::Test
- Defined in:
- lib/micro_test/test.rb
Overview
Superclass for all test classes.
Class Method Summary collapse
-
.after(what = nil) { ... } ⇒ Object
Defines a teardown method that will run after each individual test.
-
.before(what = nil) { ... } ⇒ Object
Defines a setup method that will run before each individual test.
-
.files ⇒ Hash
All files that define subclasses of this class.
-
.inherited(subclass) ⇒ Object
A callback provided by Ruby that is invoked whenever a subclass is created.
-
.reset ⇒ Object
Resets the state in preparation for a new test run.
-
.subclasses ⇒ Array<MicroTest::Test>
All subclasses of this class.
-
.test(desc) { ... } ⇒ Object
Defines a test.
-
.tests ⇒ Array<MicroTest::TestWrapper>
All individual tests defined in this class.
Class Method Details
.after(what = nil) { ... } ⇒ Object
Defines a teardown method that will run after each individual test.
60 61 62 |
# File 'lib/micro_test/test.rb', line 60 def after(what=nil, &block) @after = block end |
.before(what = nil) { ... } ⇒ Object
Defines a setup method that will run before each individual test.
53 54 55 |
# File 'lib/micro_test/test.rb', line 53 def before(what=nil, &block) @before = block end |
.files ⇒ Hash
Primarily used in the context of MicroTest::Test.
All files that define subclasses of this class.
33 34 35 |
# File 'lib/micro_test/test.rb', line 33 def files @files ||= {} end |
.inherited(subclass) ⇒ Object
A callback provided by Ruby that is invoked whenever a subclass is created.
44 45 46 47 48 |
# File 'lib/micro_test/test.rb', line 44 def inherited(subclass) file_path = caller[0][0, caller[0].index(/:[0-9]+:/)] files[file_path] = File.open(file_path).readlines subclasses << subclass end |
.reset ⇒ Object
Resets the state in preparation for a new test run.
38 39 40 41 |
# File 'lib/micro_test/test.rb', line 38 def reset tests.each { |test| test.reset } subclasses.each { |subclass| subclass.reset } end |
.subclasses ⇒ Array<MicroTest::Test>
All subclasses of this class.
15 16 17 |
# File 'lib/micro_test/test.rb', line 15 def subclasses @subclasses ||= [] end |
.test(desc) { ... } ⇒ Object
Defines a test. Allows subclasses to define tests in their class definition.
76 77 78 79 80 81 |
# File 'lib/micro_test/test.rb', line 76 def test(desc, &block) wrapper = MicroTest::TestWrapper.new(self, desc, &block) wrapper.create_method(:before, &@before) if @before wrapper.create_method(:after, &@after) if @after tests << wrapper end |
.tests ⇒ Array<MicroTest::TestWrapper>
All individual tests defined in this class.
21 22 23 |
# File 'lib/micro_test/test.rb', line 21 def tests @tests ||= [] end |