Top Level Namespace
- Includes:
- Wrong::Assert
Defined Under Namespace
Classes: String, TestGarden
Instance Method Summary collapse
-
#teardown(&block) ⇒ Object
Alternative to putting the teardown code after all relevant tests.
-
#test(topic) ⇒ Object
Begin a test block.
Instance Method Details
#teardown(&block) ⇒ Object
Alternative to putting the teardown code after all relevant tests. This can be used to keep related setup and teardown code together. Teardows are executed in the reverse of their creation order.
244 245 246 247 248 249 250 |
# File 'lib/test-garden.rb', line 244 def teardown(&block) if @test @test.teardowns.last << block else raise "Cannot teardown: not in a test" end end |
#test(topic) ⇒ Object
Begin a test block. The topic can be any object; its to_s method is applied to generate the output string. A class or string is typical.
The block can include essentially any code, including more #test calls, method calls that call #test, assert{} and teardown{} calls, etc.
If the block is omitted, then the test is assumed to be incomplete, perhaps a stub indicating future work. Incomplete tests are counted and reported.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/test-garden.rb', line 212 def test topic if @test @test.nest topic do @test.handle_test_exceptions do if block_given? yield @test.do_teardowns else raise TestGarden::IncompleteTest end end end else begin @test = TestGarden.new @test.main topic do if block_given? yield else raise TestGarden::IncompleteTest end end ensure @test = nil end end end |