Fortune: Switching to text template (#3063)

* Fortune: Switching to text template

* Fortune: Adding subtitle and using Test::Deep
master
Rob Emery 2016-05-15 20:01:11 +01:00 committed by Ben Moon
parent 3349534b76
commit 58ce9b09c9
2 changed files with 27 additions and 18 deletions

15
lib/DDG/Goodie/Fortune.pm Normal file → Executable file
View File

@ -18,12 +18,15 @@ handle remainder => sub {
my $output = $fortune_file->get_random_fortune();
$output =~ s/\n/ /g;
return $output,
structured_answer => {
input => [],
operation => 'Random fortune',
result => $output
};
return $output, structured_answer => {
data => {
title => $output,
subtitle => "Random Fortune"
},
templates => {
group => 'text'
}
};
};
1;

30
t/Fortune.t Normal file → Executable file
View File

@ -3,26 +3,32 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'fortune';
zci is_cached => 0;
my @fortune = (
'-ANY-',
structured_answer => {
input => [],
operation => 'Random fortune',
result => '-ANY-'
});
sub build_test
{
return test_zci(re(qr/.+/), structured_answer => {
data => {
title => re(qr/.+/),
subtitle => 'Random Fortune'
},
templates => {
group => 'text'
}
})
}
ddg_goodie_test(
[qw( DDG::Goodie::Fortune )],
'gimmie a fortune cookie' => test_zci(@fortune),
'gimmie a unix fortune' => test_zci(@fortune),
'give me a fortune cookie' => test_zci(@fortune),
'give me a unix fortune' => test_zci(@fortune),
'unix fortune cookie' => test_zci(@fortune),
'gimmie a fortune cookie' => build_test(),
'gimmie a unix fortune' => build_test(),
'give me a fortune cookie' => build_test(),
'give me a unix fortune' => build_test(),
'unix fortune cookie' => build_test(),
'how do I make a fortune overnight' => undef,
"bill gates' fortune" => undef,
);