Skip to content

Commit

Permalink
write all tests in terms of new example modules
Browse files Browse the repository at this point in the history
Fewer things to keep track of when trying to understand the tests
  • Loading branch information
preaction committed Mar 29, 2015
1 parent 2fbc0fb commit e1a0385
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 133 deletions.
103 changes: 39 additions & 64 deletions t/dependency/refs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
use Test::More;
use Test::Exception;
use Test::Lib;
use Test::Deep;
use Beam::Wire;

subtest 'method with no arguments' => sub {
my $wire = Beam::Wire->new(
config => {
foo => {
class => 'Foo',
class => 'My::RefTest',
args => {
foo => {
got_ref => {
'$ref' => 'greeting',
'$method' => 'greet',
'$method' => 'got_args_hash',
},
},
},
greeting => {
class => 'Greeting',
class => 'My::ArgsTest',
args => {
hello => "Hello",
default => 'World',
Expand All @@ -27,25 +28,26 @@ subtest 'method with no arguments' => sub {
);
my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
is $svc->foo, 'Hello, World' or diag explain $svc->foo;
isa_ok $svc, 'My::RefTest';
cmp_deeply $svc->got_ref, { hello => 'Hello', default => 'World' }
or diag explain $svc->got_ref;
};

subtest 'method with one argument' => sub {
my $wire = Beam::Wire->new(
config => {
bar => {
class => 'Foo',
class => 'My::RefTest',
args => {
foo => {
got_ref => {
'$ref' => 'greeting',
'$method' => 'greet',
'$args' => 'Bar',
'$method' => 'got_args_hash',
'$args' => 'hello',
},
},
},
greeting => {
class => 'Greeting',
class => 'My::ArgsTest',
args => {
hello => "Hello",
default => 'World',
Expand All @@ -55,25 +57,25 @@ subtest 'method with one argument' => sub {
);
my $svc;
lives_ok { $svc = $wire->get( 'bar' ) };
isa_ok $svc, 'Foo';
is $svc->foo, 'Hello, Bar' or diag explain $svc->foo;
isa_ok $svc, 'My::RefTest';
cmp_deeply $svc->got_ref, [ 'Hello' ] or diag explain $svc->got_ref;
};

subtest 'method with arrayref of arguments' => sub {
my $wire = Beam::Wire->new(
config => {
foo_and_bar => {
class => 'Foo',
class => 'My::RefTest',
args => {
foo => {
got_ref => {
'$ref' => 'greeting',
'$method' => 'greet',
'$args' => [ 'Foo', 'Bar' ],
'$method' => 'got_args_hash',
'$args' => [ 'default', 'hello' ],
},
},
},
greeting => {
class => 'Greeting',
class => 'My::ArgsTest',
args => {
hello => "Hello",
default => 'World',
Expand All @@ -83,45 +85,18 @@ subtest 'method with arrayref of arguments' => sub {
);
my $svc;
lives_ok { $svc = $wire->get( 'foo_and_bar' ) };
isa_ok $svc, 'Foo';
is $svc->foo, 'Hello, Foo. Hello, Bar' or diag explain $svc->foo;
};

subtest 'a different method reference' => sub {
my $wire = Beam::Wire->new(
config => {
francais => {
class => 'Foo',
args => {
foo => {
'$ref' => 'bonjour',
'$method' => 'greet',
'$args' => 'Foo',
},
},
},
bonjour => {
class => 'Greeting',
args => {
hello => 'Bonjour',
default => 'Tout Le Monde',
},
},
},
);
my $svc;
lives_ok { $svc = $wire->get( 'francais' ) };
isa_ok $svc, 'Foo';
is $svc->foo, 'Bonjour, Foo' or diag explain $svc->foo;
isa_ok $svc, 'My::RefTest';
cmp_deeply $svc->got_ref, [ 'World', 'Hello' ] or diag explain $svc->got_ref;
};

subtest 'path reference' => sub {
# XXX: Deprecate this for $value => $path
my $wire = Beam::Wire->new(
config => {
foo => {
class => 'Foo',
class => 'My::RefTest',
args => {
foo => {
got_ref => {
'$ref' => 'config',
'$path' => '//en/greeting'
}
Expand All @@ -139,18 +114,18 @@ subtest 'path reference' => sub {

my $foo;
lives_ok { $foo = $wire->get( 'foo' ) };
isa_ok $foo, 'Foo';
is $foo->foo, 'Hello, World' or diag explain $foo->foo;
isa_ok $foo, 'My::RefTest';
is $foo->got_ref, 'Hello, World' or diag explain $foo->got_ref;
};

subtest 'anonymous reference' => sub {
my $wire = Beam::Wire->new(
config => {
foo => {
class => 'Foo',
class => 'My::RefTest',
args => {
foo => {
'$class' => 'Foo',
got_ref => {
'$class' => 'My::ArgsTest',
'$args' => {
foo => 'Bar',
},
Expand All @@ -162,24 +137,24 @@ subtest 'anonymous reference' => sub {

my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
isa_ok $svc->foo, 'Foo';
is $svc->foo->foo, 'Bar';
isa_ok $svc, 'My::RefTest';
isa_ok $svc->got_ref, 'My::ArgsTest';
cmp_deeply $svc->got_ref->got_args_hash, { foo => 'Bar' };
};

subtest 'anonymous extends' => sub {
my $wire = Beam::Wire->new(
config => {
bar => {
class => 'Foo',
class => 'My::ArgsTest',
args => {
foo => 'HIDDEN',
},
},
foo => {
class => 'Foo',
class => 'My::RefTest',
args => {
foo => {
got_ref => {
'$extends' => 'bar',
'$args' => {
foo => 'Bar',
Expand All @@ -192,9 +167,9 @@ subtest 'anonymous extends' => sub {

my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
isa_ok $svc->foo, 'Foo';
is $svc->foo->foo, 'Bar';
isa_ok $svc, 'My::RefTest';
isa_ok $svc->got_ref, 'My::ArgsTest';
cmp_deeply $svc->got_ref->got_args_hash, { foo => 'Bar' };
};

done_testing;
2 changes: 1 addition & 1 deletion t/exception.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ subtest "service with both value and class/extends" => sub {
$wire = Beam::Wire->new(
config => {
foo => {
class => 'Foo',
class => 'My::ArgsTest',
value => 'foo',
}
}
Expand Down
9 changes: 0 additions & 9 deletions t/lib/Foo.pm

This file was deleted.

14 changes: 0 additions & 14 deletions t/lib/Greeting.pm

This file was deleted.

9 changes: 8 additions & 1 deletion t/lib/My/ArgsTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ sub BUILDARGS {
return { got_args => \@args };
}

sub got_args_hash { return { @{ $_[0]->got_args } } }
sub got_args_hash {
my ( $self, @keys ) = @_;
my $hash = { @{ $_[0]->got_args } };
if ( @keys ) {
return [ map { $hash->{$_} } @keys ];
}
return $hash;
}

1;
25 changes: 13 additions & 12 deletions t/service/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ subtest 'anonymous configs' => sub {
my $wire = Beam::Wire->new(
config => {
foo => {
class => 'Foo',
class => 'My::ArgsTest',
args => {
foo => {
'$config' => $SHARE_DIR->child( config => 'config.yml' )->stringify,
Expand All @@ -73,14 +73,14 @@ subtest 'anonymous configs' => sub {

my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
cmp_deeply $svc->foo, $EXPECT;
isa_ok $svc, 'My::ArgsTest';
cmp_deeply $svc->got_args_hash, { foo => $EXPECT };

subtest 'use a config as all the arguments' => sub {
my $wire = Beam::Wire->new(
config => {
foo => {
class => 'Foo',
class => 'My::ArgsTest',
args => {
'$config' => $SHARE_DIR->child( config => 'config.yml' )->stringify,
},
Expand All @@ -90,8 +90,8 @@ subtest 'anonymous configs' => sub {

my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
cmp_deeply $svc->foo, $EXPECT->{foo};
isa_ok $svc, 'My::ArgsTest';
cmp_deeply $svc->got_args_hash, $EXPECT;

};
};
Expand All @@ -105,7 +105,7 @@ subtest 'config references' => sub {
config => $SHARE_DIR->child( config => 'config.yml' )->stringify,
},
foo => {
class => 'Foo',
class => 'My::ArgsTest',
args => {
foo => {
'$ref' => 'yaml',
Expand All @@ -117,8 +117,8 @@ subtest 'config references' => sub {

my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
cmp_deeply $svc->foo, $EXPECT;
isa_ok $svc, 'My::ArgsTest';
cmp_deeply $svc->got_args_hash, { foo => $EXPECT };
};

subtest 'ref a path in a config' => sub {
Expand All @@ -128,7 +128,7 @@ subtest 'config references' => sub {
config => $SHARE_DIR->child( config => 'config.yml' )->stringify,
},
foo => {
class => 'Foo',
class => 'My::ArgsTest',
args => {
foo => {
'$ref' => 'yaml',
Expand All @@ -141,8 +141,9 @@ subtest 'config references' => sub {

my $svc;
lives_ok { $svc = $wire->get( 'foo' ) };
isa_ok $svc, 'Foo';
cmp_deeply $svc->foo, $EXPECT->{foo} or diag explain $svc->foo;
isa_ok $svc, 'My::ArgsTest';
cmp_deeply $svc->got_args_hash, { foo => $EXPECT->{foo} }
or diag explain $svc->got_args_hash;
};
};

Expand Down
Loading

0 comments on commit e1a0385

Please sign in to comment.