Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-MockModule CPAN distribution.

Report information
The Basics
Id: 56813
Status: resolved
Priority: 0/
Queue: Test-MockModule

People
Owner: GFRANKS [...] cpan.org
Requestors: mutant.nz [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.05
Fixed in: 0.07



Subject: Update docs to make clear it T::MM does not work with objects
Unless I'm missing something, T::MM doesn't work with objects, i.e. this is not possible: my $mock = Test::MockModule->new('Foo', no_auto=>1); $mock->mock( 'create' => sub { $mock }, ); $mock->mock('bar', sub { print "bah\n" }); my $foo = Foo->new(); $foo->bar(); # Dies This should be made clear in the docs. Would be a nice feature, but not sure this is the intention of the module.
On Thu Apr 22 04:46:37 2010, Mutant wrote: Show quoted text
> Unless I'm missing something, T::MM doesn't work with objects, i.e. this > is not possible: > > my $mock = Test::MockModule->new('Foo', no_auto=>1); > $mock->mock( > 'create' => sub { $mock }, > ); > $mock->mock('bar', sub { print "bah\n" }); > > my $foo = Foo->new(); > $foo->bar(); # Dies > > This should be made clear in the docs. Would be a nice feature, but not > sure this is the intention of the module.
This seems like you're trying to use Test::MockModule like Test::MockObject. In your example, $mock is actually a Test::MockModule object, not a Foo object. You'll also want to override the 'new' subroutine, rather than 'create'. Somethign like this seems like what you're looking for: use Test::MockModule; use strict; package Foo; sub foo { print "foo\n"; } package main; my $mock = Test::MockModule->new('Foo', no_auto=>1); $mock->mock( new => sub { bless {}, "Foo" }, ); $mock->mock('bar', sub { print "bah\n" }); my $foo = Foo->new(); $foo->foo(); $foo->bar(); # Succeeds Output: foo bah
I'm updating the docs with an example based on this ticket though, and will release as 0.07 later today.
Docs updated for this as of v0.07 today.