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: 70478
Status: open
Priority: 0/
Queue: Test-MockModule

People
Owner: GFRANKS [...] cpan.org
Requestors: sbaynes [...] fastmail.co.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.05
Fixed in: (no value)



Subject: Mocking a module from scratch
It would be nice if Test::MockModule could mock a module from scratch rather than just modifying a loadable module. This should include support for use of Exporter. I am trying to test against modules that export with Exporter and that are not available in the source/test environment and will only become available in the [embedded] production environment which does not include the tests. It can be done with Test::MockObject fake module but this provides no special support for the import function and the results are messy and I am looking for a better way.
You should be able to do this fairly easily, with something like this: package Foo # put code here, if you want package main use Test::MockModule my $mock = Test::MockModule->new('Foo') $mock->mock(foo => 'foo'); print Foo::foo() . "\n"; If I've misunderstood your request, can you provide an example of what you're trying to do, and where you would like to clean it up?
From: sbaynes
On Sat Mar 14 13:49:25 2015, GFRANKS wrote: Show quoted text
> You should be able to do this fairly easily, with something like this: > > package Foo > > # put code here, if you want > > package main > > use Test::MockModule > > my $mock = Test::MockModule->new('Foo') > $mock->mock(foo => 'foo'); > > print Foo::foo() . "\n"; > > > If I've misunderstood your request, can you provide an example of what > you're trying to do, and where you would like to clean it up?
That would work (be worth adding it to your documentation as an example). You still have to create the empty package oneself. I had been thinking more on the lines of: my $mock = Test::MockModule->new('Foo', create => 1 ) It is just a small bit of convenience to have Test::MockModule do the empty package creation. If I am having to have my own package line, then I might as well mock it up by writing it there and then rather than using Test::MockModule. In our build environment we are normally mocking packages from scratch in unit tests rather than loading and modifying them. This saves us having them as build time dependencies (faster build) and also keeps the unit tests shallow rather than being deeper integration tests.