I'm using a mock object to test a module. The module requires, as an input, a Foo object, and the module has a gaurd clause to assert that the foo argument
isa Foo. Now, in testing, I am sending in a mock Foo, but I'd like the mock Foo to pass the isa test:
$mock->isa('Foo').
I can't seem to get this to work.
Note in the small example below, I can mock bar, but I can't mock isa. (And yes, I know my mocked isa is always true as written -- so that $mock->isa('Foo') and $mock->isa('NotAFoo') would both be true. Yes, I'll fix my mock isa, but for now, I can't even get the mock isa called.... I never see the warning.)
THanks for any advice
use Test::MockObject;
use Test::More 'no_plan';
use strict;
my $x = Test::MockObject->new( {} );
$x->fake_module('Foo');
$x->fake_new('Foo');
$x->mock( 'isa', sub { warn 'I dont get this warning'; 1 } );
$x->mock( 'bar', sub { 2 } );
is( $x->isa('Foo'), 1 );
is( $x->bar('Foo'), 2 );
In reply to Mocking isa
by water
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.