Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Mocking a method defined in a Moo Role

by PopeFelix (Beadle)
on Jun 24, 2016 at 14:45 UTC ( [id://1166507]=note: print w/replies, xml ) Need Help??


in reply to Re: Mocking a method defined in a Moo Role
in thread Mocking a method defined in a Moo Role

No, I want to test a behavior that is defined in around(), so I want to mock MyRole::foo to return something specific. I've already tested my class and my role separately. I want to test their interaction.

Here's another example, a little closer to my actual code (which I can't post):

package MyRole2 use Moo::Role; sub call { my $self = shift; # Connect to server, retrieve a document my $document = $self->get_document; return $document; } package MyClass2; use Moo; with 'MyRole2'; around call = sub { my ($orig, $self) = @_; my $document = $self->$orig; if (has_error($document)) { die 'Error'; } return parse($document); };

So what I want to do here is to mock MyRole2::call to return a static document, defined in my test fixtures, that contains errors and test that the exception is thrown properly. I know how to test it using Test::More::throws_ok or similar. What I don't know how to do is to mock MyRole2::call and not MyClass2::call.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-19 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found