Mocking exception
- What if the get function raises an exception, how will our code handle?
- Hint: it does not, so this test will break
- But this is how we could test what will happen in that case without trying to figure out how to reliably create one using the real LWP::Simple
examples/mock-lwp/t/webapi_mock_exception.t
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 { die 'Something went wrong'; }); is_deeply $w->count_strings('Beyonce', 'Miley Cyrus'), { Beyonce => 0, 'Miley Cyrus' => 0, }; done_testing;