summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-09-21 01:31:21 -0500
committerJesse Luehrs <doy@tozt.net>2009-09-21 01:31:21 -0500
commitef9e9eeca018131c99552c07b50684148e729dca (patch)
treebe199359970dc3d93f4734ef694600ffaab0cfa3
parentda3bdbc05f592ce301d66cb412a413420c29e021 (diff)
downloadmoosex-methodtraits-ef9e9eeca018131c99552c07b50684148e729dca.tar.gz
moosex-methodtraits-ef9e9eeca018131c99552c07b50684148e729dca.zip
add a bunch more tests
-rw-r--r--t/002-add-traits.t47
-rw-r--r--t/003-method-trait-options.t42
-rw-r--r--t/004-generate-method.t49
3 files changed, 138 insertions, 0 deletions
diff --git a/t/002-add-traits.t b/t/002-add-traits.t
new file mode 100644
index 0000000..f3bb92c
--- /dev/null
+++ b/t/002-add-traits.t
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 4;
+use Test::Moose;
+
+BEGIN {
+ package Foo::Exporter;
+ use MooseX::MethodTraits;
+
+ MooseX::MethodTraits->setup_import_methods(
+ with_traits => {
+ command => {
+ traits => ['Foo::Command'],
+ },
+ other => {
+ traits => ['Foo::OtherTrait'],
+ },
+ },
+ );
+}
+
+{
+ package Foo::Command;
+ use Moose::Role;
+}
+
+{
+ package Foo::OtherTrait;
+ use Moose::Role;
+}
+
+{
+ package Foo;
+ use Moose;
+ BEGIN { Foo::Exporter->import }
+
+ command foo => sub { 'FOO' };
+ other 'foo';
+}
+
+my $foo = Foo->new;
+can_ok($foo, 'foo');
+my $method = Foo->meta->get_method('foo');
+does_ok($method, 'Foo::Command');
+does_ok($method, 'Foo::OtherTrait');
+is($foo->foo, 'FOO', 'correct method is installed');
diff --git a/t/003-method-trait-options.t b/t/003-method-trait-options.t
new file mode 100644
index 0000000..53403de
--- /dev/null
+++ b/t/003-method-trait-options.t
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 4;
+use Test::Moose;
+
+BEGIN {
+ package Foo::Exporter;
+ use MooseX::MethodTraits;
+
+ MooseX::MethodTraits->setup_import_methods(
+ with_traits => {
+ command => {
+ traits => ['Foo::Command'],
+ }
+ }
+ );
+}
+
+{
+ package Foo::Command;
+ use Moose::Role;
+
+ has bar => (
+ is => 'ro',
+ );
+}
+
+{
+ package Foo;
+ use Moose;
+ BEGIN { Foo::Exporter->import }
+
+ command foo => sub { 'FOO' }, bar => 'BAR';
+}
+
+my $foo = Foo->new;
+can_ok($foo, 'foo');
+my $method = Foo->meta->get_method('foo');
+does_ok($method, 'Foo::Command');
+is($foo->foo, 'FOO', 'correct method is installed');
+is($method->bar, 'BAR', 'method trait attribute is initialized');
diff --git a/t/004-generate-method.t b/t/004-generate-method.t
new file mode 100644
index 0000000..999fd1e
--- /dev/null
+++ b/t/004-generate-method.t
@@ -0,0 +1,49 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 4;
+use Test::Moose;
+
+BEGIN {
+ package Foo::Exporter;
+ use MooseX::MethodTraits;
+
+ MooseX::MethodTraits->setup_import_methods(
+ with_traits => {
+ alias => {
+ traits => ['Foo::Alias'],
+ munge => sub {
+ my $name = shift;
+ return sub { shift->$name(@_) },
+ [ aliased_from => $name, @_ ];
+ },
+ }
+ }
+ );
+}
+
+{
+ package Foo::Alias;
+ use Moose::Role;
+
+ has aliased_from => (
+ is => 'ro',
+ isa => 'Str',
+ );
+}
+
+{
+ package Foo;
+ use Moose;
+ BEGIN { Foo::Exporter->import }
+
+ sub foo { 'FOO' }
+ alias bar => 'foo';
+}
+
+my $foo = Foo->new;
+can_ok($foo, 'bar');
+my $method = Foo->meta->get_method('bar');
+does_ok($method, 'Foo::Alias');
+is($method->aliased_from, 'foo', 'method knows where it came from');
+is($foo->bar, 'FOO', 'aliased properly');