Michael G Schwern wrote:
> 
> On Sun, Dec 16, 2001 at 02:41:31PM +0000, Piers Cawley wrote:
> > Nothing wrong with an adaptor/factory returning something that isn't
> > a Foo, so long as it has the same interface.
> 
> That's why its isa_ok() and not ref_ok().
> 
> On the off chance Foo->new is supposed to return something that bears
> no relation to Foo at all, then just don't use isa_ok.  Or, check that
> its that other thing:
> 
>     my $foo = Foo->new;
>     isa_ok( $foo, 'Bar' );

Suppose we have RandomThing->new which randomly returns an instance of
one of a few dozen different classes, which have no relation at all with
each other except a common interface.  It wouldn't be a good idea to
test the return value of new for being a specific type, or even if that
thing is one of the 'known' types, since something new might be added in
a future version.

I think that if "all" we know about the returned type is that it is
supposed to provide some specific interface, it would be more robust to
test that the returned thing actually *does* provide the interface.

my $foo = Foo->new;
for my $method (qw/bar baz quux quuux/) {
    ok( $foo->can($method),
        "Foo->new should return something with a $method method"
    );
}

-- 
Klein bottle for rent - inquire within.

Reply via email to