From 31cc5e296b30a421c45956a87f523e4c8eb7a4f2 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Mon, 21 Sep 2015 06:03:58 -0400 Subject: [PATCH] added optional `extends` param to MO Using this module was confusing to me at first because `isa` means something else in the context of Test::MockObject. I think `extends` is more aligned with the T::M and T::M::E interfaces and so is less surprising to people who are used to that. --- README.md | 6 +++--- lib/Test/Core.pm | 8 ++++---- t/04-mocking.t | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6da2e0b..7f54f6e 100644 --- a/README.md +++ b/README.md @@ -137,10 +137,10 @@ Test::Core implements the following mocking functions using [Test::MockModule](h - `MO(%mocks)` - # Takes an optional "isa" for extending existing objects + # Takes an optional "extends" for extending existing objects my $mock = MO( - isa => 'DateTime', - now => sub { DateTime->now->add(days => 3) }, + extends => 'DateTime', + now => sub { DateTime->now->add(days => 3) }, ); # BUGS diff --git a/lib/Test/Core.pm b/lib/Test/Core.pm index 348244a..941289f 100644 --- a/lib/Test/Core.pm +++ b/lib/Test/Core.pm @@ -32,7 +32,7 @@ sub mock_module { sub mock_object { my (%mocks) = @_; - my $isa = delete $mocks{isa}; + my $isa = delete $mocks{isa} || delete $mocks{extends}; my $mock_object = $isa ? Test::MockObject::Extends->new($isa) : Test::MockObject->new; @@ -270,10 +270,10 @@ Test::Core implements the following mocking functions using L, =item C<< MO(%mocks) >> - # Takes an optional "isa" for extending existing objects + # Takes an optional "extends" for extending existing objects my $mock = MO( - isa => 'DateTime', - now => sub { DateTime->now->add(days => 3) }, + extends => 'DateTime', + now => sub { DateTime->now->add(days => 3) }, ); =back diff --git a/t/04-mocking.t b/t/04-mocking.t index 43caf92..4fedfa8 100644 --- a/t/04-mocking.t +++ b/t/04-mocking.t @@ -19,4 +19,9 @@ is $mock_dt->year => '1776'; ok $mock_dt->isa('DateTime'); ok !$mock_dt->isa('Test::MockObject'); +$mock_dt = MO(extends => DateTime->now, year => 1776); +is $mock_dt->year => '1776'; +ok $mock_dt->isa('DateTime'); +ok !$mock_dt->isa('Test::MockObject'); + done_testing;