I'm having problems mocking a subroutine in a different module than where I run the tests.
I have my tests in the ParserTests.pl file. I am trying to check a subroutine (parsing) in the LogParser.pm module
sub parse { my ($self) = @_; my $rr = $self->getRR; while(1) { my $result = $self->parseCommitSet(); if ($result eq 2) { last; } my $printStatus = $self->printOut($result); if (!$printStatus) { say "Problem occurred with writing to output"; return 0; } $self->setRR(ReportRecord->new()); } return 1; }
I am trying to make fun of printOut so that it always returns true. I am trying to do the following:
#! /usr/bin/perl use v5.10.0; use strict; use warnings; use Test::More 'no_plan'; use Test::MockObject; use LogParser; {other testsโฆ} my $mock = Test::MockObject->new(); $mock->set_true('LogParser::printOut'); my $test100FH = getTestFH($test100SetsNoPrev); $logParser = LogParser->new($test100FH); is($logParser->parse, 1, "im ok?"); close $test100FH;
But this test fails. Can you tell me why and point me to the right path to make it work correctly when I test parse ()? I read a bunch of documentation, but something like this is still a bit unclear.
Error
Can't use an undefined value as a symbol reference at /Users/achu/Documents/workspace/Perl_Script/LogParser.pm line 241, <$fh> line 8371.
This line (line 241) is inside the printOut subroutine, but this means that it does not mock this subroutine as I wanted it to. What am I doing wrong?
source share