From: James Britt Date: 2005-11-01T02:39:11+09:00 Subject: Re: TeSLa, a Domain Specific Language for Unit Testing obscured by code wrote: > Well, it doesn't quite works that way (the implementation, that is... I > tried to avoid using 'eval' as long as I could) but yes, all references > to properties or methods are to an instance of the class where the > tests are specified. If you take a look at the example.rb script > included in the package, you'll notice > > test_method :add_item => [:item4] do > requires {@items = [:item1, :item2, :item3]} > assert {size == 4} > end > > is indeed declared just bellow the 'add_item' method in class Catalog > and that 'items' is a property of that class. 'test_method' will create > a clean instance of class Catalog and execute the 'add_item' method > with :item4 as a parameter and 'assert' will check that 'size' (of the > Catalog instance) is indeed 4 as long of the 'precondition' stated by > requires was met. Ah. Thank you for the clarification. I often put my unit tests in the same source file as the class code, and being able to have tests right next to methods is quite slick. > As for behavior-driven development, I never knew it existed, thanks a > lot for the link, I'm going to have a look at it right away. > By the way, I never intended for TeSLa to be a "pure" unit testing > framework, maybe even include concepts from Eiffel's Design By Contract > (so far that's just an idea I'm toying with) so let me know of any > interesting concept you might have about testing in general and I'll > take a look at it. I'm interested in the idea of having executable comments, so that the rdoc for a method both renders as examples for the reader, and can be run as unit tests. I have no idea how your work might fit into that, though. One out-of-the-blue idea: an rdoc directive call that grabs the TeSLa code and translates it into an example using the normal calling syntax. So, test_method :add_item => [:item4] do requires {@items = [:item1, :item2, :item3]} assert {size == 4} end would become, in the rendered method docs, c = Catalog.new c.items = [:item1, :item2, :item3] c.add_item( :item4 ) Expected results: c.size == 4 Or something. Thanks, James Britt -- http://www.ruby-doc.org - The Ruby Documentation Site http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys