Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Test::MockObject not showing args when mocking a sub

by Anonymous Monk
on May 27, 2009 at 14:19 UTC ( [id://766431]=note: print w/replies, xml ) Need Help??


in reply to Test::MockObject not showing args when mocking a sub

use Test::MockObject; my $mock = Test::MockObject->new(); $mock->mock( 'fluorinate', sub { use Data::Dumper; print Dumper( \@_ ); return 'impurifying precious bodily fluids'; } ); print $mock->fluorinate(1,2); __END__ $VAR1 = [ bless( {}, 'Test::MockObject' ), 1, 2 ]; impurifying precious bodily fluids

Replies are listed 'Best First'.
Re^2: Test::MockObject not showing args when mocking a sub
by jvector (Friar) on May 27, 2009 at 14:45 UTC
    OK, so the arg list in the mocked call gets a MockObject ref unshifted into the first position. Saying
    $port->mock ('write', sub {my $Mock=shift;my $arg=shift;$arg=~s/\r/\n/g;print " +wrote $arg to the serial port\n";});
    gives
    wrote ATE0 to the serial port wrote AT+CMGF=1 to the serial port wrote AT+CPIN=9532 to the serial port wrote ATI to the serial port
    Thank you!

    This signature will be ready by Christmas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://766431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-14 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found