I've just decided to try Test::MockObject for my tests but I have problems with it. The error message seems to indicate that the subroutine encoding_from_html_document is not exported by HTML::Encoding - but in the BEGIN block I try to mock this subroutine (perhaps the double "" is indication of some internal bug, but I am a novice here). Here is my code:
use Test::More tests => 1; BEGIN { use Test::MockObject; Test::MockObject->fake_module ( 'HTML::Encoding', encoding_from_html_document => sub{ 'iso' } ); } use_ok( Catalyst::Test, 'LinkDB' );
And here is the error message when I try to run it:
1..1 not ok 1 - use Catalyst::Test; # Failed test (t/m/cdbi_link1.t at line 11) # Tried to use 'Catalyst::Test'. # Error: Couldn't load "LinkDB", "Couldn't load "LinkDB::C::Bookm +ark", ""encoding_from_html_document" is not exported by the HTML::Enc +oding module # Can't continue after import errors at lib/LinkDB/C/Bookmark.pm line +9 # BEGIN failed--compilation aborted at t/m/cdbi_link1.t line 11. # Compilation failed in require at /usr/local/share/perl/5.8.4/Module/ +Pluggable/Fast.pm line 66. # " at /usr/local/share/perl/5.8.4/Module/Pluggable/Fast.pm line 68. # Compilation failed in require at /usr/local/share/perl/5.8.4/Catalys +t/Test.pm line 78. # " at /usr/local/share/perl/5.8.4/Catalyst/Test.pm line 80. # BEGIN failed--compilation aborted at (eval 5) line 2. # Looks like you failed 1 test of 1.
What is wrong here?

I need to add that without the BEGIN block the test runs OK.

This is Test::MockObject VERSION = '0.20' and Perl version 5.8.4.


In reply to Test::MockObject and mocking module subroutines by zby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.