On Dec 29, 9:37=A0am, Robert Klemme <shortcut... / googlemail.com> wrote:
> 2009/12/29 Intransition <transf... / gmail.com>:

> I see to be a bit slow today: how do you want to use modules there?
> Do you want to include them in the test code? =A0What about:
>
> class TestCase
> =A0 def new(cl, &bl)
> =A0 =A0 =A0@cl =3D cl
> =A0 =A0 =A0instance_eval(&bl)
> =A0 end
>
> =A0 alias include extend
> end
>
> TestCase.new String do
> =A0 extend Foo
> =A0 include Bar
> end

No no. You got it exactly. Problem is the module's constants are not
coming through the #extend (which is effectively the same as the
include in the singleton class). Let say I have a library:

  module MyApp
    module SomeSpace
      class FooClass
        ...
       end
    end
  end

In the test cases, instead of having to spell out
MyApp::SomeSpace::FooClass everywhere it is needed, it would be nice
to include MyApp::SomeSpace, and then just reference FooClass in the
tests.


> > Instead of making an instance of TestCase for each case, at this point
> > it looks like I'll have to create a new subclass of it.

> Sorry, you lost me here.

Instead of the code you presented I'd have to do something like:

  class TestCase
    alias :_new, :new
    def self.new(&block)
      Class.new(self, &block)._new
    end
  end

Haven't tested it yet, but that should allow #include to work no
problem. Unfortunately it means defining all my dsl methods at the
class level --not even sure the instance level would be of any use in
this case either, in which case the ._new can be dropped -- kind of
stupid, just to get #include to work. But what else can I do?

I almost feel like I'm having a mental block and there is actually an
easy way to do this.