From: Michael Neumann Date: 2004-11-17T23:50:00+09:00 Subject: Re: assert Michael Neumann wrote: > How about this: > > def breakpoint > file, line_no = caller.first.split(':', 2) > reason = File.readlines(file)[line_no.to_i - 1]. > strip.sub(/^breakpoint\s+/, '') > p reason > # setup irb session etc. > end > > a = 4 > breakpoint unless a == 5 > > This extracts the "unless a == 5" out of the source file. Of course, > that does not work for evaled-code (unless the source-buffer is stored > somewhere and we could access it). This brings me to an idea I've seen in Python test-cases. They use docstrings before their "asserts", and these docstrings are then use when the assertion fails. Could we do this as well with comments? (bad example): Python: """Should be > 5""" assert(i > 5) Ruby: # Should be > 5 assert i > 5 This could avoid the use of the message parameter to the assert_* methods, which are used very seldom IMO. One disadvantage of comments is of course, that you can't use #{ ... }. Regards, Michael