Skip Menu |

This queue is for tickets about the MooseX-Test-Role CPAN distribution.

Report information
The Basics
Id: 132218
Status: open
Priority: 0/
Queue: MooseX-Test-Role

People
Owner: Nobody in particular
Requestors: nelo.onyiah [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Documented example usage of consuming_class (or consuming_object) does not work
From: nelo.onyiah [...] gmail.com
In the "EXPORTED FUNCTIONS" section of the POD: https://metacpan.org/pod/release/PBOYD/MooseX-Test-Role-0.07/lib/MooseX/Test/Role.pm#EXPORTED-FUNCTIONS There is an example usage of consuming_class (and consuming_object). In this example the "method" key has been omitted. ``` consuming_class('MyRole', method1 => sub { 'one' }, method2 => sub { 'two' }, required_method => sub { 'required' }, ); ``` However this does not appear to work. The following test: ``` use Test2::V0; use MooseX::Test::Role; subtest 'Excluding the "method" key' => sub { package MyRole { use Moo::Role; requires 'required_method'; }; is( consuming_class( MyRole => ( method1 => 'one', method2 => 'two', required_method => 'required', ), )->new, object { call method1 => 'one'; call method2 => 'two'; call required_method => 'required'; }, 'should work as documented in the POD example', ); }; done_testing; ``` Produces the following output: ``` -*- mode: compilation; default-directory: "/private/var/folders/_w/q9blb5897bz8510mt67v55180000gn/T/tmp.cWGA8UK6/" -*- Compilation started at Tue Mar 24 14:21:48 prove -mv t/exclude-method-key.t t/exclude-method-key.t .. # Seeded srand with seed '20200324' from local date. not ok 1 - Excluding the "method" key { not ok 1 - should work as documented in the POD example # Failed test 'should work as documented in the POD example' # at t/exclude-method-key.t line 23. # +-----------------------+-----------------------+----------+--------+ # | PATH | GOT | CHECK | LNs | # +-----------------------+-----------------------+----------+--------+ # | | MooseX::Test::Role::C | <OBJECT> | 18, 22 | # | | onsumer0=HASH(0x7fb29 | | | # | | 183c0d0) | | | # | | | | | # | method1() | <DOES NOT EXIST> | one | 462 | # | method2() | <DOES NOT EXIST> | two | 462 | # | required_method() | <UNDEF> | required | 462 | # +-----------------------+-----------------------+----------+--------+ 1..1 } # Failed test 'Excluding the "method" key' # at t/exclude-method-key.t line 25. 1..1 # Looks like you failed 1 test of 1. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/1 subtests Test Summary Report ------------------- t/exclude-method-key.t (Wstat: 256 Tests: 1 Failed: 1) Failed test: 1 Non-zero exit status: 1 Files=1, Tests=1, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.25 cusr 0.04 csys = 0.31 CPU) Result: FAIL Compilation exited abnormally with code 1 at Tue Mar 24 14:21:49 ``` A possible solution would be the following: ``` --- .direnv/perl5/lib/perl5/MooseX/Test/Role.pm.bak 2020-03-24 14:26:05.000000000 +0000 +++ .direnv/perl5/lib/perl5/MooseX/Test/Role.pm 2020-03-24 14:26:30.000000000 +0000 @@ -35,7 +35,7 @@ sub consuming_class { my ( $role, %args ) = @_; - my %methods = exists $args{methods} ? %{ $args{methods} } : (); + my %methods = exists $args{methods} ? %{ $args{methods} } : %args; my $role_type = _derive_role_type($role); confess 'first argument should be a role' unless $role_type; ```
Subject: exclude-method-key.t
use Test2::V0; use MooseX::Test::Role; subtest 'Excluding the "method" key' => sub { package MyRole { use Moo::Role; requires 'required_method'; }; is( consuming_object( MyRole => ( method1 => 'one', method2 => 'two', required_method => 'required', ), ), object { call method1 => 'one'; call method2 => 'two'; call required_method => 'required'; }, 'should work as documented in the POD example', ); }; done_testing;
Subject: moosex-test-role.diff
--- .direnv/perl5/lib/perl5/MooseX/Test/Role.pm.bak 2020-03-24 14:26:05.000000000 +0000 +++ .direnv/perl5/lib/perl5/MooseX/Test/Role.pm 2020-03-24 14:26:30.000000000 +0000 @@ -35,7 +35,7 @@ sub consuming_class { my ( $role, %args ) = @_; - my %methods = exists $args{methods} ? %{ $args{methods} } : (); + my %methods = exists $args{methods} ? %{ $args{methods} } : %args; my $role_type = _derive_role_type($role); confess 'first argument should be a role' unless $role_type;