Skip to content

Commit

Permalink
Merge pull request Test-More#265 from geistteufel/Test-Builder1.5
Browse files Browse the repository at this point in the history
Issue Test-More#264: Stringify the name attribute

Fix ok( $test, qr/.../ );
  • Loading branch information
schwern committed Mar 30, 2012
2 parents 7de0395 + 0bf75eb commit 415fea6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/TB2/Result/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ The name of the assert. For example...

has name =>
is => 'rw',
isa => 'Str'
isa => 'TB2::Stringify',
coerce => 1,
;


Expand Down
9 changes: 9 additions & 0 deletions lib/TB2/Types.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ A class name. It will be loaded.
subtype 'TB2::LoadableClass', as 'ClassName';
coerce 'TB2::LoadableClass', from 'Str', via { load_class($_); $_ };

=head3 TB2::Stringify
References stringifier class. It will coerce ref to string.
=cut

subtype 'TB2::Stringify', as 'Str';
coerce 'TB2::Stringify', from 'Ref', via { "$_" };

no TB2::Mouse::Util::TypeConstraints;

1;
42 changes: 42 additions & 0 deletions t/Types/stringify.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env perl -w

use strict;
use warnings;

BEGIN { require "t/test.pl" }


note "Stringify"; {
{
package My::Stringify;

use TB2::Mouse;
use TB2::Types;

has stringify =>
is => 'rw',
isa => 'TB2::Stringify',
coerce => 1;
}

my $obj = My::Stringify->new;

my $tests_ref = {
'regex' => qr/hello/,
'empty string' => '',
'string' => 'string',
'hashref' => { my => 'test' },
'arrayref' => ['my','test'],
'object' => $obj,
'sub' => sub { 1 },
};

while(my ($test, $ref) = each %$tests_ref) {
is $obj->stringify($ref), "$ref", 'stringify '.$test;
}

}


done_testing;

0 comments on commit 415fea6

Please sign in to comment.