Gavin Sinclair
11/21/2004 11:24:00 PM
On Sunday, November 21, 2004, 3:48:08 PM, itsme213 wrote:
>> I suppose that assert() can still be used. The new
>> version would I have to figure out that it runs in
>> the context of test/unit. In that context its behavior
>> would be compatible with test/unit.
>>
>> The other contexts that assert() should support are:
>> - production => throw an exception
>> - debugging => start an irb session
>> - custom => invoke some user provided assert failure handler
> I like this the best of all I've seen so far.
This is a good idea to an extent. I doubt how much it would be used
in practice. To me, the use-cases for production and debugging are so
different that the same code can't serve them both.
Anyway, this kind of functionality is the responsibility of an
Assumptions framework. (To avoid clasing with Test::Unit::Assertions.)
require 'assumptions'
Assumptions.configure do |a|
a.in_debug { start_irb }
a.in_production { throw_exception }
a.custom { ... }
end
Assumptions.current_mode = :debug
...
customers.each do |c|
assume c.full_name == [c.first_name, c.last_name].join(' ')
end
What I'm saying is that this functionality can't reasonably be built
into a single method ("assert") and distributed. The above code is,
to my mind, as simple as possible, but no simpler.
Why not create something like this called Assumptions? Then use the
top-level "assume" method everywhere. If it's good, I'll include it
in dev-utils, because it's obviously a good fit. But I have no
interest in creating it myself: it sounds a lot more useful in theory
than in practice.
Cheers,
Gavin