Module: Hanami::Minitest::Test::ClassMethods
- Included in:
- Hanami::Minitest::Test
- Defined in:
- lib/hanami/minitest/test.rb
Overview
Provides class-level block syntax for defining tests, setup, and teardown.
Instance Method Summary collapse
-
#setup(&block) ⇒ Object
Defines a setup method using a block.
-
#teardown(&block) ⇒ Object
Defines a teardown method using a block.
-
#test(desc = "anonymous") {|block| ... } ⇒ Object
Defines a test method using a block.
Instance Method Details
#setup(&block) ⇒ Object
Defines a setup method using a block.
The block runs after any superclass setup, ensuring the framework is fully initialized before your setup code runs.
If you need control over when super is called, define a regular setup method instead:
def setup
@subject = MyClass.new
super
end
57 58 59 60 61 62 |
# File 'lib/hanami/minitest/test.rb', line 57 def setup(&block) define_method(:setup) do super() instance_exec(&block) end end |
#teardown(&block) ⇒ Object
Defines a teardown method using a block.
The block runs before any superclass teardown, ensuring your cleanup code runs before the framework tears down (e.g. before Capybara resets its session).
If you need control over when super is called, define a regular teardown method instead:
def teardown
super
@subject.close
end
85 86 87 88 89 90 |
# File 'lib/hanami/minitest/test.rb', line 85 def teardown(&block) define_method(:teardown) do instance_exec(&block) super() end end |
#test(desc = "anonymous") {|block| ... } ⇒ Object
Defines a test method using a block.
29 30 31 32 33 34 35 |
# File 'lib/hanami/minitest/test.rb', line 29 def test(desc = "anonymous", &block) block ||= proc { skip "(no tests defined)" } name = :"test_#{desc.gsub(/[^a-zA-Z0-9]+/, "_").gsub(/^_|_$/, "")}" raise "#{name} is already defined in #{self}" if method_defined?(name) define_method(name, &block) end |