class Object

Public Instance Methods

teardown(&block) click to toggle source

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.

    # File lib/test-garden.rb
244 def teardown(&block)
245   if @test
246     @test.teardowns.last << block
247   else
248     raise "Cannot teardown: not in a test"
249   end
250 end
test(topic) { || ... } click to toggle source

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.

    # File lib/test-garden.rb
212 def test topic
213   if @test
214     @test.nest topic do
215       @test.handle_test_exceptions do
216         if block_given?
217           yield
218           @test.do_teardowns
219         else
220           raise TestGarden::IncompleteTest
221         end
222       end
223     end
224     
225   else
226     begin
227       @test = TestGarden.new
228       @test.main topic do
229         if block_given?
230           yield
231         else
232           raise TestGarden::IncompleteTest
233         end
234       end
235     ensure
236       @test = nil
237     end
238   end
239 end