Subject: | fake_module() doesn't work if constructer not mocked |
Hi,
Sort of a bug with fake_module() - if you try to fake a module that's
being used as a class, and you don't mock the constructor, the
fake_module() doesn't work, i.e. it calls the original module.
In test1.pl, I get
Can't locate object method "new" via package "Foo" at code_to_test.pl
line 7.
If there was really such a module as Foo, it would call it's new()
method as well.
In test2.pl, where I've mocked the constructor I get
Un-mocked method 'bar()' called at code_to_test.pl line 9
Which is what I would expect.
Of course, I wouldn't really expect test1.pl to work at all (i.e. you
should always have to mock the constructer), but it should really die or
something, instead of not faking the module.
Tested with version 1.01, then upgraded to 1.06 and found the same
behaviour.
Using Perl 5.8.4
Subject: | test2.pl |
use strict;
use warnings;
use Test::MockObject;
require 'code_to_test.pl';
my $mock_foo;
BEGIN {
$mock_foo = Test::MockObject->new();
$mock_foo->fake_module(
'Foo',
new => sub { $mock_foo },
);
};
a_test();
Subject: | code_to_test.pl |
use strict;
use warnings;
use Foo;
sub a_test {
my $foo = new Foo;
$foo->bar;
}
1;
Subject: | test1.pl |
use strict;
use warnings;
use Test::MockObject;
require 'code_to_test.pl';
my $mock_foo;
BEGIN {
$mock_foo = Test::MockObject->new();
$mock_foo->fake_module(
'Foo',
);
};
a_test();