Take advantage of fake_hook() in existing tests

This commit is contained in:
Jared Johnson 2014-12-18 14:16:23 -06:00
parent 0204fb0f18
commit a5f786c986
2 changed files with 12 additions and 23 deletions

View File

@ -152,13 +152,13 @@ sub __config {
my @test_data = ( my @test_data = (
{ {
pref => 'size_threshold', pref => 'size_threshold',
result => [], result => undef,
expected => 10000, expected => 10000,
descr => 'fall back to global config when user_config is absent', descr => 'fall back to global config when user_config is absent',
}, },
{ {
pref => 'test_config', pref => 'test_config',
result => [], result => undef,
expected => undef, expected => undef,
descr => 'return nothing when no user_config plugins exist', descr => 'return nothing when no user_config plugins exist',
}, },
@ -176,16 +176,11 @@ sub __config {
}, },
); );
for (@test_data) { for (@test_data) {
$qp->hooks->{user_config} = @{$_->{result}} $qp->fake_hook( 'user_config', sub { return @{$_->{result}} } )
? [ if $_->{result};
{
name => 'test hook',
code => sub { return @{$_->{result}} }
}
]
: undef;
is($sender->config($_->{pref}), $_->{expected}, $_->{descr}); is($sender->config($_->{pref}), $_->{expected}, $_->{descr});
} }
$qp->unfake_hook('user_config');
} }
sub __canonify { sub __canonify {

View File

@ -258,8 +258,8 @@ sub __config {
{ {
pref => 'size_threshold', pref => 'size_threshold',
hooks => { hooks => {
user_config => [], user_config => undef,
config => [], config => undef,
}, },
expected => { expected => {
user => 10000, user => 10000,
@ -270,8 +270,8 @@ sub __config {
{ {
pref => 'timeout', pref => 'timeout',
hooks => { hooks => {
user_config => [], user_config => undef,
config => [], config => undef,
}, },
expected => { expected => {
user => 1200, user => 1200,
@ -329,15 +329,8 @@ sub __config {
}, },
); );
for my $t (@test_data) { for my $t (@test_data) {
for my $hook (qw( config user_config )) { for my $hook ( grep { $t->{hooks}{$_} } qw( config user_config ) ) {
$qp->hooks->{$hook} = @{$t->{hooks}{$hook}} $qp->fake_hook( $hook, sub { return @{ $t->{hooks}{$hook} } } );
? [
{
name => 'test hook',
code => sub { return @{$t->{hooks}{$hook}} }
}
]
: undef;
} }
is( is(
$qp->config($t->{pref}, $a), $qp->config($t->{pref}, $a),
@ -348,6 +341,7 @@ sub __config {
$t->{expected}{global}, $t->{expected}{global},
"Global config: $t->{descr}"); "Global config: $t->{descr}");
} }
$qp->unfake_hook($_) for qw( config user_config );
} }
sub __warn_level { sub __warn_level {