Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mocking to reproduce error in our function

  • Someone reported that in certain cases the count does not work properly.
  • For example when the multi-word name is spread to multiple lines (so there is a newline).
  • This is how we can test
use strict;
use warnings;

use Test::More;
use Test::Mock::Simple;
my $mock = Test::Mock::Simple->new(module => 'MyWebAPI');

my $w = MyWebAPI->new('http://www.dailymail.co.uk/');

$mock->add(get => sub {
    return 'Beyonce Miley Cyrus Miley
Cyrus';
});
is_deeply $w->count_strings('Beyonce', 'Miley Cyrus'),
    {
        Beyonce => 1,
        'Miley Cyrus' => 2,
    };

done_testing;