dave / thomases.com [mailto:dave / thomases.com] wrote:

> "Nathaniel Talbott" <nathaniel / talbott.ws> writes:
> 
> > Ah, but JUnit uses setUp... two words. So which is the "xUnit way?"
> 
> Sigh... good point.

Don't sigh... we can get through this if we all stick together :-)


> OK, how about this.
> 
> The idea of having these set[-][uU]p methods called by coincidence has

> always bugged me. Instead, what about
> 
>    class MyTest < Test::Case
> 
>      def initialize(*args)
>        super
> 
>        overall_setup do
>          x
>          y
>        end
> 
>        per_test_setup do
>          a
>          b
>        end
>      end
> 
>      def test_...
> 
> 
> That makes it explicit.

When I first read this last night, I had the same feeling I got when you
told me about the "single require/at_exit trick" at the RubyConf... the
feeling of you sharing a great insight, and me not quite grokking the
implications of it yet :-)

Having slept on it, though, I think I'm beginning to understand, and the
idea seems even more intriguing. A couple of issues. First, I'm not
really in favor of putting overall set up here. It requires TestCase to
track from an instance perspective something that only suites really
care about. So lets just ignore it for a second, and focus on the issue
at hand: per test set up.

The real advantage I see to what you're proposing is the name error that
will occur if the wrong method name is used. The biggest disadvantage is
confusion when coming from another xUnit, and the fact that it becomes
even more likely that set up will be skipped accidentally when legacy
code is ported.

Here's an idea (if I can make it work): what if the implementation of
#set_up (or whatever it's called) in TestCase takes in a block like
you're proposing? Those who want to do things the new, cool way can use
it as proposed above, and those who would rather stick with the old
xUnit nomenclature (or are porting older code) can still use old
faithful. The framework would be smart enough to figure out which
they're doing, and act appropriately. My biggest concern with this is
that it really confuses the meaning of #set_up: it might mean, "register
this block as my set up", or, very differently, "I'm overriding this
with my set up code." Of course, the usages are so different, it might
not matter.

Thoughts?

As for overall set up, right now I don't think it lives in the TestCase,
but I could be convinced otherwise.


Nathaniel

<:((><
+ - -
| RoleModel Software, Inc.
| EQUIP VI