be more verbose in the required method error (RT#60583)
[gitmo/Moose.git] / t / roles / imported_required_method.t
CommitLineData
8d57392a 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Test::Fatal;
6use Test::Moose;
7
8BEGIN {
9 package ExportsFoo;
10 use Sub::Exporter -setup => {
11 exports => ['foo'],
12 };
13
14 sub foo { 'FOO' }
15
16 $INC{'ExportsFoo.pm'} = 1;
17}
18
19{
20 package Foo;
21 use Moose::Role;
22 requires 'foo';
23}
24
25{
26 package Bar;
27 use Moose::Role;
28 requires 'bar';
29}
30
31{
32 package Class;
33 use Moose;
34 use ExportsFoo 'foo';
35 ::like(
36 ::exception { with 'Foo' },
37 qr/^\Q'Foo' requires the method 'foo' to be implemented by 'Class'. If you imported functions intending to use them as methods, you need to explicitly mark them as such, via Class->meta->add_method(foo => \&foo)/,
38 "imported 'method' isn't seen"
39 );
40 Class->meta->add_method(foo => \&foo);
41 ::is(
42 ::exception { with 'Foo' },
43 undef,
44 "now it's a method"
45 );
46
47 ::like(
48 ::exception { with 'Bar' },
49 qr/^\Q'Bar' requires the method 'bar' to be implemented by 'Class' at/,
50 "requirement isn't imported, so don't give the extra info in the error"
51 );
52}
53
54does_ok('Class', 'Foo');
55
56done_testing;