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.