-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide define method so the mock method is unneeded in tests.
- Loading branch information
1 parent
2ef289a
commit 0298d8d
Showing
2 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use warnings; | ||
use strict; | ||
|
||
use Test::More; | ||
use Test::Warnings; | ||
|
||
use Test::MockModule; | ||
|
||
my $mocker = Test::MockModule->new('Mockee'); | ||
|
||
$mocker->define( 'doesnt_exist', 2 ); | ||
is( Mockee::doesnt_exist(), 2, 'define() allows us to mock nonexistant subroutines.' ); | ||
|
||
eval { $mocker->define( 'existing_subroutine', 6 ) }; | ||
like( $@, qr/Mockee::existing_subroutine exists\!/, 'exception when define()ing an existing subroutine' ); | ||
|
||
undef $mocker; | ||
is( Mockee->can('doesnt_exist'), undef, "the defined sub went away after mocker is undeffed" ); | ||
$mocker = Test::MockModule->new('Mockee'); | ||
|
||
$mocker->define( 'doesnt_exist', 3 ); | ||
is( Mockee::doesnt_exist(), 3, 'The subroutine can be defined again after the mock object goes out of scope and is re-instantiated.' ); | ||
|
||
done_testing(); | ||
|
||
#---------------------------------------------------------------------- | ||
|
||
package Mockee; | ||
|
||
our $VERSION; | ||
BEGIN { $VERSION = 1 } | ||
|
||
sub existing_subroutine { 1 } | ||
|
||
1; |