From 58ce9b09c9bb6057c506e42a86cf2b46612c0fd3 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 15 May 2016 20:01:11 +0100 Subject: [PATCH] Fortune: Switching to text template (#3063) * Fortune: Switching to text template * Fortune: Adding subtitle and using Test::Deep --- lib/DDG/Goodie/Fortune.pm | 15 +++++++++------ t/Fortune.t | 30 ++++++++++++++++++------------ 2 files changed, 27 insertions(+), 18 deletions(-) mode change 100644 => 100755 lib/DDG/Goodie/Fortune.pm mode change 100644 => 100755 t/Fortune.t diff --git a/lib/DDG/Goodie/Fortune.pm b/lib/DDG/Goodie/Fortune.pm old mode 100644 new mode 100755 index b343e1180c0..7fce452d698 --- a/lib/DDG/Goodie/Fortune.pm +++ b/lib/DDG/Goodie/Fortune.pm @@ -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; diff --git a/t/Fortune.t b/t/Fortune.t old mode 100644 new mode 100755 index f960e9b8726..07ccd8613fe --- a/t/Fortune.t +++ b/t/Fortune.t @@ -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, );