hi chromatic :) given being pointed toward Test::MockObject::Extends last time I decided to rework my tests to use it instead of a dozen local overrides. I immediately ran into a little snag.
I want to override IO::Socket::INET so that a class calling it's constructor will use my mocked object. so I tried this: my $mock = Test::MockObject->new('IO::Socket::INET'); $mock->fake_new('IO::Socket::INET') ->set_false('connected') ->mock('error', sub { 'localerror' }); the goal being that when my class calls IO::Socket::INET->new($args) that it fails, returning my error string. well, it works great (thanks!)... except fake_new() doesn't return $self like all the other methods seem to do, so I can't really chain the calls together like I would have expected to be able to do. patch attached :) also, I was a little confused by this note in the Test::MockObject::fake_new() docs: "Note: see Test::MockObject::Extends for a better alternative to this method." if the goal of Extends.pm is to fake an entire class, then wouldn't that include the class constructor? at first I got the impression that I was doing something wrong, but then I figured it was just a chicken-and-egg thing since I started with Extends. or maybe I am doing something wrong (or at least something non-idiomatic...) --Geoff
--- lib/Test/MockObject.pm Thu Mar 25 23:04:57 2004 +++ lib/Test/MockObject.pm.geoff Fri Aug 20 12:29:45 2004 @@ -269,6 +269,7 @@ { my ($self, $class) = @_; $self->fake_module( $class, new => sub { $self } ); + $self; } { --- lib/Test/MockObject/Extends.pm Thu Mar 25 22:58:56 2004 +++ lib/Test/MockObject/Extends.pm.geoff Fri Aug 20 12:28:42 2004 @@ -118,7 +118,7 @@ use Test::MockObject::Extends; my $object = Some::Class->new(); - my $mock_object = Test::MockObject::Extends( $object ); + my $mock_object = Test::MockObject::Extends->new( $object ); $mock->set_true( 'parent_method' );